From: nerdopolis Date: Wed, 6 Dec 2023 05:08:01 +0000 (-0500) Subject: ply-terminal-emulator: Fix terminal emulator accuracy issues, don't pad with the... X-Git-Tag: 23.51.283~8^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc0b1333179cfb4100d522ab2380e2ced19a1720;p=thirdparty%2Fplymouth.git ply-terminal-emulator: Fix terminal emulator accuracy issues, don't pad with the active formatting --- diff --git a/src/libply-splash-core/ply-rich-text.c b/src/libply-splash-core/ply-rich-text.c index 3905cd58..83fa988e 100644 --- a/src/libply-splash-core/ply-rich-text.c +++ b/src/libply-splash-core/ply-rich-text.c @@ -140,6 +140,18 @@ ply_rich_text_get_length (ply_rich_text_t *rich_text) return length; } +void +ply_rich_text_character_style_init (ply_rich_text_character_style_t *default_style) +{ + default_style->foreground_color = PLY_TERMINAL_COLOR_DEFAULT; + default_style->background_color = PLY_TERMINAL_COLOR_DEFAULT; + default_style->bold_enabled = false; + default_style->dim_enabled = false; + default_style->italic_enabled = false; + default_style->underline_enabled = false; + default_style->reverse_enabled = false; +} + ply_rich_text_character_t * ply_rich_text_character_new (void) { @@ -215,6 +227,7 @@ ply_rich_text_move_character (ply_rich_text_t *rich_text, characters[old_index] = NULL; } + void ply_rich_text_set_character (ply_rich_text_t *rich_text, ply_rich_text_character_style_t style, diff --git a/src/libply-splash-core/ply-rich-text.h b/src/libply-splash-core/ply-rich-text.h index 632405bd..00735570 100644 --- a/src/libply-splash-core/ply-rich-text.h +++ b/src/libply-splash-core/ply-rich-text.h @@ -76,11 +76,11 @@ void ply_rich_text_move_character (ply_rich_text_t *rich_text, size_t new_index); void ply_rich_text_remove_character (ply_rich_text_t *rich_text, size_t character_index); - void ply_rich_text_remove_characters (ply_rich_text_t *rich_text); ply_rich_text_character_t **ply_rich_text_get_characters (ply_rich_text_t *rich_text); void ply_rich_text_free (ply_rich_text_t *rich_text); +void ply_rich_text_character_style_init (ply_rich_text_character_style_t *default_style); ply_rich_text_character_t *ply_rich_text_character_new (void); void ply_rich_text_character_free (ply_rich_text_character_t *character); diff --git a/src/libply-splash-core/ply-terminal-emulator.c b/src/libply-splash-core/ply-terminal-emulator.c index 3f610d05..9dbe21ab 100644 --- a/src/libply-splash-core/ply-terminal-emulator.c +++ b/src/libply-splash-core/ply-terminal-emulator.c @@ -157,13 +157,7 @@ ply_terminal_emulator_new (size_t number_of_rows, terminal_emulator->pending_commands = ply_list_new (); - terminal_emulator->current_style.foreground_color = PLY_TERMINAL_COLOR_DEFAULT; - terminal_emulator->current_style.background_color = PLY_TERMINAL_COLOR_DEFAULT; - terminal_emulator->current_style.bold_enabled = false; - terminal_emulator->current_style.dim_enabled = false; - terminal_emulator->current_style.italic_enabled = false; - terminal_emulator->current_style.underline_enabled = false; - terminal_emulator->current_style.reverse_enabled = false; + ply_rich_text_character_style_init (&terminal_emulator->current_style); return terminal_emulator; } @@ -212,13 +206,16 @@ fill_offsets_with_padding (ply_terminal_emulator_t *terminal_emulator, size_t pad_stop) { ssize_t bytes_to_pad = pad_stop - pad_start; + ply_rich_text_character_style_t default_style; + + ply_rich_text_character_style_init (&default_style); if (pad_start < 0 || bytes_to_pad <= 0) return; if (pad_stop > pad_start) { for (size_t i = pad_start; i <= pad_stop; i++) { - ply_rich_text_set_character (terminal_emulator->current_line, terminal_emulator->current_style, i, " ", 1); + ply_rich_text_set_character (terminal_emulator->current_line, default_style, i, " ", 1); } } } @@ -283,6 +280,7 @@ on_control_sequence_insert_blank_characters (ply_terminal_emulator_t *terminal_e size_t string_move_end_offset; ply_rich_text_span_t span; size_t maximum_characters; + ply_rich_text_character_style_t default_style; ply_trace ("terminal control sequence: insert blank characters"); @@ -323,11 +321,13 @@ on_control_sequence_insert_blank_characters (ply_terminal_emulator_t *terminal_e fill_offsets_with_padding (terminal_emulator, string_length, new_string_length); + ply_rich_text_character_style_init (&default_style); + for (int i = string_move_end_offset; i >= terminal_emulator->cursor_column; i--) { ply_rich_text_move_character (terminal_emulator->current_line, i, i + append_count); - ply_rich_text_set_character (terminal_emulator->current_line, terminal_emulator->current_style, i, " ", 1); + ply_rich_text_set_character (terminal_emulator->current_line, default_style, i, " ", 1); if (i <= 0) break; @@ -898,6 +898,7 @@ on_escape_character_tab (ply_terminal_emulator_t *terminal_emulator, size_t new_string_length; ply_rich_text_span_t span; size_t maximum_characters; + ply_rich_text_character_style_t default_style; ply_trace ("terminal escape character: tab"); @@ -934,8 +935,10 @@ on_escape_character_tab (ply_terminal_emulator_t *terminal_emulator, if (new_string_length >= maximum_characters - 1) new_string_length = maximum_characters - 1; + ply_rich_text_character_style_init (&default_style); + for (size_t i = string_length; i < new_string_length; i++) { - ply_rich_text_set_character (terminal_emulator->current_line, terminal_emulator->current_style, i, " ", 1); + ply_rich_text_set_character (terminal_emulator->current_line, default_style, i, " ", 1); } return PLY_TERMINAL_EMULATOR_BREAK_STRING_NONE;