apply pango markup to colored text

This commit is contained in:
speedie 2023-03-04 02:07:06 +01:00
parent 8d458870d9
commit 73a9622c8e
2 changed files with 20 additions and 5 deletions

View file

@ -37,6 +37,7 @@ drawitem(struct item *item, int x, int y, int w)
int fg = 7; int fg = 7;
int bg = 0; int bg = 0;
int bgfg = 0; int bgfg = 0;
int ignore = 0;
int ib = 0; int ib = 0;
if (item == sel) { if (item == sel) {
@ -56,10 +57,8 @@ drawitem(struct item *item, int x, int y, int w)
if (item->text[rd + alen + 2] == 'm') { /* character is 'm' which is the last character in the sequence */ if (item->text[rd + alen + 2] == 'm') { /* character is 'm' which is the last character in the sequence */
buffer[wr] = '\0'; /* clear out character */ buffer[wr] = '\0'; /* clear out character */
/* draw text */ rw = pango_item ? TEXTWM(buffer) : TEXTW(buffer) - lrpad;
rw = TEXTWM(buffer) - lrpad; drw_text(drw, x, y, rw + lp, bh, lp, buffer, 0, pango_item ? True : False);
apply_fribidi(buffer);
drw_text(drw, x, y, rw + lp, bh, lp, isrtl ? fribidi_text : buffer, 0, pango_item ? True : False);
x += rw + lp; x += rw + lp;
ib = 1; ib = 1;
@ -70,6 +69,22 @@ drawitem(struct item *item, int x, int y, int w)
/* parse hex colors in scm */ /* parse hex colors in scm */
while (*ep != 'm') { while (*ep != 'm') {
unsigned v = strtoul(ep + 1, &ep, 10); unsigned v = strtoul(ep + 1, &ep, 10);
if (ignore)
continue;
if (bgfg) {
if (bgfg < 4 && v == 5) {
bgfg <<= 1;
continue;
}
if (bgfg == 4)
scm[0] = textclrs[fg = v];
else if (bgfg == 6)
scm[1] = textclrs[bg = v];
ignore = 1;
continue;
}
if (v == 1) { if (v == 1) {
fg |= 8; fg |= 8;
scm[0] = textclrs[fg]; scm[0] = textclrs[fg];

View file

@ -136,7 +136,7 @@ static char col_sgrcolor14[] = "#00ffff"; /* SGR color #14 */
static char col_sgrcolor15[] = "#ffffff"; /* SGR color #15 */ static char col_sgrcolor15[] = "#ffffff"; /* SGR color #15 */
/* Pango options */ /* Pango options */
static int pango_item = 1; /* Enable support for pango markup for the items */ static int pango_item = 0; /* Enable support for pango markup for the items */
static int pango_highlight = 1; /* Enable support for pango markup for the highlighting */ static int pango_highlight = 1; /* Enable support for pango markup for the highlighting */
static int pango_prompt = 1; /* Enable support for pango markup for the prompt */ static int pango_prompt = 1; /* Enable support for pango markup for the prompt */
static int pango_input = 1; /* Enable support for pango markup for user input */ static int pango_input = 1; /* Enable support for pango markup for user input */