zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Src/prompt.c: Add %O and %o prompt escapes
@ 2018-07-27 10:14 Joey Pabalinas
  0 siblings, 0 replies; only message in thread
From: Joey Pabalinas @ 2018-07-27 10:14 UTC (permalink / raw)
  To: Zsh Workers Mailing List; +Cc: Joey Pabalinas

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

Implement %O and %o as shorthands for resetting fg/bg color and
terminal attributes (underline/standout/boldface) respectively.

Update the documentation to include the two new prompt escapes.

Signed-off-by: Joey Pabalinas <joeypabalinas@gmail.com>
---
 Doc/Zsh/prompt.yo |  6 ++++++
 Src/prompt.c      | 19 +++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/Doc/Zsh/prompt.yo b/Doc/Zsh/prompt.yo
index 909012c8e787b04fcf..8086c54b2e651923c5 100644
--- a/Doc/Zsh/prompt.yo
+++ b/Doc/Zsh/prompt.yo
@@ -244,10 +244,16 @@ colours are allowed in the second format also.
 )
 item(tt(%K) LPAR()tt(%k)RPAR())(
 Start (stop) using a different bacKground colour.  The syntax is
 identical to that for tt(%F) and tt(%f).
 )
+item(tt(%O))(
+Reset foreground and background colours to default.
+)
+item(tt(%o))(
+Turn off all terminal attributes (underline/standout/boldface).
+)
 item(tt(%{)...tt(%}))(
 Include a string as a literal escape sequence.
 The string within the braces should not change the cursor
 position.  Brace pairs can nest.
 
diff --git a/Src/prompt.c b/Src/prompt.c
index 959ed8e3d57a0286a8..48980e744437bc6b23 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -567,10 +567,29 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 	    case 'k':
 		txtchangeset(txtchangep, TXTNOBGCOLOUR, TXT_ATTR_BG_ON_MASK);
 		txtunset(TXT_ATTR_BG_ON_MASK);
 		set_colour_attribute(TXTNOBGCOLOUR, COL_SEQ_BG, TSC_PROMPT);
 		break;
+	    case 'O':
+		txtchangeset(txtchangep, TXTNOFGCOLOUR, TXT_ATTR_FG_ON_MASK);
+		txtchangeset(txtchangep, TXTNOBGCOLOUR, TXT_ATTR_BG_ON_MASK);
+		txtunset(TXT_ATTR_FG_ON_MASK);
+		txtunset(TXT_ATTR_BG_ON_MASK);
+		set_colour_attribute(TXTNOFGCOLOUR, COL_SEQ_FG, TSC_PROMPT);
+		set_colour_attribute(TXTNOBGCOLOUR, COL_SEQ_BG, TSC_PROMPT);
+		break;
+	    case 'o':
+		txtchangeset(txtchangep, TXTNOUNDERLINE, TXTUNDERLINE);
+		txtchangeset(txtchangep, TXTNOSTANDOUT, TXTSTANDOUT);
+		txtchangeset(txtchangep, TXTNOBOLDFACE, TXTBOLDFACE);
+		txtunset(TXTUNDERLINE);
+		txtunset(TXTSTANDOUT);
+		txtunset(TXTBOLDFACE);
+		tsetcap(TCUNDERLINEEND, TSC_PROMPT|TSC_DIRTY);
+		tsetcap(TCSTANDOUTEND, TSC_PROMPT|TSC_DIRTY);
+		tsetcap(TCALLATTRSOFF, TSC_PROMPT|TSC_DIRTY);
+		break;
 	    case '[':
 		if (idigit(*++bv->fm))
 		    arg = zstrtol(bv->fm, &bv->fm, 10);
 		if (!prompttrunc(arg, ']', doprint, endchar, txtchangep))
 		    return *bv->fm;
-- 
Cheers,
Joey Pabalinas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-07-27 10:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-27 10:14 [PATCH] Src/prompt.c: Add %O and %o prompt escapes Joey Pabalinas

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