zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: zsh workers <zsh-workers@zsh.org>
Subject: Re: PATCH: _ps1234, _date_formats: Complete strftime formats for %D{}
Date: Fri, 10 Jul 2015 01:02:14 +0200	[thread overview]
Message-ID: <25965.1436482934@thecus.kiddle.eu> (raw)
In-Reply-To: <24602.1436455211@thecus.kiddle.eu>

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
 


  reply	other threads:[~2015-07-09 23:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-06  0:36 Mikael Magnusson
2015-07-06 11:11 ` Oliver Kiddle
2015-07-06 14:17   ` Mikael Magnusson
2015-07-06 14:56     ` Mikael Magnusson
2015-07-08 14:02   ` Jun T.
2015-07-08 14:42     ` Mikael Magnusson
2015-07-09 12:17       ` Oliver Kiddle
2015-07-09 13:25         ` Mikael Magnusson
2015-07-09 13:53         ` Mikael Magnusson
2015-07-09 15:20           ` Oliver Kiddle
2015-07-09 23:02             ` Oliver Kiddle [this message]
2015-07-09 12:22     ` Oliver Kiddle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=25965.1436482934@thecus.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).