console: implement proper scrolling

Add two new functions to rotate the scroll-area of the buffer. We push
lines to the scroll-back buffer if they are pushed out to the top. Lines
pushed out to the bottom are simply freed.
We never take back lines from the scrollback buffer as applications
expect the new lines to be empty.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-02-03 23:47:09 +01:00
parent ff408d6fb9
commit 0c7e50433a
2 changed files with 41 additions and 0 deletions

View File

@ -71,6 +71,8 @@ void kmscon_buffer_write(struct kmscon_buffer *buf, unsigned int x,
kmscon_symbol_t kmscon_buffer_read(struct kmscon_buffer *buf, unsigned int x,
unsigned int y);
void kmscon_buffer_newline(struct kmscon_buffer *buf);
void kmscon_buffer_scroll_down(struct kmscon_buffer *buf, unsigned int num);
void kmscon_buffer_scroll_up(struct kmscon_buffer *buf, unsigned int num);
/* console objects */

View File

@ -864,3 +864,42 @@ void kmscon_buffer_newline(struct kmscon_buffer *buf)
buf->scroll_buf[buf->scroll_fill] = nl;
buf->scroll_fill++;
}
void kmscon_buffer_scroll_down(struct kmscon_buffer *buf, unsigned int num)
{
unsigned int i;
if (!buf || !num)
return;
if (num > buf->scroll_y)
num = buf->scroll_y;
for (i = 0; i < num; ++i)
free_line(buf->scroll_buf[buf->scroll_y - i - 1]);
memmove(&buf->scroll_buf[num], buf->scroll_buf,
(buf->scroll_y - num) * sizeof(struct line*));
memset(buf->scroll_buf, 0, num * sizeof(struct line*));
buf->scroll_fill = buf->scroll_y;
}
void kmscon_buffer_scroll_up(struct kmscon_buffer *buf, unsigned int num)
{
unsigned int i;
if (!buf || !num)
return;
if (num > buf->scroll_y)
num = buf->scroll_y;
for (i = 0; i < num; ++i)
link_to_scrollback(buf, buf->scroll_buf[i]);
memmove(buf->scroll_buf, &buf->scroll_buf[num],
(buf->scroll_y - num) * sizeof(struct line*));
memset(&buf->scroll_buf[buf->scroll_y - num], 0,
num * sizeof(struct line*));
buf->scroll_fill = buf->scroll_y;
}