Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: _ps1234, _date_formats: Complete strftime formats for %D{}



We normally leave configuration of colours for complist to the users but
in the case of the completion of terminal colours, I think the following
is useful. It is also one situation where we don't need to worry about
the user's colour preferences or even whether a particular colour is
visible over their background. Any thoughts?

I think the description of "ANSI" is only applicable to the first 8 (or
16 colours), right? This hasn't allowed for custom configuration of the
lc and rc in _comp_colors. Anyone know if there is a particular layout
of rows/columns that should be used so the colours line up logically?
Should we use set the background colour instead when completing within
%K{...}? (it seemed uglier to me).

Oliver

diff --git a/Completion/Zsh/Type/_ps1234 b/Completion/Zsh/Type/_ps1234
index f182a16..de4ecb2 100644
--- a/Completion/Zsh/Type/_ps1234
+++ b/Completion/Zsh/Type/_ps1234
@@ -1,7 +1,8 @@
 #compdef -value-,PROMPT,-default- -value-,PROMPT2,-default- -value-,PROMPT3,-default- -value-,PROMPT4,-default- -value-,RPROMPT,-default- -value-,RPROMPT2,-default- -value-,PS1,-default- -value-,PS2,-default- -value-,PS3,-default- -value-,PS4,-default- -value-,RPS1,-default- -value-,RPS2,-default- -value-,SPROMPT,-default-
 
 local -a specs
-local expl bs suf pre changed=1 ret=1
+local expl grp cols bs suf pre changed=1 ret=1
+local -A ansi
 
 [[ -z $compstate[quote] ]] && bs='\'
 
@@ -22,24 +23,37 @@ done
 
 if compset -P '%[FK]'; then
   # this should use -P but that somehow causes single quotes to be stripped
-  compset -P '(\\|){' || pre=( -p "$bs{" )
-  compset -S '(\\|)}*' || suf=( -S $bs\} )
-  specs=(
-    black
-    red
-    green
-    yellow
-    blue
-    magenta
-    cyan
-    white
-    default
+  compset -P '(\\|){' || pre=( -p '{' )
+  compset -S '(\\|)}*' || suf=( -S "$bs}" )
+  ansi=(
+    black 30
+    red 31
+    green 32
+    yellow 33
+    blue 34
+    magenta 35
+    cyan 36
+    white 37
+    default 39
   )
-  _wanted ansi-colors expl 'ansi color' compadd $suf $pre -a specs && ret=0
-  if (( $#suf )) && compset -P "<->"; then
+
+  _description -V ansi-colors expl 'ansi color'
+  grp="$expl[expl[(i)-V]+1]"
+  _comp_colors+=( ${(ps.\0.)"$(printf "($grp)=%s=%s\0" ${(kv)ansi})"} )
+  compadd "$expl[@]" $suf $pre -k ansi && ret=0
+  if (( $#suf )) && compset -P "(<->|%v)"; then
     _wanted ansi-colors expl 'closing brace' compadd -S '' \} && ret=0
+  elif (( $+terminfo[colors] )); then
+    (( cols = $terminfo[colors] - 1 ))
+    (( cols = cols > 255 ? 255 : cols ))
+    _description -V terminal-colors expl 'terminal color'
+    grp="$expl[expl[(i)-V]+1]"
+    compadd "$expl[@]" $suf $pre {0..$cols}
+    for c in {0..$cols}; do
+      _comp_colors+=( "($grp)=${c}=${${$(print -P "%F{$c}")#?\[}%m}" )
+    done
   else
-    _message -e terminal-colors "number between 0 and $(( $terminfo[colors] - 1 ))"
+    _message -e terminal-colors "number"
   fi
 fi
 



Messages sorted by: Reverse Date, Date, Thread, Author