Skip to content

Commit

Permalink
Decouple some API in historybuf so that we can access more than just …
Browse files Browse the repository at this point in the history
…the next line eventually
  • Loading branch information
kovidgoyal committed Dec 28, 2024
1 parent c545ba3 commit 79c3add
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
10 changes: 6 additions & 4 deletions kitty/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,8 @@ pagerhist_push(HistoryBuf *self, ANSIBuf *as_ansi_buf) {
}

static index_type
historybuf_push(HistoryBuf *self, ANSIBuf *as_ansi_buf, Line *line) {
historybuf_push(HistoryBuf *self, ANSIBuf *as_ansi_buf) {
index_type idx = (self->start_of_data + self->count) % self->ynum;
init_line(self, idx, line);
if (self->count == self->ynum) {
pagerhist_push(self, as_ansi_buf);
self->start_of_data = (self->start_of_data + 1) % self->ynum;
Expand All @@ -291,7 +290,8 @@ historybuf_push(HistoryBuf *self, ANSIBuf *as_ansi_buf, Line *line) {

void
historybuf_add_line(HistoryBuf *self, const Line *line, ANSIBuf *as_ansi_buf) {
index_type idx = historybuf_push(self, as_ansi_buf, self->line);
index_type idx = historybuf_push(self, as_ansi_buf);
init_line(self, idx, self->line);
copy_line(line, self->line);
*attrptr(self, idx) = line->attrs;
}
Expand Down Expand Up @@ -611,7 +611,9 @@ HistoryBuf *alloc_historybuf(unsigned int lines, unsigned int columns, unsigned
index_type
historybuf_next_dest_line(HistoryBuf *self, ANSIBuf *as_ansi_buf, Line *src_line, index_type dest_y, Line *dest_line, bool continued) {
history_buf_set_last_char_as_continuation(self, dest_y, continued);
*attrptr(self, historybuf_push(self, as_ansi_buf, dest_line)) = src_line->attrs;
index_type idx = historybuf_push(self, as_ansi_buf);
*attrptr(self, idx) = src_line->attrs;
init_line(self, idx, dest_line);
return dest_y + 1;
}

Expand Down
24 changes: 13 additions & 11 deletions kitty/rewrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,17 @@ static void
init_line(TextCache *tc, index_type xnum, Line *l) {
l->text_cache = tc;
l->xnum = xnum;
}

static void
next_dest_line(Rewrap *r, bool continued) {
r->dest_y = r->next_dest_line(r->dest_buf, r->historybuf, r->as_ansi_buf, &r->src, r->dest_y, &r->dest, continued);
r->dest_x = 0;
}

static void
first_dest_line(Rewrap *r) {
r->dest_y = r->first_dest_line(r->dest_buf, r->as_ansi_buf, &r->src, &r->dest);
}

static index_type
Expand All @@ -110,13 +120,8 @@ rewrap_inner(Rewrap r) {
r.init_line(r.src_buf, r.src_y, &r.src);
r.src_x_limit = r.src.xnum;
if (!src_line_is_continued) {
r.dest_x = 0;
if (is_first_line) {
is_first_line = false;
r.dest_y = r.first_dest_line(r.dest_buf, r.as_ansi_buf, &r.src, &r.dest);
} else {
r.dest_y = r.next_dest_line(r.dest_buf, r.historybuf, r.as_ansi_buf, &r.src, r.dest_y, &r.dest, false);
}
if (is_first_line) { is_first_line = false; first_dest_line(&r); }
else next_dest_line(&r, false);
}
src_line_is_continued = r.src.cpu_cells[r.src.xnum-1].next_char_was_wrapped;
if (!src_line_is_continued) {
Expand All @@ -130,10 +135,7 @@ rewrap_inner(Rewrap r) {
if (t->is_tracked_line && t->x >= r.src_x_limit) t->x = MAX(1u, r.src_x_limit) - 1;
}
while (r.src_x < r.src_x_limit) {
if (r.dest_x >= r.dest.xnum) {
r.dest_x = 0;
r.dest_y = r.next_dest_line(r.dest_buf, r.historybuf, r.as_ansi_buf, &r.src, r.dest_y, &r.dest, true);
}
if (r.dest_x >= r.dest.xnum) next_dest_line(&r, true);
index_type num = MIN(r.src.xnum - r.src_x, r.dest.xnum - r.dest_x);
copy_range(&r.src, r.src_x, &r.dest, r.dest_x, num);
for (TrackCursor *t = r.cursors; !t->is_sentinel; t++) {
Expand Down

0 comments on commit 79c3add

Please sign in to comment.