summaryrefslogtreecommitdiff
path: root/Src/prompt.c
diff options
context:
space:
mode:
authorAxel Beckert <abe@deuxchevaux.org>2022-04-11 00:17:48 +0200
committerAxel Beckert <abe@deuxchevaux.org>2022-04-11 00:17:48 +0200
commitb09f4483416c54c1782824633dfabaf2ec0265b6 (patch)
tree304bc82642862525ae680c7fbaa249663b10ad57 /Src/prompt.c
parent12eb3e5356f2fc3351eed58ef1cef1b8fb83b504 (diff)
parent6e55c920503071e917619b8cb1a188cd35d772db (diff)
downloadzsh-b09f4483416c54c1782824633dfabaf2ec0265b6.tar.gz
zsh-b09f4483416c54c1782824633dfabaf2ec0265b6.zip
New upstream version 5.8.1.2-test
Diffstat (limited to 'Src/prompt.c')
-rw-r--r--Src/prompt.c67
1 files changed, 23 insertions, 44 deletions
diff --git a/Src/prompt.c b/Src/prompt.c
index 91e21c8e9..738c7fc7a 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -268,7 +268,7 @@ parsecolorchar(zattr arg, int is_fg)
bv->fm--;
}
} else
- arg = match_colour(NULL, 1, arg);
+ arg = match_colour(NULL, is_fg, arg);
return arg;
}
@@ -1055,9 +1055,9 @@ tsetcap(int cap, int flags)
if (txtisset(TXTUNDERLINE))
tsetcap(TCUNDERLINEBEG, flags);
if (txtisset(TXTFGCOLOUR))
- set_colour_attribute(txtattrmask, COL_SEQ_FG, TSC_PROMPT);
+ set_colour_attribute(txtattrmask, COL_SEQ_FG, flags);
if (txtisset(TXTBGCOLOUR))
- set_colour_attribute(txtattrmask, COL_SEQ_BG, TSC_PROMPT);
+ set_colour_attribute(txtattrmask, COL_SEQ_BG, flags);
}
}
}
@@ -1706,38 +1706,22 @@ match_colour(const char **teststrp, int is_fg, int colour)
return TXT_ERROR;
}
}
- /*
- * Try termcap for numbered characters if possible.
- * Don't for named characters, since our best bet
- * of getting the names right is with ANSI sequences.
- */
- if (!named && tccan(tc)) {
- if (tccolours >= 0 && colour >= tccolours) {
- /*
- * Out of range of termcap colours.
- * Can we assume ANSI colours work?
- */
- if (colour > 7)
- return TXT_ERROR; /* No. */
- } else {
- /*
- * We can handle termcap colours and the number
- * is in range, so use termcap.
- */
- on |= is_fg ? TXT_ATTR_FG_TERMCAP :
- TXT_ATTR_BG_TERMCAP;
- }
- }
+
+ /* Out of range of termcap colours and basic ANSI set. */
+ if (tccan(tc) && colour > 7 && colour >= tccolours)
+ return TXT_ERROR;
+
return on | (zattr)colour << shft;
}
/*
* Match a set of highlights in the given teststr.
* Set *on_var to reflect the values found.
+ * Return a pointer to the first character not consumed.
*/
/**/
-mod_export void
+mod_export const char *
match_highlight(const char *teststr, zattr *on_var)
{
int found = 1;
@@ -1755,7 +1739,7 @@ match_highlight(const char *teststr, zattr *on_var)
atr = match_colour(&teststr, is_fg, 0);
if (*teststr == ',')
teststr++;
- else if (*teststr)
+ else if (*teststr && *teststr != ' ')
break;
found = 1;
/* skip out of range colours but keep scanning attributes */
@@ -1768,7 +1752,7 @@ match_highlight(const char *teststr, zattr *on_var)
if (*val == ',')
val++;
- else if (*val)
+ else if (*val && *val != ' ')
break;
*on_var |= hl->mask_on;
@@ -1779,6 +1763,8 @@ match_highlight(const char *teststr, zattr *on_var)
}
}
}
+
+ return teststr;
}
/*
@@ -1788,7 +1774,7 @@ match_highlight(const char *teststr, zattr *on_var)
*/
static int
-output_colour(int colour, int fg_bg, int use_tc, int truecol, char *buf)
+output_colour(int colour, int fg_bg, int truecol, char *buf)
{
int atrlen = 3, len;
char *ptr = buf;
@@ -1806,7 +1792,7 @@ output_colour(int colour, int fg_bg, int use_tc, int truecol, char *buf)
* used instead of termcap even for colour > 7. Here this just emits the
* color number, so it works fine for both zle_highlight and tercap cases
*/
- } else if (use_tc || colour > 7) {
+ } else if (colour > 7) {
char digbuf[DIGBUFSIZE];
sprintf(digbuf, "%d", colour);
len = strlen(digbuf);
@@ -1843,7 +1829,6 @@ output_highlight(zattr atr, char *buf)
if (atr & TXTFGCOLOUR) {
len = output_colour(txtchangeget(atr, TXT_ATTR_FG_COL),
COL_SEQ_FG,
- (atr & TXT_ATTR_FG_TERMCAP),
(atr & TXT_ATTR_FG_24BIT),
ptr);
atrlen += len;
@@ -1860,7 +1845,6 @@ output_highlight(zattr atr, char *buf)
}
len = output_colour(txtchangeget(atr, TXT_ATTR_BG_COL),
COL_SEQ_BG,
- (atr & TXT_ATTR_BG_TERMCAP),
(atr & TXT_ATTR_BG_24BIT),
ptr);
atrlen += len;
@@ -2025,7 +2009,6 @@ free_colour_buffer(void)
* fg_bg indicates if we're changing the foreground or background.
* tc indicates the termcap code to use, if appropriate.
* def indicates if we're resetting the default colour.
- * use_termcap indicates if we should use termcap to output colours.
* flags is either 0 or TSC_PROMPT.
*/
@@ -2035,7 +2018,7 @@ set_colour_attribute(zattr atr, int fg_bg, int flags)
{
char *ptr;
int do_free, is_prompt = (flags & TSC_PROMPT) ? 1 : 0;
- int colour, tc, def, use_termcap, use_truecolor;
+ int colour, tc, def, use_truecolor;
int is_default_zle_highlight = 1;
if (fg_bg == COL_SEQ_FG) {
@@ -2043,13 +2026,11 @@ set_colour_attribute(zattr atr, int fg_bg, int flags)
tc = TCFGCOLOUR;
def = txtchangeisset(atr, TXTNOFGCOLOUR);
use_truecolor = txtchangeisset(atr, TXT_ATTR_FG_24BIT);
- use_termcap = txtchangeisset(atr, TXT_ATTR_FG_TERMCAP);
} else {
colour = txtchangeget(atr, TXT_ATTR_BG_COL);
tc = TCBGCOLOUR;
def = txtchangeisset(atr, TXTNOBGCOLOUR);
use_truecolor = txtchangeisset(atr, TXT_ATTR_BG_24BIT);
- use_termcap = txtchangeisset(atr, TXT_ATTR_BG_TERMCAP);
}
/* Test if current zle_highlight settings are customized, or
@@ -2064,17 +2045,14 @@ set_colour_attribute(zattr atr, int fg_bg, int flags)
}
/*
- * If we're not restoring the default, and either have a
- * colour value that is too large for ANSI, or have been told
- * to use the termcap sequence, try to use the termcap sequence.
- * True color is not covered by termcap.
+ * If we're not restoring the default or applying true color,
+ * try to use the termcap sequence.
*
* We have already sanitised the values we allow from the
* highlighting variables, so much of this shouldn't be
* necessary at this point, but we might as well be safe.
*/
- if (!def && !use_truecolor &&
- (is_default_zle_highlight && (colour > 7 || use_termcap)))
+ if (!def && !use_truecolor && is_default_zle_highlight)
{
/*
* We can if it's available, and either we couldn't get
@@ -2094,7 +2072,8 @@ set_colour_attribute(zattr atr, int fg_bg, int flags)
*bv->bp++ = Outpar;
}
} else {
- tputs(tgoto(tcstr[tc], colour, colour), 1, putshout);
+ tputs(tgoto(tcstr[tc], colour, colour), 1,
+ (flags & TSC_RAW) ? putraw : putshout);
}
/* That worked. */
return;
@@ -2153,7 +2132,7 @@ set_colour_attribute(zattr atr, int fg_bg, int flags)
*bv->bp++ = Outpar;
}
} else
- tputs(colseq_buf, 1, putshout);
+ tputs(colseq_buf, 1, (flags & TSC_RAW) ? putraw : putshout);
if (do_free)
free_colour_buffer();