Move details plugin to support n windows

calculate-0.9.5
Ray Strode 16 years ago
parent dfc91615ef
commit 66d23c49ce

@ -59,6 +59,14 @@
#define CLEAR_SCREEN_SEQUENCE "\033[2J"
#endif
#ifndef CLEAR_LINE_SEQUENCE
#define CLEAR_LINE_SEQUENCE "\033[2K\r\n"
#endif
#ifndef BACKSPACE
#define BACKSPACE "\b\033[0K"
#endif
#ifndef MOVE_CURSOR_SEQUENCE
#define MOVE_CURSOR_SEQUENCE "\033[%d;%df"
#endif
@ -572,6 +580,12 @@ ply_window_set_mode (ply_window_t *window,
return true;
}
int
ply_window_get_tty_fd (ply_window_t *window)
{
return window->tty_fd;
}
int
ply_window_get_number_of_text_rows (ply_window_t *window)
{
@ -608,6 +622,18 @@ ply_window_clear_screen (ply_window_t *window)
ply_window_set_text_cursor_position (window, 0, 0);
}
void
ply_window_clear_text_line (ply_window_t *window)
{
write (window->tty_fd, CLEAR_LINE_SEQUENCE, strlen (CLEAR_LINE_SEQUENCE));
}
void
ply_window_clear_text_character (ply_window_t *window)
{
write (window->tty_fd, BACKSPACE, strlen (BACKSPACE));
}
void
ply_window_set_background_color (ply_window_t *window,
ply_window_color_t color)

@ -100,6 +100,7 @@ bool ply_window_is_open (ply_window_t *window);
void ply_window_close (ply_window_t *window);
bool ply_window_set_mode (ply_window_t *window,
ply_window_mode_t mode);
int ply_window_get_tty_fd (ply_window_t *window);
int ply_window_get_number_of_text_rows (ply_window_t *window);
int ply_window_get_number_of_text_columns (ply_window_t *window);
void ply_window_set_text_cursor_position (ply_window_t *window,
@ -108,6 +109,8 @@ void ply_window_set_text_cursor_position (ply_window_t *window,
void ply_window_hide_text_cursor (ply_window_t *window);
void ply_window_show_text_cursor (ply_window_t *window);
void ply_window_clear_screen (ply_window_t *window);
void ply_window_clear_text_line (ply_window_t *window);
void ply_window_clear_text_character (ply_window_t *window);
bool ply_window_supports_text_color (ply_window_t *window);
void ply_window_set_background_color (ply_window_t *window,
ply_window_color_t color);

@ -70,7 +70,7 @@ static ply_boot_splash_t *start_boot_splash (state_t *state,
const char *module_path);
static ply_window_t *create_window (state_t *state,
const char *tty_name);
const char *tty_name);
static void
on_session_output (state_t *state,
@ -435,13 +435,15 @@ on_escape_pressed (state_t *state)
static ply_window_t *
create_window (state_t *state,
const char *tty_name)
const char *tty_name)
{
ply_window_t *window;
ply_trace ("creating window on %s", tty_name != NULL? tty_name : "active vt");
window = ply_window_new (tty_name);
ply_window_attach_to_event_loop (window, state->loop);
return window;
}
@ -617,7 +619,7 @@ check_for_consoles (state_t *state)
}
if (ply_list_get_length (state->windows) == 0)
ply_list_append_data (state->windows, ply_window_new ("tty1"));
ply_list_append_data (state->windows, create_window (state, "tty1"));
}
static bool

@ -53,12 +53,10 @@
#include <linux/kd.h>
#define CLEAR_LINE_SEQUENCE "\033[2K\r\n"
#define BACKSPACE "\b\033[0K"
void ask_for_password (ply_boot_splash_plugin_t *plugin,
const char *prompt,
ply_trigger_t *answer);
typedef void (* ply_boot_splash_plugin_window_handler_t) (ply_window_t *window, ply_boot_splash_plugin_t *, void *user_data, void *other_user_data);
ply_boot_splash_plugin_interface_t *ply_boot_splash_plugin_get_interface (void);
struct _ply_boot_splash_plugin
@ -66,7 +64,7 @@ struct _ply_boot_splash_plugin
ply_event_loop_t *loop;
ply_trigger_t *pending_password_answer;
ply_window_t *window;
ply_list_t *windows;
uint32_t keyboard_input_is_hidden : 1;
};
@ -79,6 +77,7 @@ create_plugin (void)
ply_trace ("creating plugin");
plugin = calloc (1, sizeof (ply_boot_splash_plugin_t));
plugin->windows = ply_list_new ();
return plugin;
}
@ -91,6 +90,8 @@ destroy_plugin (ply_boot_splash_plugin_t *plugin)
if (plugin == NULL)
return;
ply_list_free (plugin->windows);
free (plugin);
}
@ -102,21 +103,75 @@ detach_from_event_loop (ply_boot_splash_plugin_t *plugin)
ply_trace ("detaching from event loop");
}
static void
write_text_on_window (ply_window_t *window,
ply_boot_splash_plugin_t *plugin,
const char *text,
void *user_data);
static void
for_each_window (ply_boot_splash_plugin_t *plugin,
ply_boot_splash_plugin_window_handler_t handler,
void *user_data,
void *other_user_data)
{
ply_list_node_t *node;
node = ply_list_get_first_node (plugin->windows);
while (node != NULL)
{
ply_list_node_t *next_node;
ply_window_t *window;
next_node = ply_list_get_next_node (plugin->windows, node);
window = ply_list_node_get_data (node);
handler (window, plugin, user_data, other_user_data);
node = next_node;
}
}
static void
write_text_on_window (ply_window_t *window,
ply_boot_splash_plugin_t *plugin,
const char *text,
void *user_data)
{
int fd;
size_t size;
size = (size_t) user_data;
fd = ply_window_get_tty_fd (window);
write (fd, text, size);
}
void
on_keyboard_input (ply_boot_splash_plugin_t *plugin,
const char *keyboard_input,
size_t character_size)
{
if (plugin->keyboard_input_is_hidden)
write (STDOUT_FILENO, "", strlen (""));
for_each_window (plugin,
(ply_boot_splash_plugin_window_handler_t)
write_text_on_window, (void *) "*",
(void *) strlen ("*"));
else
write (STDOUT_FILENO, keyboard_input, character_size);
for_each_window (plugin,
(ply_boot_splash_plugin_window_handler_t)
write_text_on_window, (void *) keyboard_input,
(void *) character_size);
}
void
on_backspace (ply_boot_splash_plugin_t *plugin)
{
write (STDOUT_FILENO, BACKSPACE, strlen (BACKSPACE));
for_each_window (plugin,
(ply_boot_splash_plugin_window_handler_t)
ply_window_clear_text_character, NULL, NULL);
}
void
@ -128,7 +183,10 @@ on_enter (ply_boot_splash_plugin_t *plugin,
ply_trigger_pull (plugin->pending_password_answer, line);
plugin->keyboard_input_is_hidden = false;
plugin->pending_password_answer = NULL;
write (STDOUT_FILENO, CLEAR_LINE_SEQUENCE, strlen (CLEAR_LINE_SEQUENCE));
for_each_window (plugin,
(ply_boot_splash_plugin_window_handler_t)
ply_window_clear_text_line, NULL, NULL);
}
}
@ -136,14 +194,46 @@ void
add_window (ply_boot_splash_plugin_t *plugin,
ply_window_t *window)
{
plugin->window = window;
ply_list_append_data (plugin->windows, window);
}
void
remove_window (ply_boot_splash_plugin_t *plugin,
ply_window_t *window)
{
plugin->window = NULL;
ply_list_remove_data (plugin->windows, window);
}
static void
initialize_window (ply_window_t *window,
ply_boot_splash_plugin_t *plugin)
{
ply_boot_splash_plugin_interface_t *interface;
ply_window_set_mode (window, PLY_WINDOW_MODE_TEXT);
ply_window_set_keyboard_input_handler (window,
(ply_window_keyboard_input_handler_t)
on_keyboard_input, plugin);
ply_window_set_backspace_handler (window,
(ply_window_backspace_handler_t)
on_backspace, plugin);
ply_window_set_enter_handler (window,
(ply_window_enter_handler_t)
on_enter, plugin);
interface = ply_boot_splash_plugin_get_interface ();
interface->ask_for_password = ask_for_password;
}
static void
uninitialize_window (ply_window_t *window,
ply_boot_splash_plugin_t *plugin)
{
ply_window_set_keyboard_input_handler (window, NULL, NULL);
ply_window_set_backspace_handler (window, NULL, NULL);
ply_window_set_enter_handler (window, NULL, NULL);
}
bool
@ -155,27 +245,9 @@ show_splash_screen (ply_boot_splash_plugin_t *plugin,
assert (plugin != NULL);
if (plugin->window != NULL)
{
ply_boot_splash_plugin_interface_t *interface;
ply_window_set_mode (plugin->window, PLY_WINDOW_MODE_TEXT);
ply_window_set_keyboard_input_handler (plugin->window,
(ply_window_keyboard_input_handler_t)
on_keyboard_input, plugin);
ply_window_set_backspace_handler (plugin->window,
(ply_window_backspace_handler_t)
on_backspace, plugin);
ply_window_set_enter_handler (plugin->window,
(ply_window_enter_handler_t)
on_enter, plugin);
interface = ply_boot_splash_plugin_get_interface ();
interface->ask_for_password = ask_for_password;
}
for_each_window (plugin,
(ply_boot_splash_plugin_window_handler_t)
initialize_window, NULL, NULL);
plugin->loop = loop;
ply_event_loop_watch_for_exit (loop, (ply_event_loop_exit_handler_t)
@ -206,8 +278,13 @@ on_boot_output (ply_boot_splash_plugin_t *plugin,
const char *output,
size_t size)
{
ply_trace ("writing '%s' to all windows (%d bytes)",
output, size);
if (size > 0)
write (STDOUT_FILENO, output, size);
for_each_window (plugin,
(ply_boot_splash_plugin_window_handler_t)
write_text_on_window,
(void *) output, (void *) size);
}
void
@ -218,6 +295,10 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin,
ply_trace ("hiding splash screen");
for_each_window (plugin,
(ply_boot_splash_plugin_window_handler_t)
uninitialize_window, NULL, NULL);
if (plugin->pending_password_answer != NULL)
{
ply_trigger_pull (plugin->pending_password_answer, "");
@ -225,11 +306,6 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin,
plugin->keyboard_input_is_hidden = false;
}
ply_window_set_keyboard_input_handler (plugin->window, NULL, NULL);
ply_window_set_backspace_handler (plugin->window, NULL, NULL);
ply_window_set_enter_handler (plugin->window, NULL, NULL);
ply_window_clear_screen (plugin->window);
ply_event_loop_stop_watching_for_exit (plugin->loop,
(ply_event_loop_exit_handler_t)
detach_from_event_loop,
@ -237,26 +313,39 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin,
detach_from_event_loop (plugin);
}
void
ask_for_password (ply_boot_splash_plugin_t *plugin,
const char *prompt,
ply_trigger_t *answer)
static void
ask_for_password_on_window (ply_window_t *window,
ply_boot_splash_plugin_t *plugin,
const char *prompt)
{
plugin->pending_password_answer = answer;
int fd;
ply_window_set_mode (window, PLY_WINDOW_MODE_TEXT);
if (plugin->window != NULL)
ply_window_set_mode (plugin->window, PLY_WINDOW_MODE_TEXT);
fd = ply_window_get_tty_fd (window);
if (prompt != NULL)
{
write (STDOUT_FILENO, "\r\n", strlen ("\r\n"));
write (STDOUT_FILENO, prompt, strlen (prompt));
write (fd, "\r\n", strlen ("\r\n"));
write (fd, prompt, strlen (prompt));
}
write (STDOUT_FILENO, "\r\nPassword: ", strlen ("\r\nPassword: "));
write (fd, "\r\nPassword: ", strlen ("\r\nPassword: "));
plugin->keyboard_input_is_hidden = true;
}
void
ask_for_password (ply_boot_splash_plugin_t *plugin,
const char *prompt,
ply_trigger_t *answer)
{
plugin->pending_password_answer = answer;
for_each_window (plugin,
(ply_boot_splash_plugin_window_handler_t)
ask_for_password_on_window, (void *) prompt, NULL);
}
ply_boot_splash_plugin_interface_t *
ply_boot_splash_plugin_get_interface (void)
{

Loading…
Cancel
Save