From 3a50c9572d90d553333d050e0c0af5be248e3bb8 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 26 Apr 2013 14:52:51 -0700 Subject: [PATCH] Clear cells when resizing or scrolling. --- protocols/ssh/src/display.c | 34 +++++++++++++++++++++++++++------- protocols/ssh/src/terminal.c | 27 +++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/protocols/ssh/src/display.c b/protocols/ssh/src/display.c index 40fde422..ede7f16e 100644 --- a/protocols/ssh/src/display.c +++ b/protocols/ssh/src/display.c @@ -410,9 +410,14 @@ void guac_terminal_display_resize(guac_terminal_display* display, int width, int guac_terminal_operation* current; int x, y; - /* Set width and height */ - display->width = width; - display->height = height; + /* Fill with background color (index 0) */ + guac_terminal_char fill = { + .value = ' ', + .attributes = { + .foreground = 0, + .background = 0 + } + }; /* Free old operations buffer */ if (display->operations != NULL) @@ -427,19 +432,34 @@ void guac_terminal_display_resize(guac_terminal_display* display, int width, int for (y=0; ytype = GUAC_CHAR_NOP; + for (x=0; xwidth && y < display->height) + current->type = GUAC_CHAR_NOP; + + /* Otherwise, clear contents first */ + else { + current->type = GUAC_CHAR_SET; + current->character = fill; + } + + current++; + + } } + /* Set width and height */ + display->width = width; + display->height = height; + /* Send initial display size */ guac_protocol_send_size(display->client->socket, GUAC_DEFAULT_LAYER, display->char_width * width, display->char_height * height); - - } void __guac_terminal_display_flush_copy(guac_terminal_display* display) { diff --git a/protocols/ssh/src/terminal.c b/protocols/ssh/src/terminal.c index 54f26cdb..8419b63e 100644 --- a/protocols/ssh/src/terminal.c +++ b/protocols/ssh/src/terminal.c @@ -162,8 +162,21 @@ int guac_terminal_write(guac_terminal* term, const char* c, int size) { int guac_terminal_scroll_up(guac_terminal* term, int start_row, int end_row, int amount) { - /* Copy row data upwards */ - guac_terminal_copy_rows(term, start_row + amount, end_row, -amount); + /* If scrolling entire display, update scroll offset */ + if (start_row == 0 && end_row == term->term_height - 1) { + + /* Scroll up visibly */ + guac_terminal_display_copy_rows(term->display, start_row + amount, end_row, -amount); + + /* Advance by scroll amount */ + term->buffer->top += amount; + term->buffer->length += amount; + + } + + /* Otherwise, just copy row data upwards */ + else + guac_terminal_copy_rows(term, start_row + amount, end_row, -amount); /* Clear new area */ guac_terminal_clear_range(term, @@ -274,8 +287,11 @@ void guac_terminal_scroll_display_down(guac_terminal* terminal, guac_terminal_buffer_row* buffer_row = guac_terminal_buffer_get_row(terminal->buffer, row, 0); + /* Clear row */ + guac_terminal_display_set_columns(terminal->display, + dest_row, 0, terminal->display->width, &(terminal->default_char)); + /* Draw row */ - /* FIXME: Clear row first */ guac_terminal_char* current = buffer_row->characters; for (column=0; columnlength; column++) guac_terminal_display_set_columns(terminal->display, @@ -329,8 +345,11 @@ void guac_terminal_scroll_display_up(guac_terminal* terminal, guac_terminal_buffer_row* buffer_row = guac_terminal_buffer_get_row(terminal->buffer, row, 0); + /* Clear row */ + guac_terminal_display_set_columns(terminal->display, + dest_row, 0, terminal->display->width, &(terminal->default_char)); + /* Draw row */ - /* FIXME: Clear row first */ guac_terminal_char* current = buffer_row->characters; for (column=0; columnlength; column++) guac_terminal_display_set_columns(terminal->display,