]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
Introduce ply-terminal-emulator to handle parsing lines from /dev/console
authornerdopolis <bluescreen_avenger@verizon.net>
Sun, 28 May 2023 01:22:32 +0000 (21:22 -0400)
committernerdopolis <bluescreen_avenger@verizon.net>
Thu, 1 Jun 2023 02:45:06 +0000 (22:45 -0400)
src/libply-splash-core/meson.build
src/libply-splash-core/ply-terminal-emulator.c [new file with mode: 0644]
src/libply-splash-core/ply-terminal-emulator.h [new file with mode: 0644]

index bced940d3c4f074bc66c29bb14791329ef9045c0..b54e7f6d34da17d69326c4e5a0f1a5a46b6ce080 100644 (file)
@@ -8,6 +8,7 @@ libply_splash_core_sources = files(
   'ply-pixel-display.c',
   'ply-renderer.c',
   'ply-terminal.c',
+  'ply-terminal-emulator.c',
   'ply-text-display.c',
   'ply-text-progress-bar.c',
   'ply-text-step-bar.c',
@@ -62,6 +63,7 @@ libply_splash_core_headers = files(
   'ply-renderer-plugin.h',
   'ply-renderer.h',
   'ply-terminal.h',
+  'ply-terminal-emulator.h',
   'ply-text-display.h',
   'ply-text-progress-bar.h',
   'ply-text-step-bar.h',
diff --git a/src/libply-splash-core/ply-terminal-emulator.c b/src/libply-splash-core/ply-terminal-emulator.c
new file mode 100644 (file)
index 0000000..e44763e
--- /dev/null
@@ -0,0 +1,93 @@
+/* ply-terminal-emulator.c - Minimal Terminal Emulator
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ */
+
+#include "ply-list.h"
+#include "ply-terminal-emulator.h"
+#include "ply-logger.h"
+#include <stdlib.h>
+#include <string.h>
+
+#include <stdio.h>
+
+struct _ply_terminal_emulator
+{
+        ply_list_t *console_messages;
+        int         line_count;
+        int         cursor_row;
+        int         cursor_column;
+};
+
+ply_terminal_emulator_t *
+ply_terminal_emulator_new ()
+{
+        ply_terminal_emulator_t *terminal_emulator;
+
+        terminal_emulator = calloc (1, sizeof(struct _ply_terminal_emulator));
+
+        terminal_emulator->console_messages = ply_list_new ();
+        terminal_emulator->line_count = 0;
+
+        return terminal_emulator;
+}
+
+ply_list_t *
+ply_terminal_emulator_get_console_lines (ply_terminal_emulator_t *terminal_emulator)
+{
+        return terminal_emulator->console_messages;
+}
+
+void
+ply_terminal_emulator_parse_line (ply_terminal_emulator_t *terminal_emulator,
+                                  char                    *text)
+{
+        int node_number;
+        ply_list_node_t *node;
+
+        terminal_emulator->cursor_row = terminal_emulator->line_count - 1;
+        node_number = terminal_emulator->cursor_row;
+        if (node_number < 0)
+                node_number = 0;
+
+        node = ply_list_get_nth_node (terminal_emulator->console_messages, node_number);
+        ply_list_node_set_data (node, text);
+}
+
+void
+ply_terminal_emulator_parse_lines (ply_terminal_emulator_t *terminal_emulator,
+                                   char                    *text)
+{
+        char *text_substr, *saveptr;
+
+        text_substr = strtok_r (text, "\n", &saveptr);
+        while (text_substr != NULL) {
+                ply_list_append_data (terminal_emulator->console_messages, NULL);
+                terminal_emulator->line_count++;
+                ply_terminal_emulator_parse_line (terminal_emulator, text_substr);
+                text_substr = strtok_r (NULL, "\n", &saveptr);
+        }
+}
+
+void
+ply_terminal_emulator_convert_boot_buffer (ply_terminal_emulator_t *terminal_emulator,
+                                           ply_buffer_t            *boot_buffer)
+{
+        char *text = strndup (ply_buffer_get_bytes (boot_buffer), ply_buffer_get_size (boot_buffer));
+
+        ply_terminal_emulator_parse_lines (terminal_emulator, text);
+}
diff --git a/src/libply-splash-core/ply-terminal-emulator.h b/src/libply-splash-core/ply-terminal-emulator.h
new file mode 100644 (file)
index 0000000..d30ebd0
--- /dev/null
@@ -0,0 +1,35 @@
+/* ply-terminal-emulator.h - Minimal Terminal Emulator
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ */
+#ifndef PLY_TERMINAL_EMULATOR_H
+#define PLY_TERMINAL_EMULATOR_H
+
+#include "ply-boot-splash.h"
+#include <sys/syslog.h>
+
+typedef struct _ply_terminal_emulator ply_terminal_emulator_t;
+
+#ifndef PLY_HIDE_FUNCTION_DECLARATIONS
+ply_terminal_emulator_t *ply_terminal_emulator_new ();
+ply_list_t *ply_terminal_emulator_get_console_lines (ply_terminal_emulator_t *terminal_emulator);
+void ply_terminal_emulator_parse_lines (ply_terminal_emulator_t *terminal_emulator,
+                                        char                    *text);
+void ply_terminal_emulator_convert_boot_buffer (ply_terminal_emulator_t *terminal_emulator,
+                                                ply_buffer_t            *boot_buffer);
+#endif //PLY_HIDE_FUNCTION_DECLARATIONS
+#endif //PLY_TERMINAL_EMULATOR_H