diff options
| author | Ray Strode <rstrode@redhat.com> | 2008-05-23 01:00:28 -0400 |
|---|---|---|
| committer | Ray Strode <rstrode@redhat.com> | 2008-05-23 01:00:28 -0400 |
| commit | 7e14cb94526e222061774e5ed3adfc9751a53928 (patch) | |
| tree | e585db9a149d546bac278196faaf434d27ad032f /src/splash-plugins/text | |
| parent | d2b4a3ef73738f5a5a131f630a33e3a0b6e5d6de (diff) | |
| download | plymouth-7e14cb94526e222061774e5ed3adfc9751a53928.tar.gz plymouth-7e14cb94526e222061774e5ed3adfc9751a53928.tar.xz plymouth-7e14cb94526e222061774e5ed3adfc9751a53928.zip | |
Move keyboard handling to window so we can do line editing
The logic for line editing is a little complicated, so it's
best not to duplicate it across all the plugins. Now we
manage it all from the window. The plugins now access the
various editing events via there vtable, but that's an
extra layer of indirection that doesn't matter given that
we pass the window to the plugins anyway. We should drop
that and just have the plugins register for edit events
directly.
Diffstat (limited to 'src/splash-plugins/text')
| -rw-r--r-- | src/splash-plugins/text/text.c | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/splash-plugins/text/text.c b/src/splash-plugins/text/text.c index 5198e93..bfa591a 100644 --- a/src/splash-plugins/text/text.c +++ b/src/splash-plugins/text/text.c @@ -52,7 +52,8 @@ #include <linux/kd.h> -#define CLEAR_LINE_SEQUENCE "\033[2K" +#define CLEAR_LINE_SEQUENCE "\033[2K\r\n" +#define BACKSPACE "\b\033[0K" struct _ply_boot_splash_plugin { @@ -62,7 +63,6 @@ struct _ply_boot_splash_plugin ply_boot_splash_password_answer_handler_t password_answer_handler; void *password_answer_data; - ply_buffer_t *keyboard_input_buffer; uint32_t keyboard_input_is_hidden : 1; }; @@ -74,7 +74,6 @@ create_plugin (void) ply_trace ("creating plugin"); plugin = calloc (1, sizeof (ply_boot_splash_plugin_t)); - plugin->keyboard_input_buffer = ply_buffer_new (); plugin->console_fd = -1; return plugin; @@ -88,8 +87,6 @@ destroy_plugin (ply_boot_splash_plugin_t *plugin) if (plugin == NULL) return; - ply_buffer_free (plugin->keyboard_input_buffer); - free (plugin); } @@ -180,29 +177,32 @@ on_keyboard_input (ply_boot_splash_plugin_t *plugin, const char *keyboard_input, size_t character_size) { - if (plugin->password_answer_handler != NULL) - { - if (character_size == 1 && keyboard_input[0] == '\r') - { - plugin->password_answer_handler (plugin->password_answer_data, - ply_buffer_get_bytes (plugin->keyboard_input_buffer)); - plugin->keyboard_input_is_hidden = false; - ply_buffer_clear (plugin->keyboard_input_buffer); - plugin->password_answer_handler = NULL; - write (STDOUT_FILENO, CLEAR_LINE_SEQUENCE, strlen (CLEAR_LINE_SEQUENCE)); - return; - } - } - - ply_buffer_append_bytes (plugin->keyboard_input_buffer, - keyboard_input, character_size); - if (plugin->keyboard_input_is_hidden) write (STDOUT_FILENO, "•", strlen ("•")); else write (STDOUT_FILENO, keyboard_input, character_size); } +void +on_backspace (ply_boot_splash_plugin_t *plugin) +{ + write (STDOUT_FILENO, BACKSPACE, strlen (BACKSPACE)); +} + +void +on_enter (ply_boot_splash_plugin_t *plugin, + const char *line) +{ + if (plugin->password_answer_handler != NULL) + { + plugin->password_answer_handler (plugin->password_answer_data, + line); + plugin->keyboard_input_is_hidden = false; + plugin->password_answer_handler = NULL; + write (STDOUT_FILENO, CLEAR_LINE_SEQUENCE, strlen (CLEAR_LINE_SEQUENCE)); + } +} + ply_boot_splash_plugin_interface_t * ply_boot_splash_plugin_get_interface (void) { @@ -214,7 +214,9 @@ ply_boot_splash_plugin_get_interface (void) .update_status = update_status, .hide_splash_screen = hide_splash_screen, .ask_for_password = ask_for_password, - .on_keyboard_input = on_keyboard_input + .on_keyboard_input = on_keyboard_input, + .on_backspace = on_backspace, + .on_enter = on_enter }; return &plugin_interface; |
