zsh-users
 help / color / mirror / code / Atom feed
* zsh/nearcolor module usage
@ 2023-02-07  2:53 Jim
  2023-02-07  4:12 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Jim @ 2023-02-07  2:53 UTC (permalink / raw)
  To: zsh

[-- Attachment #1: Type: text/plain, Size: 1265 bytes --]

Hi,

While searching zshall man page for 'color' I came across the nearcolor
module.
This is something I hadn't used before and thought it could be useful.
Unless I missed something, which I may have, I didn't see anything about
how to
use it. The module only talks about loading it. After some google searches
I did
find an example of how to use it involving prompt expansion in an answer by
Stéphane Chazelas ... thanks Stéphane.

URL:
https://unix.stackexchange.com/questions/665370/confused-on-colors-xterm-vs-zsh-how-to-set-xterm-without-breaking-zsh-colors

% print -P '%F{#ABCB8D}text%f'

Question:  Does anyone know any other ways to use nearcolor?  I tried using
the
parameter expansion flag (%) but nothing I tried worked.

As I said, unless I missed something, it would also seem useful to add a
usage
example to the man page along with how to load the module.

BTW, not all virtual terminals seem to use the parameter COLORTERM.
xterm is one that, AFAICT, doesn't. Yet the nearcolor module appears to work
as long as TERM is set correctly.  In my case TERM set to either
xterm-256color
or tmux-256color works. If using the example in the man page, nearcolor
would
never have loaded for xterm.

Regards,

Jim Murphy

[-- Attachment #2: Type: text/html, Size: 1750 bytes --]

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

* Re: zsh/nearcolor module usage
  2023-02-07  2:53 zsh/nearcolor module usage Jim
@ 2023-02-07  4:12 ` Bart Schaefer
  2023-02-07  4:29   ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2023-02-07  4:12 UTC (permalink / raw)
  To: linuxtechguy; +Cc: zsh

On Mon, Feb 6, 2023 at 6:54 PM Jim <linux.tech.guy@gmail.com> wrote:
>
> Unless I missed something, which I may have, I didn't see anything about how to
> use it.

It is a bit obscure.

The expansion of prompts section has a cross-reference

       %F (%f)
              Start (stop) using a different foreground colour,  if  supported
              by  the  terminal.  The colour may be specified two ways: either
              as a numeric argument, as normal, or by  a  sequence  in  braces
              following  the  %F, for example %F{red}.  In the latter case the
              values allowed are as described for the fg zle_highlight  attri‐
              bute;  see Character Highlighting in zshzle(1).  This means that
              numeric colours are allowed in the second format also.

In the section on Character Highlighting, we find

       fg=colour
              The  foreground  colour should be set to colour, a decimal inte‐
              ger, the name of one of the eight most widely-supported  colours
              or as a `#' followed by an RGB triplet in hexadecimal format.

And then in the entry for the nearcolor module

       The zsh/nearcolor module replaces colours  specified  as  hex  triplets
       with  the  nearest  colour  in  the  88 or 256 colour palettes that are
       widely used by terminal emulators.

> % print -P '%F{#ABCB8D}text%f'
>
> Question:  Does anyone know any other ways to use nearcolor?  I tried using the
> parameter expansion flag (%) but nothing I tried worked.

Parameter expansion with (%) should work.
  palegreenpants="%F{#ABCB8D}pants%f"
  print -r -- $palegreenpants

> As I said, unless I missed something, it would also seem useful to add a usage
> example to the man page along with how to load the module.

A reference back to prompts and highlighting would be appropriate.

> BTW, not all virtual terminals seem to use the parameter COLORTERM.
> [...]  If using the example in the man page, nearcolor would
> never have loaded for xterm.

That example is not intended to be exhaustive or necessarily even
correct, it's just showing how to load the module only when some
arbitrary condition is true.  It's up to you to figure out the right
condition to test.  I'm not sure how to express that in the text.


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

* Re: zsh/nearcolor module usage
  2023-02-07  4:12 ` Bart Schaefer
@ 2023-02-07  4:29   ` Bart Schaefer
  2023-02-07  5:10     ` Jim
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2023-02-07  4:29 UTC (permalink / raw)
  To: linuxtechguy; +Cc: zsh

On Mon, Feb 6, 2023 at 8:12 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> Parameter expansion with (%) should work.
>   palegreenpants="%F{#ABCB8D}pants%f"
>   print -r -- $palegreenpants

Then of course I typo'd that.

  print -r -- ${(%)palegreenpants}


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

* Re: zsh/nearcolor module usage
  2023-02-07  4:29   ` Bart Schaefer
@ 2023-02-07  5:10     ` Jim
  0 siblings, 0 replies; 4+ messages in thread
From: Jim @ 2023-02-07  5:10 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh

[-- Attachment #1: Type: text/plain, Size: 622 bytes --]

Bart,

On Mon, Feb 6, 2023 at 10:30 PM Bart Schaefer <schaefer@brasslantern.com>
wrote:

> On Mon, Feb 6, 2023 at 8:12 PM Bart Schaefer <schaefer@brasslantern.com>
> wrote:
> >
> > Parameter expansion with (%) should work.
> >   palegreenpants="%F{#ABCB8D}pants%f"
> >   print -r -- $palegreenpants
>
> Then of course I typo'd that.
>
>   print -r -- ${(%)palegreenpants}
>

Thanks for the example, Now my feeble brain can wrap itself around it.

Obscure enough I didn't connect them  together. :-(  That said, the zsh
man pages are much better then a lot of other man pages I've read over
the years.

Again, thanks,

Jim

[-- Attachment #2: Type: text/html, Size: 1183 bytes --]

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

end of thread, other threads:[~2023-02-07  5:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-07  2:53 zsh/nearcolor module usage Jim
2023-02-07  4:12 ` Bart Schaefer
2023-02-07  4:29   ` Bart Schaefer
2023-02-07  5:10     ` Jim

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