From 4f57e7b3d22f63e8e0e7ac8f8ce870f1943d687a Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Tue, 14 Aug 2012 17:02:56 +0200 Subject: [PATCH] console: provide scrollback-buffer helpers These helpers allow moving around in the scrollback-buffer. Scrolling bigger portions of the screen is quite slowly as we have to traverse a list. However, nothing compared to screen-rendering so we can ignore this. But O(n) is always bad... Signed-off-by: David Herrmann --- src/console.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/console.h | 6 ++++++ 2 files changed, 65 insertions(+) diff --git a/src/console.c b/src/console.c index a0fa2ef..9d7b0e7 100644 --- a/src/console.c +++ b/src/console.c @@ -627,6 +627,65 @@ void kmscon_console_clear_sb(struct kmscon_console *con) con->sb_pos = NULL; } +void kmscon_console_sb_up(struct kmscon_console *con, unsigned int num) +{ + if (!con || !num) + return; + + while (num--) { + if (con->sb_pos) { + if (!con->sb_pos->prev) + return; + + con->sb_pos = con->sb_pos->prev; + } else if (!con->sb_last) { + return; + } else { + con->sb_pos = con->sb_last; + } + } +} + +void kmscon_console_sb_down(struct kmscon_console *con, unsigned int num) +{ + if (!con || !num) + return; + + while (num--) { + if (con->sb_pos) { + con->sb_pos = con->sb_pos->next; + if (!con->sb_pos) + return; + } else { + return; + } + } +} + +void kmscon_console_sb_page_up(struct kmscon_console *con, unsigned int num) +{ + if (!con || !num) + return; + + kmscon_console_sb_up(con, num * con->size_y); +} + +void kmscon_console_sb_page_down(struct kmscon_console *con, unsigned int num) +{ + if (!con || !num) + return; + + kmscon_console_sb_down(con, num * con->size_y); +} + +void kmscon_console_sb_reset(struct kmscon_console *con) +{ + if (!con) + return; + + con->sb_pos = NULL; +} + void kmscon_console_set_def_attr(struct kmscon_console *con, const struct font_char_attr *attr) { diff --git a/src/console.h b/src/console.h index b7cd340..ec1bf72 100644 --- a/src/console.h +++ b/src/console.h @@ -63,6 +63,12 @@ int kmscon_console_set_margins(struct kmscon_console *con, void kmscon_console_set_max_sb(struct kmscon_console *con, unsigned int max); void kmscon_console_clear_sb(struct kmscon_console *con); +void kmscon_console_sb_up(struct kmscon_console *con, unsigned int num); +void kmscon_console_sb_down(struct kmscon_console *con, unsigned int num); +void kmscon_console_sb_page_up(struct kmscon_console *con, unsigned int num); +void kmscon_console_sb_page_down(struct kmscon_console *con, unsigned int num); +void kmscon_console_sb_reset(struct kmscon_console *con); + void kmscon_console_set_def_attr(struct kmscon_console *con, const struct font_char_attr *attr); void kmscon_console_reset(struct kmscon_console *con);