diff --git a/kitty/history.c b/kitty/history.c index 1facaa556..e20749278 100644 --- a/kitty/history.c +++ b/kitty/history.c @@ -252,6 +252,19 @@ historybuf_add_line(HistoryBuf *self, const Line *line, ANSIBuf *as_ansi_buf) { *attrptr(self, idx) = (line->continued & CONTINUED_MASK) | (line->has_dirty_text ? TEXT_DIRTY_MASK : 0); } +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; + init_line(self, idx, line); + + self->count--; + + return true; +} + static PyObject* line(HistoryBuf *self, PyObject *val) { #define line_doc "Return the line with line number val. This buffer grows upwards, i.e. 0 is the most recently added line" diff --git a/kitty/lineops.h b/kitty/lineops.h index 5f350d283..c1ba8c24c 100644 --- a/kitty/lineops.h +++ b/kitty/lineops.h @@ -101,6 +101,7 @@ void linebuf_mark_line_as_not_continued(LineBuf *self, index_type y); unsigned int linebuf_char_width_at(LineBuf *self, index_type x, index_type y); void linebuf_refresh_sprite_positions(LineBuf *self); void historybuf_add_line(HistoryBuf *self, const Line *line, ANSIBuf*); +bool historybuf_pop_line(HistoryBuf *, Line *); void historybuf_rewrap(HistoryBuf *self, HistoryBuf *other, ANSIBuf*); void historybuf_init_line(HistoryBuf *self, index_type num, Line *l); CPUCell* historybuf_cpu_cells(HistoryBuf *self, index_type num);