zsh-workers
 help / color / mirror / code / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: zsh-workers@zsh.org
Cc: Bart Schaefer <schaefer@brasslantern.com>,
	Roman Perepelitsa <roman.perepelitsa@gmail.com>,
	Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH v3 try2] prompt: support generic non-visible regions
Date: Tue, 28 Feb 2023 09:55:25 -0600	[thread overview]
Message-ID: <20230228155525.4186428-1-felipe.contreras@gmail.com> (raw)

readline uses \001 (start of header) and \002 (start of text) as markers
to delimit a non-visible character zone, which are necessary to
calculate the width of a prompt.

In zsh we do this with %{ and %}, but we could support
\001 and \002 as well, so that a function which generates output for
the prompt can use colors in a way that works for both bash and zsh.

This additionally has the benefit of allowing prompts without
PROMPT_PERCENT to use colors correctly.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---

No change since the previous try.

This is how I tested the nesting:

  $' %{\e[31m\x01\e[31m\x01\e[31m\x02\e[31m\x02\e[31m%}master%{\e[m\x01\e[m\x01\e[m\x02\e[m\x02\e[m%}'

And for the \001 and \002 reference:

https://git.savannah.gnu.org/cgit/readline.git/tree/display.c#n340

 Src/prompt.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/Src/prompt.c b/Src/prompt.c
index 39fcf5eb7..8d7a38089 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -877,6 +877,16 @@ putpromptchar(int doprint, int endchar)
 		    bv->bp += strlen(bv->bp);
 		}
 	    }
+	} else if(*bv->fm == 0x01) { // start non-visible characters
+	    if (!bv->dontcount++) {
+		addbufspc(1);
+		*bv->bp++ = Inpar;
+	    }
+	} else if(*bv->fm == 0x02) { // end non-visible characters
+	    if (bv->dontcount && !--bv->dontcount) {
+		addbufspc(1);
+		*bv->bp++ = Outpar;
+	    }
 	} else {
 	    char c = *bv->fm == Meta ? *++bv->fm ^ 32 : *bv->fm;
 
-- 
2.39.2



             reply	other threads:[~2023-02-28 15:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-28 15:55 Felipe Contreras [this message]
2023-02-28 16:29 ` Oliver Kiddle
2023-03-01 12:54   ` Felipe Contreras
2023-02-28 19:36 ` Bart Schaefer
2023-03-08  4:04 ` [PATCH v4] " Felipe Contreras

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=20230228155525.4186428-1-felipe.contreras@gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=roman.perepelitsa@gmail.com \
    --cc=schaefer@brasslantern.com \
    --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).