]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
ply-terminal-emulator: Fix terminal emulator accuracy issues, don't pad with the...
authornerdopolis <bluescreen_avenger@verizon.net>
Wed, 6 Dec 2023 05:08:01 +0000 (00:08 -0500)
committern3rdopolis <bluescreenavenger@gmail.com>
Wed, 6 Dec 2023 22:47:44 +0000 (22:47 +0000)
src/libply-splash-core/ply-rich-text.c
src/libply-splash-core/ply-rich-text.h
src/libply-splash-core/ply-terminal-emulator.c

index 3905cd5842b313ec9ecb314a35539e84f3804f14..83fa988e0b05fcfc34c7358b695f3a87706e6699 100644 (file)
@@ -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,
index 632405bdf0316ba4d46e8757a389b4b4240bf16c..0073557061bda627fe68c0ec2198503731259e94 100644 (file)
@@ -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);
 
index 3f610d05dc1a81d3485d20b452b801334ecaf1d3..9dbe21ab5a9119f081948e0c884bf145d2972862 100644 (file)
@@ -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;