Skip to content

Commit

Permalink
Added Screen level 'is_eol' predicate function
Browse files Browse the repository at this point in the history
  • Loading branch information
leonerd committed May 7, 2012
1 parent 55d61f7 commit f705973
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/vterm.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ typedef struct {

void vterm_screen_get_cell(VTermScreen *screen, VTermPos pos, VTermScreenCell *cell);

int vterm_screen_is_eol(VTermScreen *screen, VTermPos pos);

void vterm_input_push_char(VTerm *vt, VTermModifier state, uint32_t c);
void vterm_input_push_key(VTerm *vt, VTermModifier state, VTermKey key);

Expand Down
12 changes: 12 additions & 0 deletions src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,18 @@ void vterm_screen_get_cell(VTermScreen *screen, VTermPos pos, VTermScreenCell *c
cell->width = 1;
}

int vterm_screen_is_eol(VTermScreen *screen, VTermPos pos)
{
/* This cell is EOL if this and every cell to the right is black */
for(; pos.col < screen->cols; pos.col++) {
ScreenCell *cell = getcell(screen, pos.row, pos.col);
if(cell->chars[0] != 0)
return 0;
}

return 1;
}

VTermScreen *vterm_obtain_screen(VTerm *vt)
{
if(vt->screen)
Expand Down
3 changes: 3 additions & 0 deletions t/40screen_ascii.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ PUSH "ABC"
?screen_cell 0,1 = {0x42} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)
?screen_cell 0,2 = {0x43} width=1 attrs={} fg=rgb(240,240,240) bg=rgb(0,0,0)
?screen_row 0 = "ABC"
?screen_eol 0,0 = 0
?screen_eol 0,2 = 0
?screen_eol 0,3 = 1
PUSH "\e[H"
movecursor 0,0
?screen_chars 0,0,1,80 = 0x41,0x42,0x43
Expand Down
11 changes: 11 additions & 0 deletions t/harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,17 @@ int main(int argc, char **argv)
printf("fg=rgb(%d,%d,%d) ", cell.fg.red, cell.fg.green, cell.fg.blue);
printf("bg=rgb(%d,%d,%d)\n", cell.bg.red, cell.bg.green, cell.bg.blue);
}
else if(strstartswith(line, "?screen_eol ")) {
char *linep = line + 12;
while(linep[0] == ' ')
linep++;
VTermPos pos;
if(sscanf(linep, "%d,%d\n", &pos.row, &pos.col) < 2) {
printf("! screen_eol unrecognised input\n");
goto abort_line;
}
printf("%d\n", vterm_screen_is_eol(screen, pos));
}
else
printf("?\n");

Expand Down

0 comments on commit f705973

Please sign in to comment.