#compdef figlet

typeset -A opt_args
local context state line
local fontdir
fontdir=$(_call_program path figlet -I2 2>/dev/null)

_arguments -s -S \
    "(-l -c -r)-x[use default justification of font]" \
    "(-x -c -r)-l[left justify]" \
    "(-x -l -r)-c[center justify]" \
    "(-x -l -c)-r[right justify]" \
    "(-S -s -o -W -m)-k[use kerning]" \
    "(-k -s -o -W -m)-S[smush letters together or else!]" \
    "(-k -S -o -W -m)-s[smushed spacing]" \
    "(-k -S -s -W -m)-o[let letters overlap]" \
    "(-k -S -s -o -m)-W[wide spacing]" \
    "(-p)-n[normal mode]" \
    "(-n)-p[paragraph mode]" \
    "(-E)-D[use Deutsch character set]" \
    "(-D)-E[use English character set]" \
    "(-X -R)-L[left-to-right]" \
    "(-L -X)-R[right-to-left]" \
    "(-L -R)-X[use default writing direction of font]" \
    "(-w)-t[use terminal width]" \
    "(-t)-w+[specify output width]:output width (in columns):" \
    "(-k -S -s -o -W)-m+[specify layout mode]:layout mode:" \
    "(-I)-v[version]" \
    "(-v)-I+[display info]:info code:(-1 0 1 2 3 4)" \
    "-d+[specify font directory]:font directory:_files -/" \
    "-f+[specify font]:font:->fonts" \
    "(-N)-C+[specify control file]:control file:->controls" \
    "(-C)-N[clear controlfile list]" \
    && return 0

(( $+opt_args[-d] )) && fontdir=$opt_args[-d]

case $state in
   (fonts)
     _files -W $fontdir -g '*flf*(:r)' && return 0
     ;;
   (controls)
     _files -W $fontdir -g '*flc*(:r)' && return 0
     ;;
esac

return 1
