Skip to content

Commit

Permalink
Recognise ED 3 as request to clear scrollback (MR428671) (thanks Russ…
Browse files Browse the repository at this point in the history
…ell McClellan)
  • Loading branch information
leonerd committed Sep 1, 2022
1 parent fb57fbe commit 74803ab
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/vterm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -680,6 +690,7 @@ static VTermStateCallbacks state_cbs = {
.bell = &bell,
.resize = &resize,
.setlineinfo = &setlineinfo,
.sb_clear = &sb_clear,
};

static VTermScreen *screen_new(VTerm *vt)
Expand Down
6 changes: 6 additions & 0 deletions src/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 5 additions & 1 deletion t/13state_edit.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
INIT
UTF8 1
WANTSTATE se
WANTSTATE seb

!ICH
RESET
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions t/harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -567,13 +577,23 @@ 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,
.movecursor = movecursor,
.settermprop = settermprop,
.sb_pushline = screen_sb_pushline,
.sb_popline = screen_sb_popline,
.sb_clear = screen_sb_clear,
};

int main(int argc, char **argv)
Expand Down Expand Up @@ -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]);
}
Expand Down

0 comments on commit 74803ab

Please sign in to comment.