From 74803ab3775ffdb8160ab79fd621f18d8e586813 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Thu, 1 Sep 2022 23:38:09 +0100 Subject: [PATCH] Recognise ED 3 as request to clear scrollback (MR428671) (thanks Russell McClellan) --- include/vterm.h | 2 ++ src/screen.c | 11 +++++++++++ src/state.c | 6 ++++++ t/13state_edit.test | 6 +++++- t/harness.c | 23 +++++++++++++++++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/vterm.h b/include/vterm.h index 8785794e..8106a543 100644 --- a/include/vterm.h +++ b/include/vterm.h @@ -427,6 +427,7 @@ typedef struct { int (*bell)(void *user); int (*resize)(int rows, int cols, VTermStateFields *fields, void *user); int (*setlineinfo)(int row, const VTermLineInfo *newinfo, const VTermLineInfo *oldinfo, void *user); + int (*sb_clear)(void *user); } VTermStateCallbacks; typedef struct { @@ -522,6 +523,7 @@ typedef struct { int (*resize)(int rows, int cols, void *user); int (*sb_pushline)(int cols, const VTermScreenCell *cells, void *user); int (*sb_popline)(int cols, VTermScreenCell *cells, void *user); + int (*sb_clear)(void* user); } VTermScreenCallbacks; VTermScreen *vterm_obtain_screen(VTerm *vt); diff --git a/src/screen.c b/src/screen.c index 37159199..db019f18 100644 --- a/src/screen.c +++ b/src/screen.c @@ -670,6 +670,16 @@ static int setlineinfo(int row, const VTermLineInfo *newinfo, const VTermLineInf return 1; } +static int sb_clear(void *user) { + VTermScreen *screen = user; + + if(screen->callbacks && screen->callbacks->sb_clear) + if((*screen->callbacks->sb_clear)(screen->cbdata)) + return 1; + + return 0; +} + static VTermStateCallbacks state_cbs = { .putglyph = &putglyph, .movecursor = &movecursor, @@ -680,6 +690,7 @@ static VTermStateCallbacks state_cbs = { .bell = &bell, .resize = &resize, .setlineinfo = &setlineinfo, + .sb_clear = &sb_clear, }; static VTermScreen *screen_new(VTerm *vt) diff --git a/src/state.c b/src/state.c index 8792c142..af4bb0a6 100644 --- a/src/state.c +++ b/src/state.c @@ -1091,6 +1091,12 @@ static int on_csi(const char *leader, const long args[], int argcount, const cha set_lineinfo(state, row, FORCE, DWL_OFF, DHL_OFF); erase(state, rect, selective); break; + + case 3: + if(state->callbacks && state->callbacks->sb_clear) + if((*state->callbacks->sb_clear)(state->cbdata)) + return 1; + break; } break; diff --git a/t/13state_edit.test b/t/13state_edit.test index b435655e..d3f3e9e4 100644 --- a/t/13state_edit.test +++ b/t/13state_edit.test @@ -1,6 +1,6 @@ INIT UTF8 1 -WANTSTATE se +WANTSTATE seb !ICH RESET @@ -242,6 +242,10 @@ PUSH "\e[2J" erase 0..25,0..80 ?cursor = 1,1 +!ED 3 +PUSH "\e[3J" + sb_clear + !SED RESET erase 0..25,0..80 diff --git a/t/harness.c b/t/harness.c index e75f9c35..1c080423 100644 --- a/t/harness.c +++ b/t/harness.c @@ -449,6 +449,15 @@ static int state_setlineinfo(int row, const VTermLineInfo *newinfo, const VTermL return 1; } +static int want_state_scrollback = 0; +static int state_sb_clear(void *user) { + if(!want_state_scrollback) + return 1; + + printf("sb_clear\n"); + return 0; +} + VTermStateCallbacks state_cbs = { .putglyph = state_putglyph, .movecursor = movecursor, @@ -458,6 +467,7 @@ VTermStateCallbacks state_cbs = { .setpenattr = state_setpenattr, .settermprop = settermprop, .setlineinfo = state_setlineinfo, + .sb_clear = state_sb_clear, }; static int selection_set(VTermSelectionMask mask, VTermStringFragment frag, void *user) @@ -567,6 +577,15 @@ static int screen_sb_popline(int cols, VTermScreenCell *cells, void *user) return 1; } +static int screen_sb_clear(void *user) +{ + if(!want_screen_scrollback) + return 1; + + printf("sb_clear\n"); + return 0; +} + VTermScreenCallbacks screen_cbs = { .damage = screen_damage, .moverect = moverect, @@ -574,6 +593,7 @@ VTermScreenCallbacks screen_cbs = { .settermprop = settermprop, .sb_pushline = screen_sb_pushline, .sb_popline = screen_sb_popline, + .sb_clear = screen_sb_clear, }; int main(int argc, char **argv) @@ -644,6 +664,9 @@ int main(int argc, char **argv) case 'f': vterm_state_set_unrecognised_fallbacks(state, sense ? &fallbacks : NULL, NULL); break; + case 'b': + want_state_scrollback = sense; + break; default: fprintf(stderr, "Unrecognised WANTSTATE flag '%c'\n", line[i]); }