Added title-parsing-fix v0.8.5 patch #10

Merged
syrell merged 1 commits from feat/title-parsing-fix into custom 2023-06-27 22:35:53 +02:00

34
st.c
View File

@ -42,6 +42,8 @@
#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f)) #define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c)) #define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
#define ISDELIM(u) (u && wcschr(worddelimiters, u)) #define ISDELIM(u) (u && wcschr(worddelimiters, u))
#define STRESCARGREST(n) ((n) == 0 ? strescseq.buf : strescseq.argp[(n)-1] + 1)
#define STRESCARGJUST(n) (*(strescseq.argp[n]) = '\0', STRESCARGREST(n))
enum term_mode { enum term_mode {
MODE_WRAP = 1 << 0, MODE_WRAP = 1 << 0,
@ -148,7 +150,7 @@ typedef struct {
char *buf; /* allocated raw string */ char *buf; /* allocated raw string */
size_t siz; /* allocation size */ size_t siz; /* allocation size */
size_t len; /* raw string length */ size_t len; /* raw string length */
char *args[STR_ARG_SIZ]; char *argp[STR_ARG_SIZ]; /* pointers to the end of nth argument */
int narg; /* nb of args */ int narg; /* nb of args */
} STREscape; } STREscape;
@ -1910,29 +1912,30 @@ strhandle(void)
}; };
term.esc &= ~(ESC_STR_END|ESC_STR); term.esc &= ~(ESC_STR_END|ESC_STR);
strparse(); strescseq.buf[strescseq.len] = '\0';
par = (narg = strescseq.narg) ? atoi(strescseq.args[0]) : 0;
switch (strescseq.type) { switch (strescseq.type) {
case ']': /* OSC -- Operating System Command */ case ']': /* OSC -- Operating System Command */
strparse();
par = (narg = strescseq.narg) ? atoi(STRESCARGJUST(0)) : 0;
switch (par) { switch (par) {
case 0: case 0:
if (narg > 1) { if (narg > 1) {
xsettitle(strescseq.args[1]); xsettitle(STRESCARGREST(1));
xseticontitle(strescseq.args[1]); xseticontitle(STRESCARGREST(1));
} }
return; return;
case 1: case 1:
if (narg > 1) if (narg > 1)
xseticontitle(strescseq.args[1]); xseticontitle(STRESCARGREST(1));
return; return;
case 2: case 2:
if (narg > 1) if (narg > 1)
xsettitle(strescseq.args[1]); xsettitle(STRESCARGREST(1));
return; return;
case 52: case 52:
if (narg > 2 && allowwindowops) { if (narg > 2 && allowwindowops) {
dec = base64dec(strescseq.args[2]); dec = base64dec(STRESCARGJUST(2));
if (dec) { if (dec) {
xsetsel(dec); xsetsel(dec);
xclipcopy(); xclipcopy();
@ -1946,7 +1949,7 @@ strhandle(void)
case 12: case 12:
if (narg < 2) if (narg < 2)
break; break;
p = strescseq.args[1]; p = STRESCARGREST(1);
if ((j = par - 10) < 0 || j >= LEN(osc_table)) if ((j = par - 10) < 0 || j >= LEN(osc_table))
break; /* shouldn't be possible */ break; /* shouldn't be possible */
@ -1962,10 +1965,10 @@ strhandle(void)
case 4: /* color set */ case 4: /* color set */
if (narg < 3) if (narg < 3)
break; break;
p = strescseq.args[2]; p = STRESCARGJUST(2);
/* FALLTHROUGH */ /* FALLTHROUGH */
case 104: /* color reset */ case 104: /* color reset */
j = (narg > 1) ? atoi(strescseq.args[1]) : -1; j = (narg > 1) ? atoi(STRESCARGJUST(1)) : -1;
if (p && !strcmp(p, "?")) { if (p && !strcmp(p, "?")) {
osc_color_response(j, 0, 1); osc_color_response(j, 0, 1);
@ -1987,7 +1990,7 @@ strhandle(void)
} }
break; break;
case 'k': /* old title set compatibility */ case 'k': /* old title set compatibility */
xsettitle(strescseq.args[0]); xsettitle(strescseq.buf);
return; return;
case 'P': /* DCS -- Device Control String */ case 'P': /* DCS -- Device Control String */
/* https://gitlab.com/gnachman/iterm2/-/wikis/synchronized-updates-spec */ /* https://gitlab.com/gnachman/iterm2/-/wikis/synchronized-updates-spec */
@ -2012,18 +2015,17 @@ strparse(void)
char *p = strescseq.buf; char *p = strescseq.buf;
strescseq.narg = 0; strescseq.narg = 0;
strescseq.buf[strescseq.len] = '\0';
if (*p == '\0') if (*p == '\0')
return; return;
while (strescseq.narg < STR_ARG_SIZ) { while (strescseq.narg < STR_ARG_SIZ) {
strescseq.args[strescseq.narg++] = p;
while ((c = *p) != ';' && c != '\0') while ((c = *p) != ';' && c != '\0')
++p; p++;
strescseq.argp[strescseq.narg++] = p;
if (c == '\0') if (c == '\0')
return; return;
*p++ = '\0'; p++;
} }
} }