console: add function to set max scrollback buffer size
authorDavid Herrmann <dh.herrmann@googlemail.com>
Thu, 2 Feb 2012 15:43:15 +0000 (16:43 +0100)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Thu, 2 Feb 2012 15:43:15 +0000 (16:43 +0100)
The maximum scrollback-buffer size can now be changed on the fly. We
also reduce the current buffer size to the new size so we do not need to
clear the console to flush the scrollback buffer.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
src/console.h
src/console_cell.c

index 3b9f746..8db27bc 100644 (file)
@@ -57,6 +57,7 @@ void kmscon_buffer_unref(struct kmscon_buffer *buf);
 int kmscon_buffer_resize(struct kmscon_buffer *buf, unsigned int x,
                                                        unsigned int y);
 void kmscon_buffer_draw(struct kmscon_buffer *buf, struct kmscon_font *font);
+void kmscon_buffer_set_max_sb(struct kmscon_buffer *buf, unsigned int max);
 
 unsigned int kmscon_buffer_get_width(struct kmscon_buffer *buf);
 unsigned int kmscon_buffer_get_height(struct kmscon_buffer *buf);
index 2f635d6..1a67482 100644 (file)
@@ -331,6 +331,39 @@ static struct line *get_from_scrollback(struct kmscon_buffer *buf)
        return line;
 }
 
+/* set maximum scrollback buffer size */
+void kmscon_buffer_set_max_sb(struct kmscon_buffer *buf, unsigned int max)
+{
+       struct line *line;
+
+       if (!buf)
+               return;
+
+       while (buf->sb_count > max) {
+               line = buf->sb_first;
+               if (!line)
+                       break;
+
+               buf->sb_first = line->next;
+               if (line->next)
+                       line->next->prev = NULL;
+               else
+                       buf->sb_last = NULL;
+               buf->sb_count--;
+
+               if (buf->position == line) {
+                       if (buf->sb_first)
+                               buf->position = buf->sb_first;
+                       else
+                               buf->position = NULL;
+               }
+
+               free_line(line);
+       }
+
+       buf->sb_max = max;
+}
+
 /*
  * Resize the current console buffer
  * This resizes the current buffer. We do not resize the lines or modify them in