summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorn3rdopolis <bluescreen_avenger@verizon.net>2023-03-19 22:42:41 -0400
committerRay Strode <rstrode@redhat.com>2023-12-02 18:19:33 -0500
commitd3d0c9d6505b1b9c5b61a8f14ad04438c23e89c5 (patch)
tree06f8adcdb23b03a2d5961b84ee02bc4e7a7504c7
parentd80237fad58454ee9f4a50b18f29876affe72da7 (diff)
space-flares: Get the messages from the console and ply-kmsg-reader, and use ply-terminal-emulator and ply-console-viewer to the display messages
-rw-r--r--src/plugins/splash/space-flares/plugin.c177
1 files changed, 176 insertions, 1 deletions
diff --git a/src/plugins/splash/space-flares/plugin.c b/src/plugins/splash/space-flares/plugin.c
index 2a942229..bea8acc6 100644
--- a/src/plugins/splash/space-flares/plugin.c
+++ b/src/plugins/splash/space-flares/plugin.c
@@ -54,6 +54,7 @@
#include "ply-pixel-display.h"
#include "ply-trigger.h"
#include "ply-utils.h"
+#include "ply-console-viewer.h"
#ifndef FRAMES_PER_SECOND
#define FRAMES_PER_SECOND 40
@@ -168,6 +169,8 @@ typedef struct
ply_list_t *sprites;
ply_rectangle_t box_area, lock_area, logo_area;
ply_image_t *scaled_background_image;
+
+ ply_console_viewer_t *console_viewer;
} view_t;
struct _ply_boot_splash_plugin
@@ -202,10 +205,26 @@ struct _ply_boot_splash_plugin
uint32_t root_is_mounted : 1;
uint32_t is_visible : 1;
uint32_t is_animating : 1;
+
+ char *monospace_font;
+ uint32_t plugin_console_messages_updating : 1;
+ uint32_t should_show_console_messages : 1;
+ ply_buffer_t *boot_buffer;
+ uint32_t console_text_color;
};
ply_boot_splash_plugin_interface_t *ply_boot_splash_plugin_get_interface (void);
static void detach_from_event_loop (ply_boot_splash_plugin_t *plugin);
+static bool validate_input (ply_boot_splash_plugin_t *plugin,
+ const char *entry_text,
+ const char *add_text);
+static void on_boot_output (ply_boot_splash_plugin_t *plugin,
+ const char *output,
+ size_t size);
+static void toggle_console_messages (ply_boot_splash_plugin_t *plugin);
+static void display_console_messages (ply_boot_splash_plugin_t *plugin);
+static void hide_console_messages (ply_boot_splash_plugin_t *plugin);
+static void unhide_console_messages (ply_boot_splash_plugin_t *plugin);
static view_t *
view_new (ply_boot_splash_plugin_t *plugin,
@@ -223,6 +242,16 @@ view_new (ply_boot_splash_plugin_t *plugin,
view->sprites = ply_list_new ();
+ if (ply_console_viewer_preferred ()) {
+ view->console_viewer = ply_console_viewer_new (view->display, plugin->monospace_font);
+ ply_console_viewer_set_text_color (view->console_viewer, plugin->console_text_color);
+
+ if (plugin->boot_buffer)
+ ply_console_viewer_convert_boot_buffer (view->console_viewer, plugin->boot_buffer);
+ } else {
+ view->console_viewer = NULL;
+ }
+
return view;
}
@@ -237,6 +266,9 @@ view_free (view_t *view)
view_free_sprites (view);
ply_list_free (view->sprites);
+ if (view->console_viewer)
+ ply_console_viewer_free (view->console_viewer);
+
ply_image_free (view->scaled_background_image);
free (view);
@@ -541,6 +573,21 @@ create_plugin (ply_key_file_t *key_file)
plugin->progress_barimage = ply_image_new (image_path);
free (image_path);
#endif
+
+ plugin->plugin_console_messages_updating = false;
+ plugin->should_show_console_messages = false;
+
+ /* Likely only able to set the font if the font is in the initrd */
+ plugin->monospace_font = ply_key_file_get_value (key_file, "two-step", "MonospaceFont");
+
+ if (plugin->monospace_font == NULL)
+ plugin->monospace_font = strdup ("monospace 10");
+
+ plugin->console_text_color =
+ ply_key_file_get_long (key_file, "two-step",
+ "ConsoleLogTextColor",
+ PLY_CONSOLE_VIEWER_LOG_TEXT_COLOR);
+
plugin->state = PLY_BOOT_SPLASH_DISPLAY_NORMAL;
plugin->progress = 0;
plugin->progress_target = -1;
@@ -564,6 +611,7 @@ destroy_plugin (ply_boot_splash_plugin_t *plugin)
ply_event_loop_stop_watching_for_exit (plugin->loop, (ply_event_loop_exit_handler_t)
detach_from_event_loop,
plugin);
+
detach_from_event_loop (plugin);
}
@@ -583,6 +631,8 @@ destroy_plugin (ply_boot_splash_plugin_t *plugin)
ply_image_free (plugin->progress_barimage);
#endif
+ free (plugin->monospace_font);
+
free_views (plugin);
free (plugin);
@@ -1346,6 +1396,10 @@ on_draw (view_t *view,
ply_label_draw_area (view->message_label,
pixel_buffer,
x, y, width, height);
+
+ if (plugin->plugin_console_messages_updating == false && view->console_viewer) {
+ ply_console_viewer_draw_area (view->console_viewer, pixel_buffer, x, y, width, height);
+ }
}
static void
@@ -1623,12 +1677,31 @@ show_splash_screen (ply_boot_splash_plugin_t *plugin,
ply_buffer_t *boot_buffer,
ply_boot_splash_mode_t mode)
{
+ ply_list_node_t *node;
+
assert (plugin != NULL);
assert (plugin->logo_image != NULL);
plugin->loop = loop;
plugin->mode = mode;
+ if (boot_buffer && ply_console_viewer_preferred ()) {
+ plugin->boot_buffer = boot_buffer;
+
+ node = ply_list_get_first_node (plugin->views);
+ while (node != NULL) {
+ view_t *view;
+ ply_list_node_t *next_node;
+
+ view = ply_list_node_get_data (node);
+ next_node = ply_list_get_next_node (plugin->views, node);
+
+ ply_console_viewer_convert_boot_buffer (view->console_viewer, plugin->boot_buffer);
+
+ node = next_node;
+ }
+ }
+
ply_trace ("loading logo image");
if (!ply_image_load (plugin->logo_image))
return false;
@@ -1795,7 +1868,12 @@ display_normal (ply_boot_splash_plugin_t *plugin)
hide_prompt (plugin);
plugin->state = PLY_BOOT_SPLASH_DISPLAY_NORMAL;
- start_animation (plugin);
+ if (!plugin->should_show_console_messages) {
+ start_animation (plugin);
+ } else {
+ unhide_console_messages (plugin);
+ }
+
redraw_views (plugin);
unpause_views (plugin);
}
@@ -1837,6 +1915,101 @@ display_message (ply_boot_splash_plugin_t *plugin,
show_message (plugin, message);
}
+static bool
+validate_input (ply_boot_splash_plugin_t *plugin,
+ const char *entry_text,
+ const char *add_text)
+{
+ if (!ply_console_viewer_preferred ())
+ return true;
+
+ if (strcmp (add_text, "\e") == 0) {
+ toggle_console_messages (plugin);
+ return false;
+ }
+
+ return true;
+}
+
+static void
+toggle_console_messages (ply_boot_splash_plugin_t *plugin)
+{
+ if (plugin->should_show_console_messages) {
+ plugin->should_show_console_messages = false;
+ hide_console_messages (plugin);
+ } else {
+ unhide_console_messages (plugin);
+ }
+}
+
+static void
+display_console_messages (ply_boot_splash_plugin_t *plugin)
+{
+ ply_list_node_t *node;
+ view_t *view;
+
+ pause_views (plugin);
+
+ plugin->plugin_console_messages_updating = true;
+ node = ply_list_get_first_node (plugin->views);
+ while (node != NULL) {
+ view = ply_list_node_get_data (node);
+ ply_console_viewer_show (view->console_viewer, view->display);
+ node = ply_list_get_next_node (plugin->views, node);
+ }
+ plugin->plugin_console_messages_updating = false;
+
+ redraw_views (plugin);
+ unpause_views (plugin);
+}
+
+static void
+unhide_console_messages (ply_boot_splash_plugin_t *plugin)
+{
+ plugin->should_show_console_messages = true;
+ stop_animation (plugin);
+ display_console_messages (plugin);
+}
+
+static void
+hide_console_messages (ply_boot_splash_plugin_t *plugin)
+{
+ ply_list_node_t *node;
+ view_t *view;
+
+ plugin->should_show_console_messages = false;
+
+ plugin->plugin_console_messages_updating = true;
+ node = ply_list_get_first_node (plugin->views);
+ while (node != NULL) {
+ view = ply_list_node_get_data (node);
+ ply_console_viewer_hide (view->console_viewer);
+ node = ply_list_get_next_node (plugin->views, node);
+ }
+ plugin->plugin_console_messages_updating = false;
+ if (plugin->state == PLY_BOOT_SPLASH_DISPLAY_NORMAL)
+ start_animation (plugin);
+}
+
+static void
+on_boot_output (ply_boot_splash_plugin_t *plugin,
+ const char *output,
+ size_t size)
+{
+ ply_list_node_t *node;
+ view_t *view;
+
+ if (!ply_console_viewer_preferred ())
+ return;
+
+ node = ply_list_get_first_node (plugin->views);
+ while (node != NULL) {
+ view = ply_list_node_get_data (node);
+ ply_console_viewer_parse_lines (view->console_viewer, output, size);
+ node = ply_list_get_next_node (plugin->views, node);
+ }
+}
+
ply_boot_splash_plugin_interface_t *
ply_boot_splash_plugin_get_interface (void)
{
@@ -1856,6 +2029,8 @@ ply_boot_splash_plugin_get_interface (void)
.display_password = display_password,
.display_question = display_question,
.display_message = display_message,
+ .on_boot_output = on_boot_output,
+ .validate_input = validate_input,
};
return &plugin_interface;