From 13616729e689caeca86499566616b1d2579cbda4 Mon Sep 17 00:00:00 2001 From: nerdopolis Date: Tue, 5 Dec 2023 21:10:49 -0500 Subject: [PATCH 1/6] ply-terminal-emulator: cleanup dead code --- src/libply-splash-core/ply-terminal-emulator.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/libply-splash-core/ply-terminal-emulator.c b/src/libply-splash-core/ply-terminal-emulator.c index 47526224..eb323f38 100644 --- a/src/libply-splash-core/ply-terminal-emulator.c +++ b/src/libply-splash-core/ply-terminal-emulator.c @@ -110,8 +110,6 @@ struct _ply_terminal_emulator ply_rich_text_t *current_line; ply_rich_text_character_style_t current_style; - - uint32_t default_colors_forced : 1; }; typedef ply_terminal_emulator_break_string_t (*ply_terminal_emulator_dispatch_handler_t)(); @@ -159,8 +157,6 @@ ply_terminal_emulator_new (size_t maximum_line_count) terminal_emulator->current_style.underline_enabled = false; terminal_emulator->current_style.reverse_enabled = false; - terminal_emulator->default_colors_forced = false; - return terminal_emulator; } @@ -1221,12 +1217,6 @@ ply_terminal_emulator_parse_substring (ply_terminal_emulator_t *terminal_emulato if (terminal_emulator->break_action == PLY_TERMINAL_EMULATOR_BREAK_STRING_ACTION_RESET_CURSOR_COLUMN) terminal_emulator->cursor_column = 0; - if (terminal_emulator->default_colors_forced == true) { - terminal_emulator->default_colors_forced = false; - terminal_emulator->current_style.foreground_color = PLY_TERMINAL_COLOR_DEFAULT; - terminal_emulator->current_style.background_color = PLY_TERMINAL_COLOR_DEFAULT; - } - terminal_emulator->current_line = NULL; } From 18c582f0ddb8aca9fb3eaa231a8c527ce270d63c Mon Sep 17 00:00:00 2001 From: nerdopolis Date: Wed, 6 Dec 2023 07:23:09 -0500 Subject: [PATCH 2/6] ply-terminal-emulator: Don't spam the debug logs with the two most-common commands --- src/libply-splash-core/ply-terminal-emulator.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libply-splash-core/ply-terminal-emulator.c b/src/libply-splash-core/ply-terminal-emulator.c index eb323f38..5ce0a8db 100644 --- a/src/libply-splash-core/ply-terminal-emulator.c +++ b/src/libply-splash-core/ply-terminal-emulator.c @@ -738,8 +738,6 @@ on_control_sequence_set_attributes (ply_terminal_emulator_t *terminal_emulator, ply_terminal_color_t default_foreground_color = PLY_TERMINAL_COLOR_DEFAULT; ply_terminal_color_t default_background_color = PLY_TERMINAL_COLOR_DEFAULT; - ply_trace ("terminal control sequence: set attributes"); - assert (code == 'm'); if (paramaters_valid != true) @@ -915,8 +913,6 @@ ply_terminal_emulator_break_string_t on_escape_character_linefeed (ply_terminal_emulator_t *terminal_emulator, const char code) { - ply_trace ("terminal escape character: line feed"); - assert (code == '\n' || code == '\v' || code == '\f'); terminal_emulator->cursor_row_offset++; From 149a1ce3e7fd09d7f37da5d82fb7b4eafaf9e871 Mon Sep 17 00:00:00 2001 From: nerdopolis Date: Tue, 5 Dec 2023 21:12:37 -0500 Subject: [PATCH 3/6] ply-terminal-emulator: Require a fixed upfront column count Some commands really do need to know how wide the terminal is to operate correctly. Without it long lines don't wrap right and other badness can happen. This commit addresses the problem by changing the terminal to take both a `number_of_rows` and `number_of_columns` argument at construct time instead of just a `maximum_line_count`. In order to properly implement that change, this commit also adds new api to `ply_rich_text_t` to specify which parts of a run of rich text is read-only and which parts of the run can be modified. Changes in this commit were made with assistance from Ray Strode --- src/libply-splash-core/ply-rich-text.c | 57 +++++++++++- src/libply-splash-core/ply-rich-text.h | 5 + .../ply-terminal-emulator.c | 93 +++++++++++++------ .../ply-terminal-emulator.h | 3 +- .../ply-console-viewer.c | 2 +- 5 files changed, 127 insertions(+), 33 deletions(-) diff --git a/src/libply-splash-core/ply-rich-text.c b/src/libply-splash-core/ply-rich-text.c index 13a9791f..3905cd58 100644 --- a/src/libply-splash-core/ply-rich-text.c +++ b/src/libply-splash-core/ply-rich-text.c @@ -29,8 +29,9 @@ struct _ply_rich_text_t { - ply_array_t *characters; - size_t reference_count; + ply_array_t *characters; + ply_rich_text_span_t span; + size_t reference_count; }; ply_rich_text_t * @@ -152,6 +153,9 @@ ply_rich_text_character_new (void) void ply_rich_text_character_free (ply_rich_text_character_t *character) { + if (character == NULL) + return; + free (character->bytes); free (character); } @@ -173,6 +177,13 @@ ply_rich_text_remove_character (ply_rich_text_t *rich_text, characters = ply_rich_text_get_characters (rich_text); + if (character_index < rich_text->span.offset) + return; + + if (character_index >= rich_text->span.offset + rich_text->span.range) + return; + + if (characters[character_index] == NULL) return; @@ -186,6 +197,20 @@ ply_rich_text_move_character (ply_rich_text_t *rich_text, size_t new_index) { ply_rich_text_character_t **characters = ply_rich_text_get_characters (rich_text); + + if (old_index < rich_text->span.offset) + return; + + if (new_index < rich_text->span.offset) + return; + + if (old_index >= rich_text->span.offset + rich_text->span.range) + return; + + if (new_index >= rich_text->span.offset + rich_text->span.range) + return; + + characters[new_index] = characters[old_index]; characters[old_index] = NULL; } @@ -200,12 +225,22 @@ ply_rich_text_set_character (ply_rich_text_t *rich_text, ply_rich_text_character_t **characters; ply_rich_text_character_t *character; + while (ply_array_get_size (rich_text->characters) <= character_index) { + ply_array_add_pointer_element (rich_text->characters, NULL); + } + + + if (character_index < rich_text->span.offset) + return; + + if (character_index >= rich_text->span.offset + rich_text->span.range) + return; + + characters = ply_rich_text_get_characters (rich_text); if (characters[character_index] == NULL) { character = ply_rich_text_character_new (); - ply_array_add_pointer_element (rich_text->characters, character); - characters = (ply_rich_text_character_t **) ply_array_get_pointer_elements (rich_text->characters); } else { character = characters[character_index]; if (character->bytes) { @@ -252,3 +287,17 @@ ply_rich_text_iterator_next (ply_rich_text_iterator_t *iterator, return true; } + +void +ply_rich_text_set_mutable_span (ply_rich_text_t *rich_text, + ply_rich_text_span_t *span) +{ + rich_text->span = *span; +} + +void +ply_rich_text_get_mutable_span (ply_rich_text_t *rich_text, + ply_rich_text_span_t *span) +{ + *span = rich_text->span; +} diff --git a/src/libply-splash-core/ply-rich-text.h b/src/libply-splash-core/ply-rich-text.h index 6455158c..632405bd 100644 --- a/src/libply-splash-core/ply-rich-text.h +++ b/src/libply-splash-core/ply-rich-text.h @@ -90,5 +90,10 @@ void ply_rich_text_iterator_init (ply_rich_text_iterator_t *iterator, bool ply_rich_text_iterator_next (ply_rich_text_iterator_t *iterator, ply_rich_text_character_t **character); +void ply_rich_text_set_mutable_span (ply_rich_text_t *rich_text, + ply_rich_text_span_t *span); +void ply_rich_text_get_mutable_span (ply_rich_text_t *rich_text, + ply_rich_text_span_t *span); + #endif //PLY_HIDE_FUNCTION_DECLARATIONS #endif //PLY_RICH_TEXT_H diff --git a/src/libply-splash-core/ply-terminal-emulator.c b/src/libply-splash-core/ply-terminal-emulator.c index 5ce0a8db..3f610d05 100644 --- a/src/libply-splash-core/ply-terminal-emulator.c +++ b/src/libply-splash-core/ply-terminal-emulator.c @@ -27,10 +27,6 @@ #include -#ifndef PLY_TERMINAL_LINE_MAX -#define PLY_TERMINAL_LINE_MAX 4096 -#endif - #define PLY_TERMINAL_SPACES_PER_TAB 8 /* Characters between 64 to 157 end the escape sequence strings (in testing) @@ -94,7 +90,9 @@ struct _ply_terminal_emulator { ply_terminal_emulator_parse_state_t state; - size_t maximum_line_count; + size_t number_of_rows; + size_t number_of_columns; + size_t line_count; ply_array_t *lines; @@ -127,17 +125,27 @@ static ply_terminal_emulator_command_t *ply_terminal_emulator_command_new (void) static void ply_terminal_emulator_command_free (ply_terminal_emulator_command_t *command); ply_terminal_emulator_t * -ply_terminal_emulator_new (size_t maximum_line_count) +ply_terminal_emulator_new (size_t number_of_rows, + size_t number_of_columns) { ply_terminal_emulator_t *terminal_emulator; + ply_rich_text_t *terminal_emulator_line; + ply_rich_text_span_t span; terminal_emulator = calloc (1, sizeof(struct _ply_terminal_emulator)); terminal_emulator->line_count = 1; - terminal_emulator->maximum_line_count = maximum_line_count; + terminal_emulator->number_of_rows = number_of_rows; + terminal_emulator->number_of_columns = number_of_columns; terminal_emulator->lines = ply_array_new (PLY_ARRAY_ELEMENT_TYPE_POINTER); - for (int i = 0; i < terminal_emulator->maximum_line_count; i++) { - ply_array_add_pointer_element (terminal_emulator->lines, ply_rich_text_new ()); + + span.offset = 0; + span.range = terminal_emulator->number_of_columns; + + for (int i = 0; i < terminal_emulator->number_of_rows; i++) { + terminal_emulator_line = ply_rich_text_new (); + ply_rich_text_set_mutable_span (terminal_emulator_line, &span); + ply_array_add_pointer_element (terminal_emulator->lines, terminal_emulator_line); } terminal_emulator->cursor_row_offset = 0; @@ -273,6 +281,8 @@ on_control_sequence_insert_blank_characters (ply_terminal_emulator_t *terminal_e size_t new_string_length; size_t append_count; size_t string_move_end_offset; + ply_rich_text_span_t span; + size_t maximum_characters; ply_trace ("terminal control sequence: insert blank characters"); @@ -293,17 +303,20 @@ on_control_sequence_insert_blank_characters (ply_terminal_emulator_t *terminal_e parameter = 1; } + ply_rich_text_get_mutable_span (terminal_emulator->current_line, &span); + maximum_characters = span.offset + span.range; + new_string_length = string_length + parameter; - if (new_string_length >= PLY_TERMINAL_LINE_MAX) { - append_count = PLY_TERMINAL_LINE_MAX - string_length - 1; - new_string_length = PLY_TERMINAL_LINE_MAX - 1; + if (new_string_length >= maximum_characters) { + append_count = maximum_characters - string_length - 1; + new_string_length = maximum_characters - 1; } else { append_count = parameter; } string_move_end_offset = string_length - 1; - if (string_move_end_offset >= PLY_TERMINAL_LINE_MAX) - string_move_end_offset = PLY_TERMINAL_LINE_MAX - 1; + if (string_move_end_offset >= maximum_characters) + string_move_end_offset = maximum_characters - 1; if (new_string_length <= 0) return PLY_TERMINAL_EMULATOR_BREAK_STRING_NONE; @@ -400,6 +413,8 @@ on_control_sequence_move_cursor_right (ply_terminal_emulator_t *terminal_emulato { int parameter; size_t string_length = ply_rich_text_get_length (terminal_emulator->current_line); + ply_rich_text_span_t span; + size_t maximum_characters; ply_trace ("terminal control sequence: move cursor right"); @@ -422,7 +437,10 @@ on_control_sequence_move_cursor_right (ply_terminal_emulator_t *terminal_emulato terminal_emulator->cursor_column += parameter; - if (terminal_emulator->cursor_column >= PLY_TERMINAL_LINE_MAX) + ply_rich_text_get_mutable_span (terminal_emulator->current_line, &span); + maximum_characters = span.offset + span.range; + + if (terminal_emulator->cursor_column >= maximum_characters) return PLY_TERMINAL_EMULATOR_BREAK_STRING; fill_offsets_with_padding (terminal_emulator, string_length, terminal_emulator->cursor_column); @@ -547,6 +565,8 @@ on_control_sequence_move_cursor_to_column (ply_terminal_emulator_t *terminal_emu bool paramaters_valid) { int parameter; + ply_rich_text_span_t span; + size_t maximum_characters; size_t string_length = ply_rich_text_get_length (terminal_emulator->current_line); @@ -569,7 +589,10 @@ on_control_sequence_move_cursor_to_column (ply_terminal_emulator_t *terminal_emu parameter = 1; } - if (parameter > PLY_TERMINAL_LINE_MAX) { + ply_rich_text_get_mutable_span (terminal_emulator->current_line, &span); + maximum_characters = span.offset + span.range; + + if (parameter > maximum_characters) { terminal_emulator->cursor_column = 1; } else { /* parameter is never 0. the column '1' represents the 0 index on the string */ @@ -596,6 +619,8 @@ on_control_sequence_erase_line (ply_terminal_emulator_t *terminal_emulator, size_t starting_offset = terminal_emulator->cursor_column; size_t string_length = ply_rich_text_get_length (terminal_emulator->current_line); size_t i; + ply_rich_text_span_t span; + size_t maximum_characters; ply_trace ("terminal control sequence: erase line"); @@ -617,8 +642,11 @@ on_control_sequence_erase_line (ply_terminal_emulator_t *terminal_emulator, erase_line_type = PLY_TERMINAL_EMULATOR_ERASE_LINE_TYPE_CURSOR_TO_RIGHT; } - if (starting_offset >= PLY_TERMINAL_LINE_MAX) - starting_offset = PLY_TERMINAL_LINE_MAX - 1; + ply_rich_text_get_mutable_span (terminal_emulator->current_line, &span); + maximum_characters = span.offset + span.range; + + if (starting_offset >= maximum_characters) + starting_offset = maximum_characters - 1; if (erase_line_type == PLY_TERMINAL_EMULATOR_ERASE_LINE_TYPE_CURSOR_TO_LEFT || erase_line_type == PLY_TERMINAL_EMULATOR_ERASE_LINE_TYPE_WHOLE_LINE) { /* Ensure that all characters from the start of the string to the cursor are spaces */ @@ -868,6 +896,8 @@ on_escape_character_tab (ply_terminal_emulator_t *terminal_emulator, size_t string_length = ply_rich_text_get_length (terminal_emulator->current_line); size_t new_cursor_position; size_t new_string_length; + ply_rich_text_span_t span; + size_t maximum_characters; ply_trace ("terminal escape character: tab"); @@ -881,9 +911,12 @@ on_escape_character_tab (ply_terminal_emulator_t *terminal_emulator, pad_character_count = PLY_TERMINAL_SPACES_PER_TAB - (terminal_emulator->cursor_column % PLY_TERMINAL_SPACES_PER_TAB); } + ply_rich_text_get_mutable_span (terminal_emulator->current_line, &span); + maximum_characters = span.offset + span.range; + new_cursor_position = terminal_emulator->cursor_column + pad_character_count; - if (new_cursor_position >= PLY_TERMINAL_LINE_MAX - 1) - new_cursor_position = PLY_TERMINAL_LINE_MAX - 1; + if (new_cursor_position >= maximum_characters - 1) + new_cursor_position = maximum_characters - 1; terminal_emulator->cursor_column = new_cursor_position; @@ -898,8 +931,8 @@ on_escape_character_tab (ply_terminal_emulator_t *terminal_emulator, new_string_length = string_length + pad_character_count; - if (new_string_length >= PLY_TERMINAL_LINE_MAX - 1) - new_string_length = PLY_TERMINAL_LINE_MAX - 1; + if (new_string_length >= maximum_characters - 1) + new_string_length = maximum_characters - 1; 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); @@ -1007,7 +1040,7 @@ ply_terminal_emulator_get_nth_line (ply_terminal_emulator_t *terminal_emulator, int line_number) { ply_rich_text_t *const *console_lines = (ply_rich_text_t *const *) ply_array_get_pointer_elements (terminal_emulator->lines); - return console_lines[line_number % terminal_emulator->maximum_line_count]; + return console_lines[line_number % terminal_emulator->number_of_rows]; } int @@ -1031,6 +1064,8 @@ ply_terminal_emulator_parse_substring (ply_terminal_emulator_t *terminal_emulato ply_terminal_emulator_break_string_t break_string = PLY_TERMINAL_EMULATOR_BREAK_STRING_NONE; int parameter_value; ply_terminal_emulator_command_t *command; + ply_rich_text_span_t span; + size_t maximum_characters; int character_length; ply_list_node_t *node; @@ -1044,7 +1079,10 @@ ply_terminal_emulator_parse_substring (ply_terminal_emulator_t *terminal_emulato return; } - if (terminal_emulator->cursor_column >= PLY_TERMINAL_LINE_MAX) + ply_rich_text_get_mutable_span (terminal_emulator->current_line, &span); + maximum_characters = span.offset + span.range; + + if (terminal_emulator->cursor_column >= maximum_characters) terminal_emulator->cursor_column = 0; new_length = ply_rich_text_get_length (terminal_emulator->current_line); @@ -1078,7 +1116,7 @@ ply_terminal_emulator_parse_substring (ply_terminal_emulator_t *terminal_emulato i++; - if (i >= PLY_TERMINAL_LINE_MAX) + if (i >= maximum_characters) break; } ply_rich_text_set_character (terminal_emulator->current_line, terminal_emulator->current_style, terminal_emulator->cursor_column, character_string, character_length); @@ -1103,8 +1141,9 @@ ply_terminal_emulator_parse_substring (ply_terminal_emulator_t *terminal_emulato ply_rich_text_set_character (terminal_emulator->current_line, terminal_emulator->current_style, terminal_emulator->cursor_column, character_string, 1); terminal_emulator->cursor_column++; - if (terminal_emulator->cursor_column >= PLY_TERMINAL_LINE_MAX) { - terminal_emulator->cursor_column = 0; + if (terminal_emulator->cursor_column >= maximum_characters) { + terminal_emulator->cursor_row_offset++; + terminal_emulator->break_action = PLY_TERMINAL_EMULATOR_BREAK_STRING_ACTION_RESET_CURSOR_COLUMN; break_string = PLY_TERMINAL_EMULATOR_BREAK_STRING; } } diff --git a/src/libply-splash-core/ply-terminal-emulator.h b/src/libply-splash-core/ply-terminal-emulator.h index 4fc93610..a189146d 100644 --- a/src/libply-splash-core/ply-terminal-emulator.h +++ b/src/libply-splash-core/ply-terminal-emulator.h @@ -52,7 +52,8 @@ typedef void (*ply_terminal_emulator_output_handler_t) (void *user_data, const char *output); #ifndef PLY_HIDE_FUNCTION_DECLARATIONS -ply_terminal_emulator_t *ply_terminal_emulator_new (size_t maximum_line_count); +ply_terminal_emulator_t *ply_terminal_emulator_new (size_t number_of_rows, + size_t number_of_columns); void ply_terminal_emulator_free (ply_terminal_emulator_t *terminal_emulator); void ply_terminal_emulator_parse_lines (ply_terminal_emulator_t *terminal_emulator, const char *text, diff --git a/src/libply-splash-graphics/ply-console-viewer.c b/src/libply-splash-graphics/ply-console-viewer.c index 274e389b..a41592df 100644 --- a/src/libply-splash-graphics/ply-console-viewer.c +++ b/src/libply-splash-graphics/ply-console-viewer.c @@ -100,7 +100,7 @@ ply_console_viewer_new (ply_pixel_display_t *display, ply_list_append_data (console_viewer->message_labels, console_message_label); } - console_viewer->terminal_emulator = ply_terminal_emulator_new (line_count); + console_viewer->terminal_emulator = ply_terminal_emulator_new (line_count, console_viewer->line_max_chars); ply_terminal_emulator_watch_for_output (console_viewer->terminal_emulator, (ply_terminal_emulator_output_handler_t) From fc0b1333179cfb4100d522ab2380e2ced19a1720 Mon Sep 17 00:00:00 2001 From: nerdopolis Date: Wed, 6 Dec 2023 00:08:01 -0500 Subject: [PATCH 4/6] ply-terminal-emulator: Fix terminal emulator accuracy issues, don't pad with the active formatting --- src/libply-splash-core/ply-rich-text.c | 13 +++++++++++ src/libply-splash-core/ply-rich-text.h | 2 +- .../ply-terminal-emulator.c | 23 +++++++++++-------- 3 files changed, 27 insertions(+), 11 deletions(-) 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; From 12435d8b867dec3c6522aa125271faee8f9a56ad Mon Sep 17 00:00:00 2001 From: nerdopolis Date: Wed, 6 Dec 2023 16:43:22 -0500 Subject: [PATCH 5/6] ply-rich-text: Rename functions from ending in _init to _initialize --- src/libply-splash-core/ply-rich-text.c | 8 ++++---- src/libply-splash-core/ply-rich-text.h | 8 ++++---- src/libply-splash-core/ply-terminal-emulator.c | 8 ++++---- src/plugins/controls/label-freetype/plugin.c | 12 ++++++------ 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/libply-splash-core/ply-rich-text.c b/src/libply-splash-core/ply-rich-text.c index 83fa988e..8e65b424 100644 --- a/src/libply-splash-core/ply-rich-text.c +++ b/src/libply-splash-core/ply-rich-text.c @@ -141,7 +141,7 @@ ply_rich_text_get_length (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_style_initialize (ply_rich_text_character_style_t *default_style) { default_style->foreground_color = PLY_TERMINAL_COLOR_DEFAULT; default_style->background_color = PLY_TERMINAL_COLOR_DEFAULT; @@ -269,9 +269,9 @@ ply_rich_text_set_character (ply_rich_text_t *rich_text, } void -ply_rich_text_iterator_init (ply_rich_text_iterator_t *iterator, - ply_rich_text_t *rich_text, - ply_rich_text_span_t *span) +ply_rich_text_iterator_initialize (ply_rich_text_iterator_t *iterator, + ply_rich_text_t *rich_text, + ply_rich_text_span_t *span) { iterator->rich_text = rich_text; iterator->span = *span; diff --git a/src/libply-splash-core/ply-rich-text.h b/src/libply-splash-core/ply-rich-text.h index 00735570..bce267cf 100644 --- a/src/libply-splash-core/ply-rich-text.h +++ b/src/libply-splash-core/ply-rich-text.h @@ -80,13 +80,13 @@ 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); +void ply_rich_text_character_style_initialize (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); -void ply_rich_text_iterator_init (ply_rich_text_iterator_t *iterator, - ply_rich_text_t *rich_text, - ply_rich_text_span_t *span); +void ply_rich_text_iterator_initialize (ply_rich_text_iterator_t *iterator, + ply_rich_text_t *rich_text, + ply_rich_text_span_t *span); bool ply_rich_text_iterator_next (ply_rich_text_iterator_t *iterator, 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 9dbe21ab..bc31d2d4 100644 --- a/src/libply-splash-core/ply-terminal-emulator.c +++ b/src/libply-splash-core/ply-terminal-emulator.c @@ -157,7 +157,7 @@ ply_terminal_emulator_new (size_t number_of_rows, terminal_emulator->pending_commands = ply_list_new (); - ply_rich_text_character_style_init (&terminal_emulator->current_style); + ply_rich_text_character_style_initialize (&terminal_emulator->current_style); return terminal_emulator; } @@ -208,7 +208,7 @@ fill_offsets_with_padding (ply_terminal_emulator_t *terminal_emulator, 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); + ply_rich_text_character_style_initialize (&default_style); if (pad_start < 0 || bytes_to_pad <= 0) return; @@ -321,7 +321,7 @@ 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); + ply_rich_text_character_style_initialize (&default_style); for (int i = string_move_end_offset; i >= terminal_emulator->cursor_column; i--) { ply_rich_text_move_character (terminal_emulator->current_line, @@ -935,7 +935,7 @@ 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); + ply_rich_text_character_style_initialize (&default_style); for (size_t i = string_length; i < new_string_length; i++) { ply_rich_text_set_character (terminal_emulator->current_line, default_style, i, " ", 1); diff --git a/src/plugins/controls/label-freetype/plugin.c b/src/plugins/controls/label-freetype/plugin.c index dfe4f3f0..487abcd3 100644 --- a/src/plugins/controls/label-freetype/plugin.c +++ b/src/plugins/controls/label-freetype/plugin.c @@ -242,9 +242,9 @@ size_control (ply_label_plugin_control_t *label) } if (label->rich_text != NULL) { - ply_rich_text_iterator_init (&rich_text_iterator, - label->rich_text, - &label->span); + ply_rich_text_iterator_initialize (&rich_text_iterator, + label->rich_text, + &label->span); } else { ply_utf8_string_iterator_init (&utf8_string_iterator, label->text, @@ -450,9 +450,9 @@ draw_control (ply_label_plugin_control_t *label, slot = label->face->glyph; if (label->rich_text != NULL) { - ply_rich_text_iterator_init (&rich_text_iterator, - label->rich_text, - &label->span); + ply_rich_text_iterator_initialize (&rich_text_iterator, + label->rich_text, + &label->span); } else { ply_utf8_string_iterator_init (&utf8_string_iterator, label->text, From 5af79f4ee6ef899275b2fa33a878e525cdacde48 Mon Sep 17 00:00:00 2001 From: nerdopolis Date: Wed, 6 Dec 2023 16:47:14 -0500 Subject: [PATCH 6/6] ply-utils: rename ply_utf8_string_iterator_init to ply_utf8_string_iterator_initialize --- src/libply/ply-utils.c | 8 ++++---- src/libply/ply-utils.h | 8 ++++---- src/plugins/controls/label-freetype/plugin.c | 16 ++++++++-------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c index ae50213b..cebeacc6 100644 --- a/src/libply/ply-utils.c +++ b/src/libply/ply-utils.c @@ -790,10 +790,10 @@ ply_utf8_string_get_byte_offset_from_character_offset (const char *string, } void -ply_utf8_string_iterator_init (ply_utf8_string_iterator_t *iterator, - const char *string, - ssize_t starting_offset, - ssize_t range) +ply_utf8_string_iterator_initialize (ply_utf8_string_iterator_t *iterator, + const char *string, + ssize_t starting_offset, + ssize_t range) { size_t byte_offset; diff --git a/src/libply/ply-utils.h b/src/libply/ply-utils.h index 289d3a3f..3e487b4e 100644 --- a/src/libply/ply-utils.h +++ b/src/libply/ply-utils.h @@ -127,10 +127,10 @@ int ply_utf8_string_get_length (const char *string, size_t ply_utf8_string_get_byte_offset_from_character_offset (const char *string, size_t character_offset); -void ply_utf8_string_iterator_init (ply_utf8_string_iterator_t *iterator, - const char *string, - ssize_t starting_offset, - ssize_t range); +void ply_utf8_string_iterator_initialize (ply_utf8_string_iterator_t *iterator, + const char *string, + ssize_t starting_offset, + ssize_t range); bool ply_utf8_string_iterator_next (ply_utf8_string_iterator_t *iterator, const char **character, size_t *size); diff --git a/src/plugins/controls/label-freetype/plugin.c b/src/plugins/controls/label-freetype/plugin.c index 487abcd3..7cf9ce73 100644 --- a/src/plugins/controls/label-freetype/plugin.c +++ b/src/plugins/controls/label-freetype/plugin.c @@ -246,10 +246,10 @@ size_control (ply_label_plugin_control_t *label) label->rich_text, &label->span); } else { - ply_utf8_string_iterator_init (&utf8_string_iterator, - label->text, - 0, - ply_utf8_string_get_length (label->text, strlen (label->text))); + ply_utf8_string_iterator_initialize (&utf8_string_iterator, + label->text, + 0, + ply_utf8_string_get_length (label->text, strlen (label->text))); } label->area.width = 0; label->area.height = 0; @@ -454,10 +454,10 @@ draw_control (ply_label_plugin_control_t *label, label->rich_text, &label->span); } else { - ply_utf8_string_iterator_init (&utf8_string_iterator, - label->text, - 0, - ply_utf8_string_get_length (label->text, strlen (label->text))); + ply_utf8_string_iterator_initialize (&utf8_string_iterator, + label->text, + 0, + ply_utf8_string_get_length (label->text, strlen (label->text))); } target = ply_pixel_buffer_get_argb32_data (pixel_buffer);