Clear with NULL character. Do not include NULLs in copied text.

This commit is contained in:
Michael Jumper 2013-05-15 10:11:47 -07:00
parent ce21f2c883
commit b5e3c2e721
4 changed files with 32 additions and 9 deletions

View File

@ -38,6 +38,8 @@
#ifndef _SSH_GUAC_COMMON_H #ifndef _SSH_GUAC_COMMON_H
#define _SSH_GUAC_COMMON_H #define _SSH_GUAC_COMMON_H
#include <stdbool.h>
/** /**
* Returns the closest value to the value given that is also * Returns the closest value to the value given that is also
* within the given range. * 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); 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 #endif

View File

@ -35,6 +35,8 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include <stdbool.h>
int guac_terminal_fit_to_range(int value, int min, int max) { int guac_terminal_fit_to_range(int value, int min, int max) {
if (value < min) return min; 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 != ' ';
}

View File

@ -547,7 +547,7 @@ void guac_terminal_display_resize(guac_terminal_display* display, int width, int
/* Fill with background color (index 0) */ /* Fill with background color (index 0) */
guac_terminal_char fill = { guac_terminal_char fill = {
.value = ' ', .value = 0,
.attributes = { .attributes = {
.foreground = 0, .foreground = 0,
.background = 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 operation is a cler operation (set to space) */
if (current->type == GUAC_CHAR_SET && if (current->type == GUAC_CHAR_SET &&
current->character.value == ' ') { !guac_terminal_has_glyph(current->character.value)) {
/* The determined bounds of the rectangle of contiguous /* The determined bounds of the rectangle of contiguous
* operations */ * operations */
@ -786,7 +786,7 @@ void __guac_terminal_display_flush_clear(guac_terminal_display* display) {
/* If not identical operation, stop */ /* If not identical operation, stop */
if (rect_current->type != GUAC_CHAR_SET if (rect_current->type != GUAC_CHAR_SET
|| rect_current->character.value != ' ' || guac_terminal_has_glyph(rect_current->character.value)
|| joining_color != color) || joining_color != color)
break; break;
@ -831,7 +831,7 @@ void __guac_terminal_display_flush_clear(guac_terminal_display* display) {
/* Mark clear operations as NOP */ /* Mark clear operations as NOP */
if (rect_current->type == GUAC_CHAR_SET if (rect_current->type == GUAC_CHAR_SET
&& rect_current->character.value == ' ' && !guac_terminal_has_glyph(rect_current->character.value)
&& joining_color == color) && joining_color == color)
rect_current->type = GUAC_CHAR_NOP; rect_current->type = GUAC_CHAR_NOP;

View File

@ -58,7 +58,7 @@ guac_terminal* guac_terminal_create(guac_client* client,
int width, int height) { int width, int height) {
guac_terminal_char default_char = { guac_terminal_char default_char = {
.value = ' ', .value = 0,
.attributes = { .attributes = {
.foreground = 7, .foreground = 7,
.background = 0, .background = 0,
@ -208,7 +208,7 @@ int guac_terminal_clear_columns(guac_terminal* term,
/* Build space */ /* Build space */
guac_terminal_char blank; guac_terminal_char blank;
blank.value = ' '; blank.value = 0;
blank.attributes = term->current_attributes; blank.attributes = term->current_attributes;
/* Clear */ /* Clear */
@ -415,9 +415,16 @@ int __guac_terminal_buffer_string(guac_terminal_buffer_row* row, int start, int
int length = 0; int length = 0;
int i; int i;
for (i=start; i<=end; i++) { for (i=start; i<=end; i++) {
int bytes = guac_terminal_encode_utf8(row->characters[i].value, string);
string += bytes; int codepoint = row->characters[i].value;
length += bytes;
/* If not null (blank), add to string */
if (codepoint != 0) {
int bytes = guac_terminal_encode_utf8(codepoint, string);
string += bytes;
length += bytes;
}
} }
return length; return length;