diff options
| author | Thomas Ulmer <thomasmulmer02@gmail.com> | 2025-12-20 15:30:02 -0800 |
|---|---|---|
| committer | Thomas Ulmer <thomasmulmer02@gmail.com> | 2025-12-20 15:30:02 -0800 |
| commit | c3a8504c0246df41cc5c82f5e2e07f6cb1cd5082 (patch) | |
| tree | 73fe03fcb3ec481a90b380a6bd0c03bca525d97b /st/st-0.9.3/st.c | |
| parent | eed90894d41a8e0892ea51d6be93369850c493b5 (diff) | |
st: undercurl
Diffstat (limited to 'st/st-0.9.3/st.c')
| -rw-r--r-- | st/st-0.9.3/st.c | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/st/st-0.9.3/st.c b/st/st-0.9.3/st.c index 20c45ec..9f2df77 100644 --- a/st/st-0.9.3/st.c +++ b/st/st-0.9.3/st.c @@ -35,6 +35,7 @@ #define UTF_SIZ 4 #define ESC_BUF_SIZ (128*UTF_SIZ) #define ESC_ARG_SIZ 16 +#define CAR_PER_ARG 4 #define STR_BUF_SIZ ESC_BUF_SIZ #define STR_ARG_SIZ ESC_ARG_SIZ #define HISTSIZE 2000 @@ -168,6 +169,7 @@ typedef struct { int arg[ESC_ARG_SIZ]; int narg; /* nb of args */ char mode[2]; + int carg[ESC_ARG_SIZ][CAR_PER_ARG]; /* colon args */ } CSIEscape; /* STR Escape sequence structs */ @@ -188,6 +190,7 @@ static void ttywriteraw(const char *, size_t); static void csidump(void); static void csihandle(void); +static void readcolonargs(char **, int, int[][CAR_PER_ARG]); static void csiparse(void); static void csireset(void); static void osc_color_response(int, int, int); @@ -1365,6 +1368,28 @@ tnewline(int first_col) } void +readcolonargs(char **p, int cursor, int params[][CAR_PER_ARG]) +{ + int i = 0; + for (; i < CAR_PER_ARG; i++) + params[cursor][i] = -1; + + if (**p != ':') + return; + + char *np = NULL; + i = 0; + + while (**p == ':' && i < CAR_PER_ARG) { + while (**p == ':') + (*p)++; + params[cursor][i] = strtol(*p, &np, 10); + *p = np; + i++; + } +} + +void csiparse(void) { char *p = csiescseq.buf, *np; @@ -1387,6 +1412,7 @@ csiparse(void) v = -1; csiescseq.arg[csiescseq.narg++] = v; p = np; + readcolonargs(&p, csiescseq.narg-1, csiescseq.carg); if (sep == ';' && *p == ':') sep = ':'; /* allow override to colon once */ if (*p != sep || csiescseq.narg == ESC_ARG_SIZ) @@ -1616,6 +1642,10 @@ tsetattr(const int *attr, int l) ATTR_STRUCK ); term.c.attr.fg = defaultfg; term.c.attr.bg = defaultbg; + term.c.attr.ustyle = -1; + term.c.attr.ucolor[0] = -1; + term.c.attr.ucolor[1] = -1; + term.c.attr.ucolor[2] = -1; break; case 1: term.c.attr.mode |= ATTR_BOLD; @@ -1627,7 +1657,12 @@ tsetattr(const int *attr, int l) term.c.attr.mode |= ATTR_ITALIC; break; case 4: - term.c.attr.mode |= ATTR_UNDERLINE; + term.c.attr.ustyle = csiescseq.carg[i][0]; + if (term.c.attr.ustyle != 0) + term.c.attr.mode |= ATTR_UNDERLINE; + else + term.c.attr.mode &= ~ATTR_UNDERLINE; + term.c.attr.mode ^= ATTR_DIRTYUNDERLINE; break; case 5: /* slow blink */ /* FALLTHROUGH */ @@ -1679,10 +1714,16 @@ tsetattr(const int *attr, int l) term.c.attr.bg = defaultbg; break; case 58: - /* This starts a sequence to change the color of - * "underline" pixels. We don't support that and - * instead eat up a following "5;n" or "2;r;g;b". */ - tdefcolor(attr, &i, l); + term.c.attr.ucolor[0] = csiescseq.carg[i][1]; + term.c.attr.ucolor[1] = csiescseq.carg[i][2]; + term.c.attr.ucolor[2] = csiescseq.carg[i][3]; + term.c.attr.mode ^= ATTR_DIRTYUNDERLINE; + break; + case 59: + term.c.attr.ucolor[0] = -1; + term.c.attr.ucolor[1] = -1; + term.c.attr.ucolor[2] = -1; + term.c.attr.mode ^= ATTR_DIRTYUNDERLINE; break; default: if (BETWEEN(attr[i], 30, 37)) { |
