zsh-users
 help / color / mirror / code / Atom feed
From: Grant Taylor <gtaylor@tnetconsulting.net>
To: zsh-users@zsh.org
Subject: Re: Help fix Zsh shell command prompt error or stranee
Date: Tue, 22 Aug 2023 23:27:14 -0500	[thread overview]
Message-ID: <93c9527e-1a22-2bd1-94d6-21bb549a3264@tnetconsulting.net> (raw)
In-Reply-To: <CAN=4vMqzvMRijxp_qWzi-tr2+5ncqWvP-dbJKtbf_Z7YKvGbZg@mail.gmail.com>

On 8/22/23 1:26 AM, Roman Perepelitsa wrote:
> I'm intrigued. When is %{...%} necessary?

My use case is a mixture of #2 and / or #3.

> These are the use-cases I know of, and I would venture a guess that 
> they apply to a small minority of users:
> 
> 1. To work around bugs in the terminal. For example, if the terminal 
> displays "X" as a wide character, you would need to use "%2{X%}" 
> instead of the plain "X".
> 
> 2. To embed special markers at the start and the end of the prompt 
> that are recognized by the terminal.
> 
> 3. To use styling that isn't available through %-escapes. For example, 
> italic, or dim.

Maybe it's a 4th category, VT100 / ANSI / XTerm escape sequences that 
aren't supported through %-escapes.

  - Setting the tile
  - Setting the *default* foreground color
  - Setting the *default* background color.

N.B. to see the difference changing the /default/ color makes, try 
setting the color, clearing the screen, and running a colorized ls (or 
some other program that generates colored output).  I'll bet you dollars 
to donuts that the background and / or foreground color is different 
/after/ the /colorized/ output from the program.  --  Frequently, such 
programs use "\e[0m" (where "\e" is the escape character, 0x1B).

Conversely, "\e]10;#RRGGBB\e\\" (where "\\" is the backslash character, 
0x5C) will cause the default foreground color to be changed to the 
RRGGBB value.  Similarly "\e]11;##RRGGBB\e\\" will cause the default 
background color to be changed to the RRGGBB value.  Thus when "\e[0m" 
is used, the system used the RRGGBB value for the foreground and background.

There are many other formatting attributes that can be used:

  - bold
  - dim
  - reverse video
  - underline
  - italic
  - blinking
  - double-height
  - double-width

Some terminals support causing it to change the font size.
Some terminals support causing it to change the font used.
Some terminals support causing it to resize the window.
Some terminals support causing it to send data to the printer.
Some terminals support clearing the (off screen) scroll back buffer.
Some terminals support clearing the (on screen) scroll back buffer 
(similar to clearing the screen).
Some terminals support soft fonts.
Some terminals support graphics; XTerm supports SIXEL and ReGIS.

Almost all of these things require multiple (single width) bytes as 
control sequences.

There is no reason that these can't be used in part of the prompt.

Using the %{...%} means that ZLE (?) won't count the multiple (single 
width) bytes output to do fancy things with the terminal.

> Are there any other use cases for %{...%}?

I think so.

> Note that it's not necessary (and not a good idea anyway) to embed 
> special terminal commands into prompt. Things like setting the terminal 
> title, notifying the terminal about the current working directory, 
> etc. These are better done by writing to the TTY in the corresponding 
> hooks (precmd, chpwd, etc.).

Please elaborate as to why these things, which are fixed strings of 
text, shouldn't be embedded in the PROMPT / PS1 et al.

I completely get doing dynamic things that need to be computed in 
precmd.  But I don't yet see a reason why a static string can't be 
embedded in the prompt (PROMPT / PS1) directly.

I use preexec() to change the window title to show information on the 
command that is being run.

The PROMPT / PS1 then re-sets the window title back to a fixed string or 
a string that Zsh alters via other normal %-escapes; %d, %/, or %~. 
E.g. PROMPT / PS1 (et al.) can have something like the following

    "...\e]0;%~\e\a..."

Where:
  "..." is other similar static (from an environment variable content 
point of view) text
  "\a" is the "alert" a.k.a. "bell" character, 0x07.

Why do I need to do processing in the precmd() function when I can 
easily use static variables.

I believe I could make the PROMPT / PS1 variables be read-only in 
~/.zshrc and not need to change them while still having the fully 
dynamic prompt that I currently have.

    local -r PROMPT

> This is different from prompt markers that I mentioned above, which 
> must be embedded into the prompt.

I'm not seeing the "prompt markers" that you're talking about.  Please 
elaborate.

N.B. transient_rprompt is fun.  }:-)



-- 
Grant. . . .


  reply	other threads:[~2023-08-23 21:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-19  0:35 Budi
2023-08-19  2:01 ` Grant Taylor
2023-08-20  6:30   ` Roman Perepelitsa
2023-08-20 10:50     ` Budi
2023-08-20 17:11       ` Bart Schaefer
2023-08-20 15:54     ` Grant Taylor
2023-08-22  6:26       ` Roman Perepelitsa
2023-08-23  4:27         ` Grant Taylor [this message]
2023-08-19 16:09 ` Bart Schaefer

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=93c9527e-1a22-2bd1-94d6-21bb549a3264@tnetconsulting.net \
    --to=gtaylor@tnetconsulting.net \
    --cc=zsh-users@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).