From 7c9fdcb770eb4e8b6c93a4e37d90ba8e57e9287b Mon Sep 17 00:00:00 2001 From: Michael Grant Date: Fri, 31 Jul 2026 10:39:09 +0100 Subject: [PATCH] Add k=c and a helper function to check for secondary prompt. --- input.c | 29 ++++++++++++++++++++++------- regress/input-modes.sh | 16 +++++++++++----- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/input.c b/input.c index dcf02eb95..5efb5c355 100644 --- a/input.c +++ b/input.c @@ -3197,7 +3197,7 @@ input_osc_133_exit_status(const char *p, int *present) { const char *end; char *copy; - const char *errstr; + char *endptr; long long status; *present = 0; @@ -3215,9 +3215,10 @@ input_osc_133_exit_status(const char *p, int *present) return (0); } *present = 1; - status = strtonum(copy, 0, 255, &errstr); + errno = 0; + status = (int)strtol(copy, &endptr, 10); free(copy); - if (errstr != NULL) + if (errno != 0 || endptr == copy || status < 0 || status > 255) return (255); return (status); } @@ -3262,6 +3263,22 @@ input_fire_command_event(struct window_pane *wp, const char *name) events_fire(name, ep); } +/* Check if an OSC 133 prompt is secondary or a continuation. */ +static int +input_osc_133_secondary_prompt(const char *p) +{ + const char *cp; + + while ((cp = strstr(p, ";k=")) != NULL) { + cp += 3; + if ((*cp == 's' || *cp == 'c') && + (cp[1] == '\0' || cp[1] == ';')) + return (1); + p = cp; + } + return (0); +} + /* Handle the OSC 133 sequence. */ static void input_osc_133(struct input_ctx *ictx, const char *p) @@ -3271,7 +3288,6 @@ input_osc_133(struct input_ctx *ictx, const char *p) struct grid *gd = s->grid; u_int line = s->cy + gd->hsize; struct grid_line *gl = NULL; - const char *cp; int status, status_present; if (line < gd->hsize + gd->sy) @@ -3284,7 +3300,7 @@ input_osc_133(struct input_ctx *ictx, const char *p) if (!(gl->flags & (GRID_LINE_START_PROMPT| GRID_LINE_SECOND_PROMPT))) { gl->osc133_data.prompt_col = s->cx; - if (strstr(p + 1, ";k=s") != NULL) + if (input_osc_133_secondary_prompt(p)) gl->flags |= GRID_LINE_SECOND_PROMPT; else gl->flags |= GRID_LINE_START_PROMPT; @@ -3297,11 +3313,10 @@ input_osc_133(struct input_ctx *ictx, const char *p) break; case 'P': if (gl != NULL) { - cp = strstr(p, ";k=s"); if (!(gl->flags & (GRID_LINE_START_PROMPT| GRID_LINE_SECOND_PROMPT))) { gl->osc133_data.prompt_col = s->cx; - if (cp != NULL && (cp[4] == ';' || cp[4] == '\0')) + if (input_osc_133_secondary_prompt(p)) gl->flags |= GRID_LINE_SECOND_PROMPT; else gl->flags |= GRID_LINE_START_PROMPT; diff --git a/regress/input-modes.sh b/regress/input-modes.sh index 8ae905f89..cf0e5f875 100644 --- a/regress/input-modes.sh +++ b/regress/input-modes.sh @@ -5,9 +5,12 @@ start_pane alternate 10 3 'MAIN\033[?1049hALT\033[?1049lZ\n' check_capture alternate 'MAINZ' -start_pane osc133 20 8 'xx\033]133;A\007p>\033]133;B\007cmd\nxy\033]133;P;k=s\007more\nzz\033]133;C\007out\033]133;D;7\007\nq\033]133;C\007bad\033]133;D;-1\007\nqq\033]133;C\007big\033]133;D;300\007\nzzz\033]133;C\007ok\033]133;D\007\n' +start_pane osc133 20 12 'xx\033]133;A\007p>\033]133;B\007cmd\nxy\033]133;P;k=s\007more\nxz\033]133;A;k=s\007more\nxw\033]133;P;k=c\007more\nxv\033]133;A;k=c\007more\nzz\033]133;C\007out\033]133;D;7\007\nq\033]133;C\007bad\033]133;D;-1\007\nqq\033]133;C\007big\033]133;D;300\007\nzzz\033]133;C\007ok\033]133;D\007\n' check_capture osc133 'xxp>cmd xymore +xzmore +xwmore +xvmore zzout qbad qqbig @@ -15,10 +18,13 @@ zzzok' check_raw_matches osc133 \ 'L 0 \(0\) flags=START_PROMPT,START_COMMAND\[[0-9a-f]+\].* osc133=2,4,0,0,0' \ 'L 1 \(1\) flags=SECOND_PROMPT\[[0-9a-f]+\].* osc133=2,0,0,0,0' \ - 'L 2 \(2\) flags=START_OUTPUT,END_OUTPUT\[[0-9a-f]+\].* osc133=0,0,2,5,7' \ - 'L 3 \(3\) flags=START_OUTPUT,END_OUTPUT\[[0-9a-f]+\].* osc133=0,0,1,4,255' \ - 'L 4 \(4\) flags=START_OUTPUT,END_OUTPUT\[[0-9a-f]+\].* osc133=0,0,2,5,255' \ - 'L 5 \(5\) flags=START_OUTPUT,END_OUTPUT\[[0-9a-f]+\].* osc133=0,0,3,5,0' + 'L 2 \(2\) flags=SECOND_PROMPT\[[0-9a-f]+\].* osc133=2,0,0,0,0' \ + 'L 3 \(3\) flags=SECOND_PROMPT\[[0-9a-f]+\].* osc133=2,0,0,0,0' \ + 'L 4 \(4\) flags=SECOND_PROMPT\[[0-9a-f]+\].* osc133=2,0,0,0,0' \ + 'L 5 \(5\) flags=START_OUTPUT,END_OUTPUT,END_OUTPUT_STATUS\[[0-9a-f]+\].* osc133=0,0,2,5,7' \ + 'L 6 \(6\) flags=START_OUTPUT,END_OUTPUT,END_OUTPUT_STATUS\[[0-9a-f]+\].* osc133=0,0,1,4,255' \ + 'L 7 \(7\) flags=START_OUTPUT,END_OUTPUT,END_OUTPUT_STATUS\[[0-9a-f]+\].* osc133=0,0,2,5,255' \ + 'L 8 \(8\) flags=START_OUTPUT,END_OUTPUT\[[0-9a-f]+\].* osc133=0,0,3,5,0' $TMUX kill-server 2>/dev/null exit $exit_status