diff options
Diffstat (limited to 'pkgs')
| -rw-r--r-- | pkgs/claude-inbox.nix | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/pkgs/claude-inbox.nix b/pkgs/claude-inbox.nix index d17b454..64633cf 100644 --- a/pkgs/claude-inbox.nix +++ b/pkgs/claude-inbox.nix @@ -407,10 +407,71 @@ let esac fi COMPREPLY=() + local kinds=() k=0 for g in "$cmds" "$left" "$repolist" "$branchlist"; do for c in $(compgen -W "$g" -- "$cur"); do - case " ''${COMPREPLY[*]} " in *" $c "*) ;; *) COMPREPLY+=("$c") ;; esac + case " ''${COMPREPLY[*]} " in + *" $c "*) ;; + *) COMPREPLY+=("$c"); kinds+=("$k") ;; + esac done + k=$((k + 1)) + done + # Listing only (a second TAB), in color, by kind: readline would + # print escapes as ^[, so the list is printed here, and readline gets + # one blank candidate, to list instead, and redraw the prompt after. + if [ "$COMP_TYPE" = 63 ] && [ ''${#COMPREPLY[@]} -gt 1 ]; then + local colors= + colors=$(_claude_inbox_colors) || return 0 + _claude_inbox_list "$colors" "''${kinds[*]}" "''${COMPREPLY[@]}" >/dev/tty + COMPREPLY=(" ") + fi + } + # the colors of commands, options, REPOs, BRANCHes, as SGR parameters: + # truecolor, 256 colors, or 8, as the terminal has them; none (and so + # readline's own listing) with NO_COLOR, or on a dumb terminal + _claude_inbox_colors() { + [ -z "''${NO_COLOR-}" ] && [ -w /dev/tty ] || return 1 + case ''${TERM-dumb} in dumb | "") return 1 ;; esac + local n + case ''${COLORTERM-} in + truecolor | 24bit) + echo "38;2;230;180;80 38;2;150;150;175 38;2;100;160;240 38;2;120;200;120" + return ;; + esac + case $TERM in + *256color*) n=256 ;; + *) n=$(tput colors 2>/dev/null) || n=8 ;; + esac + if [ "''${n:-0}" -ge 256 ]; then + echo "38;5;179 38;5;103 38;5;75 38;5;114" + elif [ "''${n:-0}" -ge 8 ]; then + echo "33 35 34 32" + else + return 1 + fi + } + # COLORS KINDS WORD...: the words in columns, down then across, like + # readline's, each in the color of its kind + _claude_inbox_list() { + local colors=($1) kinds=($2) words=("''${@:3}") w width=0 n=$(($# - 2)) + for w in "''${words[@]}"; do [ ''${#w} -le "$width" ] || width=''${#w}; done + width=$((width + 2)) + local cols=$(( ''${COLUMNS:-80} / width )) rows r c i + [ "$cols" -ge 1 ] || cols=1 + rows=$(( (n + cols - 1) / cols )) + printf '\n' + for ((r = 0; r < rows; r++)); do + for ((c = 0; c < cols; c++)); do + i=$((c * rows + r)) + [ "$i" -lt "$n" ] || break + if [ $((c + 1)) -lt "$cols" ] && [ $((i + rows)) -lt "$n" ]; then + printf '\e[%sm%s\e[0m%*s' "''${colors[kinds[i]]}" "''${words[i]}" $((width - ''${#words[i]})) "" + else + printf '\e[%sm%s\e[0m' "''${colors[kinds[i]]}" "''${words[i]}" + fi + done + [ $((r + 1)) -ge "$rows" ] || printf '\n' done } # in that order (bash 4.4 and later) |
