From 071986138b0d9ec31e3c37484526932b932b2bad Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 17 Mar 2021 13:43:26 +0530 Subject: [PATCH] Cleanup previous merge --- kitty/history.c | 8 ++------ kitty/line-buf.c | 8 ++++---- kitty/lineops.h | 2 +- kitty/screen.c | 28 +++++++++------------------- kitty_tests/__init__.py | 2 +- kitty_tests/screen.py | 2 +- 6 files changed, 18 insertions(+), 32 deletions(-) diff --git a/kitty/history.c b/kitty/history.c index e20749278..3a4ae5baf 100644 --- a/kitty/history.c +++ b/kitty/history.c @@ -254,14 +254,10 @@ historybuf_add_line(HistoryBuf *self, const Line *line, ANSIBuf *as_ansi_buf) { bool historybuf_pop_line(HistoryBuf *self, Line *line) { - if (self->count <= 0) - return false; - - index_type idx = (self->start_of_data + self->count-1) % self->ynum; + if (self->count <= 0) return false; + index_type idx = (self->start_of_data + self->count - 1) % self->ynum; init_line(self, idx, line); - self->count--; - return true; } diff --git a/kitty/line-buf.c b/kitty/line-buf.c index b0372436e..67ef730ac 100644 --- a/kitty/line-buf.c +++ b/kitty/line-buf.c @@ -327,11 +327,11 @@ is_continued(LineBuf *self, PyObject *val) { } unsigned int -linebuf_continued_lines_count(LineBuf *self, index_type stop_at_line) { - unsigned int count = 0; - for (unsigned int i = 0; i < self->ynum && i < stop_at_line; i++) +linebuf_continued_lines_count(const LineBuf *self, const index_type stop_before_line) { + index_type count = 0; + for (index_type i = 0; i < self->ynum && i < stop_before_line; i++) { if (self->line_attrs[i] & CONTINUED_MASK) count++; - + } return count; } diff --git a/kitty/lineops.h b/kitty/lineops.h index 63a0d2c34..7e81c2bf2 100644 --- a/kitty/lineops.h +++ b/kitty/lineops.h @@ -91,7 +91,7 @@ void linebuf_clear(LineBuf *, char_type ch); void linebuf_index(LineBuf* self, index_type top, index_type bottom); void linebuf_reverse_index(LineBuf *self, index_type top, index_type bottom); void linebuf_clear_line(LineBuf *self, index_type y); -unsigned int linebuf_continued_lines_count(LineBuf *, index_type); +unsigned int linebuf_continued_lines_count(const LineBuf *, const index_type); void linebuf_insert_lines(LineBuf *self, unsigned int num, unsigned int y, unsigned int bottom); void linebuf_delete_lines(LineBuf *self, index_type num, index_type y, index_type bottom); void linebuf_add_line_to_top(LineBuf *, Line *); diff --git a/kitty/screen.c b/kitty/screen.c index d0bef8841..b28d593d3 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -248,26 +248,16 @@ screen_resize(Screen *self, unsigned int lines, unsigned int columns) { if (OPT(scrollback_fill_enlarged_window)) { - int lines_to_fill = (lines - self->main_linebuf->ynum) \ - + (linebuf_continued_lines_count(self->main_linebuf, y) - linebuf_continued_lines_count(n, y)); - - while (lines_to_fill > 0) { - if (self->historybuf->count <= 0) break; - - unsigned int top = 0, bottom = lines-1; - - linebuf_reverse_index(n, top, bottom); - y++; - INDEX_GRAPHICS(1); - + int lines_to_fill = (lines - self->main_linebuf->ynum) + ( + linebuf_continued_lines_count(self->main_linebuf, self->cursor->y) - linebuf_continued_lines_count(n, y)); + const unsigned int top = 0, bottom = lines-1; Line last_history_line = {.xnum=self->historybuf->xnum}; - bool line_popped = historybuf_pop_line(self->historybuf, &last_history_line); - if (!line_popped) - break; - linebuf_add_line_to_top(n, &last_history_line); - - lines_to_fill--; - } + while (lines_to_fill-- > 0) { + if (!historybuf_pop_line(self->historybuf, &last_history_line)) break; + linebuf_reverse_index(n, top, bottom); + INDEX_GRAPHICS(1); + linebuf_add_line_to_top(n, &last_history_line); + } } Py_CLEAR(self->main_linebuf); self->main_linebuf = n; diff --git a/kitty_tests/__init__.py b/kitty_tests/__init__.py index 5626cf067..19568636a 100644 --- a/kitty_tests/__init__.py +++ b/kitty_tests/__init__.py @@ -91,7 +91,7 @@ class BaseTest(TestCase): options = Options(merge_configs(defaults._asdict(), final_options)) set_options(options) - def create_screen(self, cols=5, lines=5, scrollback=5, cell_width=10, cell_height=20, options=None, content=tuple()): + def create_screen(self, cols=5, lines=5, scrollback=5, cell_width=10, cell_height=20, options=None, content=()): self.set_options(options) c = Callbacks() s = Screen(c, lines, cols, scrollback, cell_width, cell_height, 0, c) diff --git a/kitty_tests/screen.py b/kitty_tests/screen.py index 684ccb29d..bdb493794 100644 --- a/kitty_tests/screen.py +++ b/kitty_tests/screen.py @@ -304,7 +304,7 @@ class TestScreen(BaseTest): self.ae(x_before, s.cursor.x) def test_scrollback_fill_after_resize(self): - def prepare_screen(content=tuple()): + def prepare_screen(content=()): return self.create_screen( lines=5, cols=5,