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

Re: [PATCH] Update man pages to match change to Functions/Misc/colors



Still trying to digest.

On Wed, Dec 13, 2023 at 9:31 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
On Wed, Dec 13, 2023 at 5:27 AM Jim <linux.tech.guy@xxxxxxxxx> wrote:
>
> The one thing that looks strange about the change is prompt %S and %s, previously
> standout mode, will now mean reverse mode.

The "colors" function should not be conflated with the prompt escapes.
They have almost nothing to do with one another.  Changes to the
function do not affect prompts unless you are using the PROMPT_SUBST
option to interpolate variables defined by "colors".  What's emitted
by the prompt escapes has not changed as a result of any updates to
zsh:

I was associating  the two, thanks for clarifying.

The lack of a firm definition of "standout" is why this change was
made.  Even "italic" remains a bit iffy; from
 https://en.wikipedia.org/wiki/ANSI_escape_code
 3  Italic  Not widely supported. Sometimes treated as inverse or blink.

(That wikipedia page also has some useful color charts, I'd not found
those before.)

Very familiar with this page, but way TLDR all of it. But a great reference.

In any case you're right that the contrib.yo doc should be updated,
but none of your other changes would be correct.

I agree. But something I believe is lacking is the absence of usable predefined
attributes in the color function. bold_color and reset_color are the only ones
even though the color associative array has many others uncommented.
Would another associative array for the user to use be helpful? Something
along the lines of ${attribute[<attribute name>}}

e.g.  attribute[reverse] attribute[no-reverse]
   attribute[bold] attribute[faint] attribute[normal]
   ...

The attached patch is offered as a possible enhancement. It generates
the ANSI code for all uncommented attributes. Some attributes may not
be implemented in the user's prefered terminal emulator but would for
others. VTE derived terminals support most if not all of those in colors.

If the patch is acceptable, I would try to generate the man page additions
and changes. Not that familiar with yodl and the "zsh definitions", but would
be willing to take a stab at it.

Regards,

Jim Murphy
diff --git a/Functions/Misc/colors b/Functions/Misc/colors
index 8a0cec383..d5933c9a9 100644
--- a/Functions/Misc/colors
+++ b/Functions/Misc/colors
@@ -21,7 +21,7 @@ color=(
   07 reverse                27 no-reverse
 # 07 standout               27 no-standout
   08 conceal                28 no-conceal
-# 09 strikethrough        # 29 no-strikethrough
+  09 strikethrough          29 no-strikethrough

 # Font selection:
 # 10 font-default
@@ -51,9 +51,9 @@ color=(
 # 50 no-proportional
 # 51 border-rectangle
 # 52 border-circle
-# 53 overline
+  53 overline
 # 54 no-border
-# 55 no-overline
+  55 no-overline
 # 56 through 59 reserved

 # Ideogram markings:
@@ -84,7 +84,11 @@ color=(
 # Map in both directions; could do this with e.g. ${(k)colors[(i)normal]},
 # but it's clearer to include them all both ways.

-local k
+local k Pattern
+local -a color_names
+print -- "color_names:  $color_names"
+color_names=(${${${(Mk)color:#bg-*}:#*bright*}#*-})   # get all color names
+print -- "color_names:  $color_names"
 for k in ${(k)color}; do color[${color[$k]}]=$k; done

 # Add "fg-" keys for all the text colors, for clarity.
@@ -105,15 +109,29 @@ for k in '' fg- bg-; do
   color[${k}bright-grey]=${color[${k}bright-gray]}
 done

-colour=(${(kv)color})	# A case where ksh namerefs would be useful ...
+colour=(${(kv)color}) # A case where ksh namerefs would be useful ...

 # The following are terminal escape sequences used by colored prompt themes.

-local lc=$'\e[' rc=m	# Standard ANSI terminal escape values
+local lc=$'\e[' rc=m  # Standard ANSI terminal escape values
+
+# Attributes

 typeset -Hg reset_color bold_color
-reset_color="$lc${color[none]}$rc"
-bold_color="$lc${color[bold]}$rc"
+typeset -AHg attribute
+
+reset_color="$lc${color[none]}$rc"    # legacy attributes so existing scripts
+bold_color="$lc${color[bold]}$rc"     # won't fail
+
+# Get list of all attributes, generate ANSI code for each and add to the
+# associative array "attribute".
+Pattern="${(j.|.)color_names}"
+#for k in ${${(ok)color:#(<->|bg-|fg-|bright)*}:#(${(j.|.)~color_names})}; do
+#for k in ${(ok)color:#(<->|bg-|fg-|bright)*}:#($~Pattern)})}; do
+for k in ${(ok)color:#(<->|bg-|fg-|bright|$~Pattern)*}; do
+  attribute[$k]="$lc${color[$k]}$rc"
+done
+attribute[reset]=${attribute[none]}   # add additional name reset(aka none)

 # Foreground



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