From efc7c11775323fd9b75f94c20896b6d7b1929ad1 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Tue, 18 Sep 2012 15:31:35 -0400 Subject: [PATCH] text-progress-bar: Try to be more defensive about text leaks We try to prevent text from showing through in the text splash, by disable dmesg to screen and by redirecting console messages to a log file. Still, occasionally a kernel message may leak through. This commit tries to harden against that by moving the cursor up to home when we aren't using it. --- src/libply-splash-core/ply-text-display.c | 43 +++++++++++++++++++ src/libply-splash-core/ply-text-display.h | 6 +++ .../ply-text-progress-bar.c | 11 +++++ 3 files changed, 60 insertions(+) diff --git a/src/libply-splash-core/ply-text-display.c b/src/libply-splash-core/ply-text-display.c index 7cabd98f..fcaff22e 100644 --- a/src/libply-splash-core/ply-text-display.c +++ b/src/libply-splash-core/ply-text-display.c @@ -58,6 +58,10 @@ #define MOVE_CURSOR_SEQUENCE "\033[%d;%df" #endif +#ifndef SET_TOP_AND_BOTTOM_MARGINS_SEQUENCE +#define SET_TOP_AND_BOTTOM_MARGINS_SEQUENCE "\033[%d;%dr" +#endif + #ifndef HIDE_CURSOR_SEQUENCE #define HIDE_CURSOR_SEQUENCE "\033[?25l" #endif @@ -70,6 +74,14 @@ #define COLOR_SEQUENCE_FORMAT "\033[%dm" #endif +#ifndef ENABLE_WRAPPING_SEQUENCE +#define ENABLE_WRAPPING_SEQUENCE "\033[?7h" +#endif + +#ifndef DISABLE_WRAPPING_SEQUENCE +#define DISABLE_WRAPPING_SEQUENCE "\033[?7l" +#endif + #ifndef PAUSE_SEQUENCE #define PAUSE_SEQUENCE "\023" #endif @@ -147,6 +159,37 @@ ply_text_display_set_cursor_position (ply_text_display_t *display, row, column); } +void +ply_text_display_set_scrollable_area (ply_text_display_t *display, + int top_row, + int bottom_row) +{ + int number_of_rows; + + number_of_rows = ply_text_display_get_number_of_rows (display); + + top_row = CLAMP (top_row, 0, bottom_row); + bottom_row = CLAMP (bottom_row, top_row, number_of_rows - 1); + + ply_terminal_write (display->terminal, + SET_TOP_AND_BOTTOM_MARGINS_SEQUENCE, + top_row, bottom_row); +} + +void +ply_text_display_enable_wrapping (ply_text_display_t *display) +{ + ply_terminal_write (display->terminal, + ENABLE_WRAPPING_SEQUENCE); +} + +void +ply_text_display_disable_wrapping (ply_text_display_t *display) +{ + ply_terminal_write (display->terminal, + DISABLE_WRAPPING_SEQUENCE); +} + void ply_text_display_clear_screen (ply_text_display_t *display) { diff --git a/src/libply-splash-core/ply-text-display.h b/src/libply-splash-core/ply-text-display.h index 3fd7dab2..7f1e20b7 100644 --- a/src/libply-splash-core/ply-text-display.h +++ b/src/libply-splash-core/ply-text-display.h @@ -54,6 +54,12 @@ int ply_text_display_get_number_of_columns (ply_text_display_t *display); void ply_text_display_set_cursor_position (ply_text_display_t *display, int column, int row); +void ply_text_display_set_scrollable_area (ply_text_display_t *display, + int top_row, + int bottom_row); +void ply_text_display_enable_wrapping (ply_text_display_t *display); +void ply_text_display_disable_wrapping (ply_text_display_t *display); + __attribute__((__format__ (__printf__, 2, 3))) void ply_text_display_write (ply_text_display_t *display, const char *format, diff --git a/src/libply-splash-core/ply-text-progress-bar.c b/src/libply-splash-core/ply-text-progress-bar.c index bf4b3781..852f016b 100644 --- a/src/libply-splash-core/ply-text-progress-bar.c +++ b/src/libply-splash-core/ply-text-progress-bar.c @@ -184,6 +184,8 @@ ply_text_progress_bar_draw (ply_text_progress_bar_t *progress_bar) width = progress_bar->number_of_columns - 2 - strlen (os_string); + ply_text_display_disable_wrapping (progress_bar->display); + ply_text_display_set_scrollable_area (progress_bar->display, 0, progress_bar->row); ply_text_display_set_cursor_position (progress_bar->display, progress_bar->column, progress_bar->row); @@ -210,6 +212,7 @@ ply_text_progress_bar_draw (ply_text_progress_bar_t *progress_bar) ply_text_display_write (progress_bar->display, "%c", ' '); } + ply_text_display_set_cursor_position (progress_bar->display, 0, 0); ply_text_display_set_background_color (progress_bar->display, PLY_TERMINAL_COLOR_BLACK); @@ -230,10 +233,18 @@ ply_text_progress_bar_draw (ply_text_progress_bar_t *progress_bar) progress_bar->row); ply_text_display_write (progress_bar->display, "%s", os_string); + ply_text_display_set_cursor_position (progress_bar->display, 0, 0); ply_text_display_set_foreground_color (progress_bar->display, PLY_TERMINAL_COLOR_DEFAULT); } + + ply_text_display_set_background_color (progress_bar->display, + PLY_TERMINAL_COLOR_DEFAULT); + + ply_text_display_set_scrollable_area (progress_bar->display, 0, progress_bar->row - 1); + ply_text_display_set_cursor_position (progress_bar->display, 0, 0); + ply_text_display_enable_wrapping (progress_bar->display); } void -- 2.47.2