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 <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-08-14 17:02:56 +02:00
parent 681c9acb4c
commit 4f57e7b3d2
2 changed files with 65 additions and 0 deletions

View File

@ -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)
{

View File

@ -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);