Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH v4] prompt: support generic non-visible regions
- X-seq: zsh-workers 51535
- From: Felipe Contreras <felipe.contreras@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Cc: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>, Oliver Kiddle <opk@xxxxxxx>, Felipe Contreras <felipe.contreras@xxxxxxxxx>
- Subject: [PATCH v4] prompt: support generic non-visible regions
- Date: Tue, 7 Mar 2023 22:04:47 -0600
- Archived-at: <https://zsh.org/workers/51535>
- In-reply-to: <20230228155525.4186428-1-felipe.contreras@gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <20230228155525.4186428-1-felipe.contreras@gmail.com>
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@xxxxxxxxx>
---
Interdiff against v3:
diff --git a/Src/prompt.c b/Src/prompt.c
index 8d7a38089..2ed90ebe1 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -877,12 +877,12 @@ putpromptchar(int doprint, int endchar)
bv->bp += strlen(bv->bp);
}
}
- } else if(*bv->fm == 0x01) { // start non-visible characters
+ } 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
+ } else if(*bv->fm == 0x02) { /* end non-visible characters */
if (bv->dontcount && !--bv->dontcount) {
addbufspc(1);
*bv->bp++ = Outpar;
Src/prompt.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/Src/prompt.c b/Src/prompt.c
index 39fcf5eb7..2ed90ebe1 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author