From: nerdopolis Date: Sun, 28 May 2023 01:22:32 +0000 (-0400) Subject: Introduce ply-terminal-emulator to handle parsing lines from /dev/console X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e1d2b88394ac5d3f221f323b177e22dc7344dec;p=thirdparty%2Fplymouth.git Introduce ply-terminal-emulator to handle parsing lines from /dev/console --- diff --git a/src/libply-splash-core/meson.build b/src/libply-splash-core/meson.build index bced940d..b54e7f6d 100644 --- a/src/libply-splash-core/meson.build +++ b/src/libply-splash-core/meson.build @@ -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 index 00000000..e44763e2 --- /dev/null +++ b/src/libply-splash-core/ply-terminal-emulator.c @@ -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 +#include + +#include + +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 index 00000000..d30ebd00 --- /dev/null +++ b/src/libply-splash-core/ply-terminal-emulator.h @@ -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 + +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