Prepare collapsible OSC 133 output for review

Use the parent output-range implementation and preserve source rows and columns when output is folded or wrapped. Clear stale exit-status presence on repeated D markers. Apply the requested coding style and add regressions for folded output selections and prompt properties.
This commit is contained in:
Michael Grant
2026-10-08 17:17:30 +02:00
parent 303ff3be8e
commit 0d65a0f60c
6 changed files with 680 additions and 334 deletions

70
input.c
View File

@@ -3203,8 +3203,13 @@ input_osc_133_save_marker(struct window_pane *wp, struct screen *s)
struct input_osc_133_ctx ctx = {0};
u_int y;
if (wp == NULL || s != &wp->base || SCREEN_IS_ALTERNATE(s) ||
(~wp->flags & PANE_CMDRUNNING))
if (wp == NULL)
return (ctx);
if (s != &wp->base)
return (ctx);
if (SCREEN_IS_ALTERNATE(s))
return (ctx);
if (~wp->flags & PANE_CMDRUNNING)
return (ctx);
ctx.running = 1;
ctx.start = UINT_MAX;
@@ -3218,12 +3223,14 @@ input_osc_133_save_marker(struct window_pane *wp, struct screen *s)
continue;
}
od = &gl->osc133_data;
if ((gl->flags & GRID_LINE_END_OUTPUT) &&
od->out_end_col >= od->out_start_col)
break;
if ((gl->flags & GRID_LINE_START_PROMPT) &&
od->prompt_col > od->out_start_col)
break;
if (gl->flags & GRID_LINE_END_OUTPUT) {
if (od->out_end_col >= od->out_start_col)
break;
}
if (gl->flags & GRID_LINE_START_PROMPT) {
if (od->prompt_col > od->out_start_col)
break;
}
ctx.start = y - 1;
ctx.col = od->out_start_col;
break;
@@ -3243,11 +3250,14 @@ input_osc_133_restore_marker(struct screen *s,
if (!ctx->running)
return;
collected = gd->scroll_collected - ctx->collected;
if (ctx->start != UINT_MAX && ctx->start >= collected) {
gl = grid_get_line(gd, ctx->start - collected);
if ((gl->flags & GRID_LINE_START_OUTPUT) &&
gl->osc133_data.out_start_col == ctx->col)
return;
if (ctx->start != UINT_MAX) {
if (ctx->start >= collected) {
gl = grid_get_line(gd, ctx->start - collected);
if (gl->flags & GRID_LINE_START_OUTPUT) {
if (gl->osc133_data.out_start_col == ctx->col)
return;
}
}
}
gl = grid_get_line(gd, gd->hsize);
gl->flags |= GRID_LINE_START_OUTPUT;
@@ -3331,11 +3341,15 @@ 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] == ';'))
p = cp + 3;
if (*p != 's') {
if (*p != 'c')
continue;
}
if (p[1] == '\0')
return (1);
if (p[1] == ';')
return (1);
p = cp;
}
return (0);
}
@@ -3344,8 +3358,9 @@ input_osc_133_secondary_prompt(const char *p)
static void
input_osc_133_mark_prompt(struct grid_line *gl, u_int col, const char *p)
{
if (gl == NULL || gl->flags &
(GRID_LINE_START_PROMPT|GRID_LINE_SECOND_PROMPT))
if (gl == NULL)
return;
if (gl->flags & (GRID_LINE_START_PROMPT|GRID_LINE_SECOND_PROMPT))
return;
gl->osc133_data.prompt_col = col;
if (input_osc_133_secondary_prompt(p))
@@ -3382,15 +3397,19 @@ input_osc_133(struct input_ctx *ictx, const char *p)
break;
case 'B':
case 'I':
if (gl != NULL && !(gl->flags & GRID_LINE_START_COMMAND)) {
gl->flags |= GRID_LINE_START_COMMAND;
gl->osc133_data.cmd_col = s->cx;
if (gl != NULL) {
if (~gl->flags & GRID_LINE_START_COMMAND) {
gl->flags |= GRID_LINE_START_COMMAND;
gl->osc133_data.cmd_col = s->cx;
}
}
break;
case 'C':
if (gl != NULL && !(gl->flags & GRID_LINE_START_OUTPUT)) {
gl->flags |= GRID_LINE_START_OUTPUT;
gl->osc133_data.out_start_col = s->cx;
if (gl != NULL) {
if (~gl->flags & GRID_LINE_START_OUTPUT) {
gl->flags |= GRID_LINE_START_OUTPUT;
gl->osc133_data.out_start_col = s->cx;
}
}
if (wp != NULL) {
wp->cmd_start_time = time(NULL);
@@ -3410,6 +3429,7 @@ input_osc_133(struct input_ctx *ictx, const char *p)
}
if (gl != NULL) {
gl->flags |= GRID_LINE_END_OUTPUT;
gl->flags &= ~GRID_LINE_END_OUTPUT_STATUS;
if (status_present)
gl->flags |= GRID_LINE_END_OUTPUT_STATUS;
gl->osc133_data.out_end_col = s->cx;