#compdef mdless

autoload -U is-at-least

_mdless() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'(--full-width)--columns=[Maximum number of columns to use for output. Defaults to 80, the terminal width (whichever is smaller), or \`defaults.columns\` in \`~/.config/mdcat/config.toml\`. Pass 0 to disable line wrapping]:COLUMNS:_default' \
'--completions=[Generate completions for a shell to standard output and exit]:COMPLETIONS:(bash elvish fish powershell zsh)' \
'--theme=[Colour theme to use. Defaults to auto-detecting dark or light from the terminal, or to the \`\[theme\]\` section'\''s \`base\` in \`~/.config/mdcat/config.toml\` if that file exists]:THEME:((auto\:"Detect dark/light mode from the terminal and pick accordingly"
dark\:"Use the built-in dark theme"
light\:"Use the built-in light theme"
catppuccin-mocha\:"Catppuccin Mocha (dark)"
catppuccin-latte\:"Catppuccin Latte (light)"
gruvbox-dark\:"Gruvbox dark"
gruvbox-light\:"Gruvbox light"
dracula\:"Dracula"
nord\:"Nord"
solarized-dark\:"Solarized dark"
solarized-light\:"Solarized light"))' \
'--image-protocol=[Force a specific inline image protocol instead of auto-detecting one from the terminal. Useful inside tmux/screen, where the outer terminal'\''s capabilities usually aren'\''t visible to auto-detection. \`none\` disables inline images entirely. Also settable via \`\$MDCAT_IMAGE_PROTOCOL\`]:PROTOCOL:((none\:"Disable inline images entirely"
iterm2\:"iTerm2'\''s inline image protocol"
kitty\:"The kitty terminal graphics protocol"
sixel\:"The sixel image protocol"))' \
'--tabs=[Expand tabs in the input to spaces, using a tab stop width of COLUMNS, before parsing. Off by default, so literal tabs pass through unchanged; without this, a tab inside text content (not part of the Markdown block structure) throws off line-wrapping and alignment width calculations, since terminals render it as jumping to the next tab stop rather than occupying a single column. Also settable via \`defaults.tabs\` in \`~/.config/mdcat/config.toml\`]:COLUMNS:_default' \
'-c[Disable all colours and other styles]' \
'--no-colour[Disable all colours and other styles]' \
'(--columns)--full-width[Use the full terminal width instead of capping it at 80 columns. Also settable via \`defaults.full_width\` in \`~/.config/mdcat/config.toml\`]' \
'-l[Do not load remote resources like images. Also settable via \`defaults.local_only\` in \`~/.config/mdcat/config.toml\`]' \
'--local[Do not load remote resources like images. Also settable via \`defaults.local_only\` in \`~/.config/mdcat/config.toml\`]' \
'--fail[Exit immediately if any error occurs processing an input file. Also settable via \`defaults.fail_fast\` in \`~/.config/mdcat/config.toml\`]' \
'--detect-terminal[Print detected terminal name and exit]' \
'(-c --no-colour)--ansi[Skip terminal detection and only use ANSI formatting]' \
'-w[Watch the input file and re-render on change. Requires a single file argument]' \
'--watch[Watch the input file and re-render on change. Requires a single file argument]' \
'--margin[Add a two-space left margin to all output. Reduces the effective render width accordingly. Also settable via \`defaults.margin\` in \`~/.config/mdcat/config.toml\`]' \
'--smart-punctuation[Render typographic punctuation\: straight quotes become curly, \`--\`/\`---\` become en/em dashes, and \`...\` becomes an ellipsis. Also settable via \`defaults.smart_punctuation\` in \`~/.config/mdcat/config.toml\`]' \
'--list-themes[Print a sample rendered with every built-in theme, to help pick one, and exit]' \
'--toc[Print a table of contents generated from the document'\''s headings before its content. Entries link to the source file, for terminals and later viewers that support OSC 8 links and resolve GitHub-style heading anchors; plain text on standard input, since there'\''s no file to link to]' \
'-P[Do not paginate output (default for mdcat)]' \
'--no-pager[Do not paginate output (default for mdcat)]' \
'-p[Paginate the output of mdcat with a pager like less (default). Overrides an earlier --no-pager]' \
'--paginate[Paginate the output of mdcat with a pager like less (default). Overrides an earlier --no-pager]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
'*::filenames -- Files to read.  If - read from standard input instead:_files' \
&& ret=0
}

(( $+functions[_mdless_commands] )) ||
_mdless_commands() {
    local commands; commands=()
    _describe -t commands 'mdless commands' commands "$@"
}

if [ "$funcstack[1]" = "_mdless" ]; then
    _mdless "$@"
else
    compdef _mdless mdless
fi
