From b5e3c2e721b19c0d95375d04a98786c94ed7d0b2 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 15 May 2013 10:11:47 -0700 Subject: [PATCH] Clear with NULL character. Do not include NULLs in copied text. --- protocols/ssh/include/common.h | 8 ++++++++ protocols/ssh/src/common.c | 8 ++++++++ protocols/ssh/src/display.c | 8 ++++---- protocols/ssh/src/terminal.c | 17 ++++++++++++----- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/protocols/ssh/include/common.h b/protocols/ssh/include/common.h index f945a558..effcd67f 100644 --- a/protocols/ssh/include/common.h +++ b/protocols/ssh/include/common.h @@ -38,6 +38,8 @@ #ifndef _SSH_GUAC_COMMON_H #define _SSH_GUAC_COMMON_H +#include + /** * Returns the closest value to the value given that is also * within the given range. @@ -50,5 +52,11 @@ int guac_terminal_fit_to_range(int value, int min, int max); */ int guac_terminal_encode_utf8(int codepoint, char* utf8); +/** + * Returns whether a codepoint has a corresponding glyph, or is rendered + * as a blank space. + */ +bool guac_terminal_has_glyph(int codepoint); + #endif diff --git a/protocols/ssh/src/common.c b/protocols/ssh/src/common.c index fcd5230a..00d6bdec 100644 --- a/protocols/ssh/src/common.c +++ b/protocols/ssh/src/common.c @@ -35,6 +35,8 @@ * * ***** END LICENSE BLOCK ***** */ +#include + int guac_terminal_fit_to_range(int value, int min, int max) { if (value < min) return min; @@ -90,3 +92,9 @@ int guac_terminal_encode_utf8(int codepoint, char* utf8) { } +bool guac_terminal_has_glyph(int codepoint) { + return + codepoint != 0 + && codepoint != ' '; +} + diff --git a/protocols/ssh/src/display.c b/protocols/ssh/src/display.c index 9afbfba3..9b0754db 100644 --- a/protocols/ssh/src/display.c +++ b/protocols/ssh/src/display.c @@ -547,7 +547,7 @@ void guac_terminal_display_resize(guac_terminal_display* display, int width, int /* Fill with background color (index 0) */ guac_terminal_char fill = { - .value = ' ', + .value = 0, .attributes = { .foreground = 0, .background = 0 @@ -743,7 +743,7 @@ void __guac_terminal_display_flush_clear(guac_terminal_display* display) { /* If operation is a cler operation (set to space) */ if (current->type == GUAC_CHAR_SET && - current->character.value == ' ') { + !guac_terminal_has_glyph(current->character.value)) { /* The determined bounds of the rectangle of contiguous * operations */ @@ -786,7 +786,7 @@ void __guac_terminal_display_flush_clear(guac_terminal_display* display) { /* If not identical operation, stop */ if (rect_current->type != GUAC_CHAR_SET - || rect_current->character.value != ' ' + || guac_terminal_has_glyph(rect_current->character.value) || joining_color != color) break; @@ -831,7 +831,7 @@ void __guac_terminal_display_flush_clear(guac_terminal_display* display) { /* Mark clear operations as NOP */ if (rect_current->type == GUAC_CHAR_SET - && rect_current->character.value == ' ' + && !guac_terminal_has_glyph(rect_current->character.value) && joining_color == color) rect_current->type = GUAC_CHAR_NOP; diff --git a/protocols/ssh/src/terminal.c b/protocols/ssh/src/terminal.c index 651c2056..cd175f80 100644 --- a/protocols/ssh/src/terminal.c +++ b/protocols/ssh/src/terminal.c @@ -58,7 +58,7 @@ guac_terminal* guac_terminal_create(guac_client* client, int width, int height) { guac_terminal_char default_char = { - .value = ' ', + .value = 0, .attributes = { .foreground = 7, .background = 0, @@ -208,7 +208,7 @@ int guac_terminal_clear_columns(guac_terminal* term, /* Build space */ guac_terminal_char blank; - blank.value = ' '; + blank.value = 0; blank.attributes = term->current_attributes; /* Clear */ @@ -415,9 +415,16 @@ int __guac_terminal_buffer_string(guac_terminal_buffer_row* row, int start, int int length = 0; int i; for (i=start; i<=end; i++) { - int bytes = guac_terminal_encode_utf8(row->characters[i].value, string); - string += bytes; - length += bytes; + + int codepoint = row->characters[i].value; + + /* If not null (blank), add to string */ + if (codepoint != 0) { + int bytes = guac_terminal_encode_utf8(codepoint, string); + string += bytes; + length += bytes; + } + } return length;