zsh-workers
 help / color / mirror / code / Atom feed
* colors_plus
@ 2023-02-12 17:04 Jim
  2023-02-12 20:51 ` colors_plus Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Jim @ 2023-02-12 17:04 UTC (permalink / raw)
  To: devs


[-- Attachment #1.1: Type: text/plain, Size: 3529 bytes --]

Hi all,

To be honest I wrote the following with the intent to send it to zsh-users,
but the
more I thought about it I decided to first ask those on zsh-workers for your
thoughts and opinions.

For lack  of a better name, "colors_plus" for now.  This is a function I
have been
trying to think through as an addition to the current colors function. It
should work
on at least some virtual terminals(best guess). Doesn't work on the linux
console,
so colors would still be needed.

Attached is the function colors_plus_test.  It is also a wip(work in
progress) so has a
number of notes and comments.  Also code that is commented out that was used
for testing, that may or may not have worked out. It needs a lot of
cleanup, to say
the least, but should be good enough for testing. It should show what a
virtual
terminal is capable of outputting. Results can only be determined by visual
observation.

Anyway I was hoping that some on this list would run the function and give
me
feedback on what you think of the output. It has several defaults so
autoloading
the function and then typing the function's name will give you 8 lines of
output.
The 8 colors match those used in the colors function. There is a 27 colors
option
with color names. There is a 64 color options, but it doesn't have color
names, if
you care to look. BTW some of the 27 color names couldn't be found in files
like
rgb.txt. Lots of google searches to come up with some of the names.  I'm
open
to suggestions on color names too. The shorter the name, the better it
would be.

Command line arguments for colors_plus_test are:
  [1|2|3]  the number of colors to output 1) 8 (default), 2) 27 and 3) 64
colors
  [n|b|d] **  n) for normal text output(default), b) for bold and d) for dim
  [i|f|r|u|s|c] ** These can be used in any combination from none to all of
them.
    Although some combinations will be useless for most people.
    i) italic, f) flash, r) reverse, u) underscore, s) strikethrough and c)
conceal

** case insensitive

Examples:
  colors_plus_test  -- defaults to "colors_plus_test 1 n" 8 colors and
normal
  colors_plus_test 2 b i r  -- outputs 27 colors as bold italic reverse
  colors_plus_test d  -- outputs 8 colors as dim
  ...

Requirements:
  Colors_plus uses the module zsh/nearcolor to convert the hex input to a
usable
  output. The zsh man page suggests checking the COLORTERM parameter to see
  if it is equal to either 24bit or truecolor to load the module.  xterm
doesn't set this
  parameter, but the function will work with xterm if TERM is set to
xterm-256color.
  For those using TMUX, on an xterm, TERM set to tmux-256color will also
work.
  Haven't tested TMUX running on other terminals yet.

Tested on the following virtual terminals and appears to work:
  xterm
  xfce4-terminal

Tested on the following virtual terminals with mixed results:
kitty - also doesn't work well with 'colors function'

Parameter(s) and elements:
  For the function colors_plus, which I'm working on, I'm considering using
one
  associative array "CP" with element names something like:
  Would the following be to obscure for most to use?
  ${CP[2nfi_electric_blue]}
     2 - number of colors
     n - normal
     fi - flash italic , note these letters would be in alphabetical order
for consistency
    _ - separator
     colorname - name of the color to display

As I said, comments are welcome. Are 8 colors enough? Are 27 colors to many?
So fire away!  Also haven't tested on a bright(white) background.

Regards and thanks,

Jim Murphy

[-- Attachment #1.2: Type: text/html, Size: 4545 bytes --]

[-- Attachment #2: colors_plus_test --]
[-- Type: application/octet-stream, Size: 3907 bytes --]

emulate -L zsh -o extendedglob
# Function:  colors_plus_test
# Author:  Jim "friartek" Murphy
# Copyright:  2023
# License:  FREE
# This is still a (W)ork (I)n (P)rogress!
[[ -v modules[zsh/nearcolor] ]] || zmodload zsh/nearcolor
# NOTES: (quite a few)  [[[
# IS NEARCOLOR SUPPORTED by a virtual terminal with the current TERM setting?
# Virtual terminals such as xterm do not, AFAIK, set COLORTERM but the
# following check will verify if nearcolor is supported with the current TERM
# setting.  TERM set to xterm-256color should work. For TMUX users, setting
# TERM to tmux-256color should also work.
# The following will check if nearcolor works or doesn't. If not, it unloadS
# nearcolor module.
# X="%F{#abcdef}"
# A=${${${(V)$(print -r ${(%)X})}##*;}%m}
# [[ $#A -ne 0 ]] && print "nearcolor is supported" || zmodload -ui zsh/nearcolor
# Source: https://unix.stackexchange.com/questions/665370/\
#   confused-on-colors-xterm-vs-zsh-how-to-set-xterm-without-breaking-zsh-colors
# Thanks to Stéphane Chazelas
# print -P '%F{#ABCB8D}text%f'
# Next line, compliments of Bart Schaefer (modified)
# var="%F{#ABCB8D}text%f" ; print -r -- ${(%)var}
# ]]]
# INPUT:
# (1) 8 colors (2) 27 colors (3) 64 colors ## way in the future (4) 125 colors
# (N)ormal=0 (B)old=1 (D)im=2
# (I)talic-3 (U)nder=4 (F)lash=5 (R)everse=7 (C)onceal=8 (S)trike=9
local     ABi ABI ACN C Ce CF Cl CP Cs E L M N NCOLORS T X R G B RC
local -a  H Hs M CLs CLXs Os LC Tmp UC CN8 CN27 CN64 CSC8 CSC27
local -A  CP CN2CAN Hex8
CF=$HOME/.config/colors_plus.cfg
NCOLORS=8 # default
CN8=(black blue green cyan red magenta yellow white)
CN27=(
  black  navy         blue    jade   teal        azure
  green  spring_green cyan    maroon purple      violet
  olive  grey         lilac   sage   light_green electric_blue
  red    bright_pink  magenta orange congo_pink  pink
  yellow sunny        white
  # two letter color codes
  # bk ny be je tl ae gn sg cn mn pe vt oe gy lc se lg eb rd bp ma or cp pk yw sy we
)
# The following tries to come up with a two character color code for each color.
# This code isn't perfect but appears to work for the 27 colors in this files
# original CN27 parameter.
# orignal code fair, changes oops ...
for E ($CN27) { [[ $E == *_* ]] \
  && { Tmp=(${(s._.)E}) ; ACN=${Tmp[1][1]}${Tmp[2][1]} } \
  || ACN=$E[1]$E[-1]
  Tmp=(${(v)CN2CAN})
  ABi=${Tmp[(i)$ACN]}
  [[ $ABi -gt $#Tmp ]] || ACN=$E[1,2]
  CN2CAN[$E]=$ACN
}
#print -- CN2CAN:  $#CN2CAN
#for E (${CN27}) print -- $E $CN2CAN[$E]
#return
for M ({1..3}) {
  N=${argv[(i)$M]}
  [[ $N -le $#argv ]] && {
    L=$M
    case $M in ; 1) CP=CN8 ;; 2) CP=CN27 ;; 3) CP=CN64 ;; esac
  }
} ; : ${CP:=CN8}
for E (D d N n B b) {
  N=${argv[(i)$E]}
  [[ $N -gt $#argv ]] && continue
  case $E in
    D|d) Os=('2;') ;; B|b) Os=('1;') ;; N|n) Os=('0;') ;;
  esac
}
: ${Os:=0;} # Default normal
for E (I i U u F f R r C c S s) {
  N=${argv[(i)$E]}
  [[ $N -gt $#argv ]] && continue
  case $E in
    I|i) Os+=('3;') ;; U|u) Os+=('4;') ;; F|f) Os+=('5;') ;;
    R|r) Os+=('7;') ;; C|c) Os+=('8;') ;; S|s) Os+=('9;') ;;
  esac
} ; O=${(j..)Os}
UC=({A..Z}) ; LC=({a..z}) ; M=(${UC:^LC}) ; T=${(j..)M}
Cs=$'\e['$O'38;5;' ; Ce='m' ; RC=$'\e['0$Ce
Hs=('00 ff' '00 7f ff' '00 55 aa ff' '00 3f 7f bf ff')  # 8(default), 27 or 64 colors
N=
: ${N:=${L:=1}}  # N = 1(default) or 2 or 3
H=(${(z)Hs[N]})
for R ($H) { for G ($H) { for B ($H) {
      X=$R$G$B ; C="%F{#${X}}"
      CLXs+=($X)
      #CLs+=(${${${(V)$(print -P ${C})}##*;}%m})
      CLs+=(${${${(V)$(print -r ${(%)C})}##*;}%m})
} } }
#for E ($CLs) { Cl="$Cs$E$Ce" ; print -- $Cl$T$RC ${(l.3.. .)E} }
#for E ($CLs) { Cl="$Cs$E$Ce" ; print -- $Cl$T$RC ${(V)Cl} }
for N ({1..${#CLs}}) { E=$CLs[N] ; Cl="$Cs$E$Ce"
  print -- $Cl$T$RC ${CLXs[N]} ${(V)Cl} ${${(P)CP}[N]} }
#for E ($CLs) { Cl="$Cs$E$Ce" ; print ${(V)Cl} }

# vim: foldmethod=marker foldmarker=[[[,]]] foldlevel=0 :
# vim: ts=2 sw=2 sts=2 sta ai et ft=zsh :

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: colors_plus
  2023-02-12 17:04 colors_plus Jim
@ 2023-02-12 20:51 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2023-02-12 20:51 UTC (permalink / raw)
  To: linuxtechguy; +Cc: devs

On Sun, Feb 12, 2023 at 9:05 AM Jim <linux.tech.guy@gmail.com> wrote:
>
> Anyway I was hoping that some on this list would run the function and give  me
> feedback on what you think of the output. It has several defaults so autoloading
> the function and then typing the function's name will give you 8 lines of output.
> The 8 colors match those used in the colors function.

There was a post-5.9 patch to the colors function to extend it to 16
colors (workers/50212).  The additional 8 may not work on the console,
I haven't checked.

You might add the named set you're creating to the hash tables
initialized by colors, and bypass re-creating your new names if
they're already there.

I also suggest anyplace where you're doing something like
  var=...$(print -r ${(%)x})...
it would be preferable to do
  print -r -v var ...${(%)x}...
to avoid the command substitution.

This function will be directly affected by Oliver's repairs in 51258,
51272, 51280, 51281, 51289, 51320, 51383 and maybe others, so you
might want to grab and build the latest sources from sourceforge git.

No other immediate commentary.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-12 20:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-12 17:04 colors_plus Jim
2023-02-12 20:51 ` colors_plus Bart Schaefer

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).