From b260a61c8f0d3eb4c7abcf89fce7754052a53947 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 31 Jul 2021 12:36:04 +0530 Subject: [PATCH] Get rid of bits from LineAttrs --- kitty/data-types.h | 2 +- kitty/history.c | 24 ++++++++++++------------ kitty/line-buf.c | 38 +++++++++++++++++++------------------- kitty/line.c | 4 ++-- kitty/rewrap.h | 6 +++--- kitty/screen.c | 40 ++++++++++++++++++++-------------------- 6 files changed, 57 insertions(+), 57 deletions(-) diff --git a/kitty/data-types.h b/kitty/data-types.h index e4ff1e5a9..dac2378ee 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -166,7 +166,7 @@ typedef union LineAttrs { uint8_t has_dirty_text : 1; uint8_t is_prompt_start : 1; uint8_t is_output_start : 1; - } bits; + }; uint8_t val; } LineAttrs ; diff --git a/kitty/history.c b/kitty/history.c index 843877e91..590c436d8 100644 --- a/kitty/history.c +++ b/kitty/history.c @@ -162,12 +162,12 @@ historybuf_cpu_cells(HistoryBuf *self, index_type lnum) { void historybuf_mark_line_clean(HistoryBuf *self, index_type y) { - attrptr(self, index_of(self, y))->bits.has_dirty_text = false; + attrptr(self, index_of(self, y))->has_dirty_text = false; } void historybuf_mark_line_dirty(HistoryBuf *self, index_type y) { - attrptr(self, index_of(self, y))->bits.has_dirty_text = true; + attrptr(self, index_of(self, y))->has_dirty_text = true; } void @@ -225,7 +225,7 @@ pagerhist_push(HistoryBuf *self, ANSIBuf *as_ansi_buf) { Line l = {.xnum=self->xnum}; init_line(self, self->start_of_data, &l); line_as_ansi(&l, as_ansi_buf, &prev_cell); - if (ringbuf_bytes_used(ph->ringbuf) && !l.attrs.bits.continued) pagerhist_write_bytes(ph, (const uint8_t*)"\n", 1); + if (ringbuf_bytes_used(ph->ringbuf) && !l.attrs.continued) pagerhist_write_bytes(ph, (const uint8_t*)"\n", 1); pagerhist_write_bytes(ph, (const uint8_t*)"\x1b[m", 3); if (pagerhist_write_ucs4(ph, as_ansi_buf->buf, as_ansi_buf->len)) pagerhist_write_bytes(ph, (const uint8_t*)"\r", 1); } @@ -304,10 +304,10 @@ as_ansi(HistoryBuf *self, PyObject *callback) { for(unsigned int i = 0; i < self->count; i++) { init_line(self, i, &l); if (i < self->count - 1) { - l.attrs.bits.continued = attrptr(self, index_of(self, i + 1))->bits.continued; - } else l.attrs.bits.continued = false; + l.attrs.continued = attrptr(self, index_of(self, i + 1))->continued; + } else l.attrs.continued = false; line_as_ansi(&l, &output, &prev_cell); - if (!l.attrs.bits.continued) { + if (!l.attrs.continued) { ensure_space_for(&output, buf, Py_UCS4, output.len + 1, capacity, 2048, false); output.buf[output.len++] = 10; // 10 = \n } @@ -409,12 +409,12 @@ pagerhist_as_bytes(HistoryBuf *self, PyObject *args UNUSED) { Line l = {.xnum=self->xnum}; get_line(self, 0, &l); size_t sz = ringbuf_bytes_used(ph->ringbuf); - if (!l.attrs.bits.continued) sz += 1; + if (!l.attrs.continued) sz += 1; PyObject *ans = PyBytes_FromStringAndSize(NULL, sz); if (!ans) return NULL; uint8_t *buf = (uint8_t*)PyBytes_AS_STRING(ans); ringbuf_memcpy_from(buf, ph->ringbuf, sz); - if (!l.attrs.bits.continued) buf[sz-1] = '\n'; + if (!l.attrs.continued) buf[sz-1] = '\n'; return ans; #undef ph } @@ -458,7 +458,7 @@ dirty_lines(HistoryBuf *self, PyObject *a UNUSED) { #define dirty_lines_doc "dirty_lines() -> Line numbers of all lines that have dirty text." PyObject *ans = PyList_New(0); for (index_type i = 0; i < self->count; i++) { - if (attrptr(self, i)->bits.has_dirty_text) { + if (attrptr(self, i)->has_dirty_text) { PyList_Append(ans, PyLong_FromUnsignedLong(i)); } } @@ -525,9 +525,9 @@ HistoryBuf *alloc_historybuf(unsigned int lines, unsigned int columns, unsigned #define init_src_line(src_y) init_line(src, map_src_index(src_y), src->line); -#define is_src_line_continued(src_y) (map_src_index(src_y) < src->ynum - 1 ? (attrptr(src, map_src_index(src_y + 1))->bits.continued) : false) +#define is_src_line_continued(src_y) (map_src_index(src_y) < src->ynum - 1 ? (attrptr(src, map_src_index(src_y + 1))->continued) : false) -#define next_dest_line(cont) { LineAttrs *lap = attrptr(dest, historybuf_push(dest, as_ansi_buf)); *lap = src->line->attrs; if (cont) lap->bits.continued = true; dest->line->attrs.bits.continued = cont; } +#define next_dest_line(cont) { LineAttrs *lap = attrptr(dest, historybuf_push(dest, as_ansi_buf)); *lap = src->line->attrs; if (cont) lap->continued = true; dest->line->attrs.continued = cont; } #define first_dest_line next_dest_line(false); @@ -551,7 +551,7 @@ historybuf_rewrap(HistoryBuf *self, HistoryBuf *other, ANSIBuf *as_ansi_buf) { other->count = 0; other->start_of_data = 0; if (self->count > 0) { rewrap_inner(self, other, self->count, NULL, NULL, as_ansi_buf); - for (index_type i = 0; i < other->count; i++) attrptr(other, (other->start_of_data + i) % other->ynum)->bits.has_dirty_text = true; + for (index_type i = 0; i < other->count; i++) attrptr(other, (other->start_of_data + i) % other->ynum)->has_dirty_text = true; } } diff --git a/kitty/line-buf.c b/kitty/line-buf.c index 7e02b1511..8e30086d8 100644 --- a/kitty/line-buf.c +++ b/kitty/line-buf.c @@ -37,36 +37,36 @@ linebuf_clear(LineBuf *self, char_type ch) { for (index_type i = 0; i < self->ynum; i++) { clear_chars_to(self, i, ch); self->line_attrs[i].val = 0; - self->line_attrs[i].bits.has_dirty_text = true; + self->line_attrs[i].has_dirty_text = true; } } } void linebuf_mark_line_dirty(LineBuf *self, index_type y) { - self->line_attrs[y].bits.has_dirty_text = true; + self->line_attrs[y].has_dirty_text = true; } void linebuf_mark_line_clean(LineBuf *self, index_type y) { - self->line_attrs[y].bits.has_dirty_text = false; + self->line_attrs[y].has_dirty_text = false; } void linebuf_mark_line_as_not_continued(LineBuf *self, index_type y) { - self->line_attrs[y].bits.continued = false; + self->line_attrs[y].continued = false; } void linebuf_mark_line_as_prompt_start(LineBuf *self, index_type y) { - self->line_attrs[y].bits.is_prompt_start = true; - self->line_attrs[y].bits.is_output_start = false; + self->line_attrs[y].is_prompt_start = true; + self->line_attrs[y].is_output_start = false; } void linebuf_mark_line_as_output_start(LineBuf *self, index_type y) { - self->line_attrs[y].bits.is_prompt_start = false; - self->line_attrs[y].bits.is_output_start = true; + self->line_attrs[y].is_prompt_start = false; + self->line_attrs[y].is_output_start = true; } @@ -174,7 +174,7 @@ set_attribute(LineBuf *self, PyObject *args) { if (!set_named_attribute_on_line(gpu_lineptr(self, y), which, val, self->xnum)) { PyErr_SetString(PyExc_KeyError, "Unknown cell attribute"); return NULL; } - self->line_attrs[y].bits.has_dirty_text = true; + self->line_attrs[y].has_dirty_text = true; } Py_RETURN_NONE; } @@ -186,7 +186,7 @@ set_continued(LineBuf *self, PyObject *args) { int val; if (!PyArg_ParseTuple(args, "Ip", &y, &val)) return NULL; if (y >= self->ynum) { PyErr_SetString(PyExc_ValueError, "Out of bounds."); return NULL; } - self->line_attrs[y].bits.continued = val; + self->line_attrs[y].continued = val; Py_RETURN_NONE; } @@ -195,7 +195,7 @@ dirty_lines(LineBuf *self, PyObject *a UNUSED) { #define dirty_lines_doc "dirty_lines() -> Line numbers of all lines that have dirty text." PyObject *ans = PyList_New(0); for (index_type i = 0; i < self->ynum; i++) { - if (self->line_attrs[i].bits.has_dirty_text) { + if (self->line_attrs[i].has_dirty_text) { PyList_Append(ans, PyLong_FromUnsignedLong(i)); } } @@ -259,7 +259,7 @@ clear_line_(Line *l, index_type xnum) { zero_at_ptr_count(l->cpu_cells, xnum); zero_at_ptr_count(l->gpu_cells, xnum); if (BLANK_CHAR != 0) clear_chars_in_line(l->cpu_cells, l->gpu_cells, xnum, BLANK_CHAR); - l->attrs.bits.has_dirty_text = false; + l->attrs.has_dirty_text = false; } void @@ -329,7 +329,7 @@ is_continued(LineBuf *self, PyObject *val) { #define is_continued_doc "is_continued(y) -> Whether the line y is continued or not" unsigned long y = PyLong_AsUnsignedLong(val); if (y >= self->ynum) { PyErr_SetString(PyExc_ValueError, "Out of bounds."); return NULL; } - if (self->line_attrs[y].bits.continued) { Py_RETURN_TRUE; } + if (self->line_attrs[y].continued) { Py_RETURN_TRUE; } Py_RETURN_FALSE; } @@ -347,7 +347,7 @@ linebuf_insert_lines(LineBuf *self, unsigned int num, unsigned int y, unsigned i self->line_map[i] = self->line_map[i - num]; self->line_attrs[i] = self->line_attrs[i - num]; } - if (y + num < self->ynum) self->line_attrs[y + num].bits.continued = false; + if (y + num < self->ynum) self->line_attrs[y + num].continued = false; for (i = 0; i < num; i++) { self->line_map[y + i] = self->scratch[ylimit - num + i]; } @@ -382,7 +382,7 @@ linebuf_delete_lines(LineBuf *self, index_type num, index_type y, index_type bot self->line_map[i] = self->line_map[i + num]; self->line_attrs[i] = self->line_attrs[i + num]; } - self->line_attrs[y].bits.continued = false; + self->line_attrs[y].continued = false; for (i = 0; i < num; i++) { self->line_map[ylimit - num + i] = self->scratch[y + i]; } @@ -408,7 +408,7 @@ linebuf_copy_line_to(LineBuf *self, Line *line, index_type where) { init_line(self, self->line, self->line_map[where]); copy_line(line, self->line); self->line_attrs[where] = line->attrs; - self->line_attrs[where].bits.has_dirty_text = true; + self->line_attrs[where].has_dirty_text = true; } static PyObject* @@ -427,10 +427,10 @@ as_ansi(LineBuf *self, PyObject *callback) { } while(ylimit > 0); for(index_type i = 0; i <= ylimit; i++) { - l.attrs.bits.continued = self->line_attrs[(i + 1 < self->ynum) ? i+1 : i].bits.continued; + l.attrs.continued = self->line_attrs[(i + 1 < self->ynum) ? i+1 : i].continued; init_line(self, (&l), self->line_map[i]); line_as_ansi(&l, &output, &prev_cell); - if (!l.attrs.bits.continued) { + if (!l.attrs.continued) { ensure_space_for(&output, buf, Py_UCS4, output.len + 1, capacity, 2048, false); output.buf[output.len++] = 10; // 10 = \n } @@ -587,7 +587,7 @@ linebuf_rewrap(LineBuf *self, LineBuf *other, index_type *num_content_lines_befo *track_x = tcarr[0].x; *track_y = tcarr[0].y; *track_x2 = tcarr[1].x; *track_y2 = tcarr[1].y; *num_content_lines_after = other->line->ynum + 1; - for (i = 0; i < *num_content_lines_after; i++) other->line_attrs[i].bits.has_dirty_text = true; + for (i = 0; i < *num_content_lines_after; i++) other->line_attrs[i].has_dirty_text = true; *num_content_lines_before = first + 1; } diff --git a/kitty/line.c b/kitty/line.c index 724d1d506..950562963 100644 --- a/kitty/line.c +++ b/kitty/line.c @@ -374,7 +374,7 @@ as_ansi(Line* self, PyObject *a UNUSED) { static PyObject* is_continued(Line* self, PyObject *a UNUSED) { #define is_continued_doc "Return the line's continued flag" - PyObject *ans = self->attrs.bits.continued ? Py_True : Py_False; + PyObject *ans = self->attrs.continued ? Py_True : Py_False; Py_INCREF(ans); return ans; } @@ -802,7 +802,7 @@ as_text_generic(PyObject *args, void *container, get_line_func get_line, index_t ansibuf->active_hyperlink_id = 0; for (index_type y = 0; y < lines; y++) { Line *line = get_line(container, y); - if (!line->attrs.bits.continued && y > 0) { + if (!line->attrs.continued && y > 0) { ret = PyObject_CallFunctionObjArgs(callback, nl, NULL); if (ret == NULL) goto end; Py_CLEAR(ret); diff --git a/kitty/rewrap.h b/kitty/rewrap.h index 7f151b402..fd18528aa 100644 --- a/kitty/rewrap.h +++ b/kitty/rewrap.h @@ -19,7 +19,7 @@ #define init_dest_line(dest_y) init_line(dest, dest->line, dest->line_map[dest_y]); dest->line->attrs = dest->line_attrs[dest_y]; #endif -#define set_dest_line_attrs(dest_y, continued_) dest->line_attrs[dest_y] = src->line->attrs; if (continued_) dest->line_attrs[dest_y].bits.continued = true; +#define set_dest_line_attrs(dest_y, continued_) dest->line_attrs[dest_y] = src->line->attrs; if (continued_) dest->line_attrs[dest_y].continued = true; #ifndef first_dest_line #define first_dest_line init_dest_line(0); set_dest_line_attrs(0, false) @@ -31,7 +31,7 @@ linebuf_index(dest, 0, dest->ynum - 1); \ if (historybuf != NULL) { \ init_dest_line(dest->ynum - 1); \ - dest->line->attrs.bits.has_dirty_text = true; \ + dest->line->attrs.has_dirty_text = true; \ historybuf_add_line(historybuf, dest->line, as_ansi_buf); \ }\ linebuf_clear_line(dest, dest->ynum - 1, true); \ @@ -41,7 +41,7 @@ #endif #ifndef is_src_line_continued -#define is_src_line_continued(src_y) (src_y < src->ynum - 1 ? (src->line_attrs[src_y + 1].bits.continued) : false) +#define is_src_line_continued(src_y) (src_y < src->ynum - 1 ? (src->line_attrs[src_y + 1].continued) : false) #endif static inline void diff --git a/kitty/screen.c b/kitty/screen.c index d90068328..2ad09d894 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -284,8 +284,8 @@ prevent_current_prompt_from_rewrapping(Screen *self, index_type columns) { while (y >= 0) { linebuf_init_line(self->main_linebuf, y); Line *line = self->linebuf->line; - if (line->attrs.bits.is_output_start) return; - if (line->attrs.bits.is_prompt_start) break; + if (line->attrs.is_output_start) return; + if (line->attrs.is_prompt_start) break; y--; } if (y < 0) return; @@ -470,7 +470,7 @@ move_widened_char(Screen *self, CPUCell* cpu_cell, GPUCell *gpu_cell, index_type if (self->modes.mDECAWM) { // overflow goes onto next line screen_carriage_return(self); screen_linefeed(self); - self->linebuf->line_attrs[self->cursor->y].bits.continued = true; + self->linebuf->line_attrs[self->cursor->y].continued = true; linebuf_init_line(self->linebuf, self->cursor->y); dest_cpu = self->linebuf->line->cpu_cells; dest_gpu = self->linebuf->line->gpu_cells; @@ -644,7 +644,7 @@ screen_draw(Screen *self, uint32_t och, bool from_input_stream) { if (self->modes.mDECAWM) { screen_carriage_return(self); screen_linefeed(self); - self->linebuf->line_attrs[self->cursor->y].bits.continued = true; + self->linebuf->line_attrs[self->cursor->y].continued = true; } else { self->cursor->x = self->columns - char_width; } @@ -1352,8 +1352,8 @@ screen_cursor_at_a_shell_prompt(const Screen *self) { if (self->cursor->y >= self->lines || self->linebuf != self->main_linebuf) return false; for (index_type y=self->cursor->y + 1; y-- > 0; ) { linebuf_init_line(self->linebuf, y); - if (self->linebuf->line->attrs.bits.is_output_start) return -1; - if (self->linebuf->line->attrs.bits.is_prompt_start) return y; + if (self->linebuf->line->attrs.is_output_start) return -1; + if (self->linebuf->line->attrs.is_prompt_start) return y; } return -1; } @@ -1810,16 +1810,16 @@ screen_history_scroll_to_prompt(Screen *self, int num_of_prompts_to_jump) { num_of_prompts_to_jump = num_of_prompts_to_jump < 0 ? -num_of_prompts_to_jump : num_of_prompts_to_jump; int y = -self->scrolled_by; #define ensure_y_ok if (y >= (int)self->lines || -y > (int)self->historybuf->count) return false; -#define move_y_to_start_of_promt while (-y + 1 <= (int)self->historybuf->count && range_line_(self, y - 1)->attrs.bits.is_prompt_start) y--; -#define move_y_to_end_of_promt while (y + 1 < (int)self->lines && range_line_(self, y + 1)->attrs.bits.is_prompt_start) y++; +#define move_y_to_start_of_promt while (-y + 1 <= (int)self->historybuf->count && range_line_(self, y - 1)->attrs.is_prompt_start) y--; +#define move_y_to_end_of_promt while (y + 1 < (int)self->lines && range_line_(self, y + 1)->attrs.is_prompt_start) y++; ensure_y_ok; - if (range_line_(self, y)->attrs.bits.is_prompt_start) { + if (range_line_(self, y)->attrs.is_prompt_start) { if (delta < 0) { move_y_to_start_of_promt; } else { move_y_to_end_of_promt; } } while (num_of_prompts_to_jump) { y += delta; ensure_y_ok; - if (range_line_(self, y)->attrs.bits.is_prompt_start) { + if (range_line_(self, y)->attrs.is_prompt_start) { num_of_prompts_to_jump--; if (delta < 0) { move_y_to_start_of_promt; } else { move_y_to_end_of_promt; } } @@ -1948,7 +1948,7 @@ screen_update_cell_data(Screen *self, void *address, FONTS_DATA_HANDLE fonts_dat for (index_type y = 0; y < MIN(self->lines, self->scrolled_by); y++) { lnum = self->scrolled_by - 1 - y; historybuf_init_line(self->historybuf, lnum, self->historybuf->line); - if (self->historybuf->line->attrs.bits.has_dirty_text) { + if (self->historybuf->line->attrs.has_dirty_text) { render_line(fonts_data, self->historybuf->line, lnum, self->cursor, self->disable_ligatures); if (screen_has_marker(self)) mark_text_in_line(self->marker, self->historybuf->line); historybuf_mark_line_clean(self->historybuf, lnum); @@ -1958,10 +1958,10 @@ screen_update_cell_data(Screen *self, void *address, FONTS_DATA_HANDLE fonts_dat for (index_type y = self->scrolled_by; y < self->lines; y++) { lnum = y - self->scrolled_by; linebuf_init_line(self->linebuf, lnum); - if (self->linebuf->line->attrs.bits.has_dirty_text || + if (self->linebuf->line->attrs.has_dirty_text || (cursor_has_moved && (self->cursor->y == lnum || self->last_rendered.cursor_y == lnum))) { render_line(fonts_data, self->linebuf->line, lnum, self->cursor, self->disable_ligatures); - if (self->linebuf->line->attrs.bits.has_dirty_text && screen_has_marker(self)) mark_text_in_line(self->marker, self->linebuf->line); + if (self->linebuf->line->attrs.has_dirty_text && screen_has_marker(self)) mark_text_in_line(self->marker, self->linebuf->line); linebuf_mark_line_clean(self->linebuf, lnum); } @@ -2178,7 +2178,7 @@ text_for_range(Screen *self, const Selection *sel, bool insert_newlines) { for (int i = 0, y = idata.y; y < limit; y++, i++) { Line *line = range_line_(self, y); XRange xr = xrange_for_iteration(&idata, y, line); - char leading_char = (i > 0 && insert_newlines && !line->attrs.bits.continued) ? '\n' : 0; + char leading_char = (i > 0 && insert_newlines && !line->attrs.continued) ? '\n' : 0; PyObject *text = unicode_in_range(line, xr.x, xr.x_limit, true, leading_char, false); if (text == NULL) { Py_DECREF(ans); return PyErr_NoMemory(); } PyTuple_SET_ITEM(ans, i, text); @@ -2447,8 +2447,8 @@ last_cmd_output(Screen *self, PyObject *args) { const int limit = -self->historybuf->count; while (y >= limit) { Line *line = range_line_(self, y); - if (line->attrs.bits.is_prompt_start) prompt_pos = y; - if (line->attrs.bits.is_output_start) { + if (line->attrs.is_prompt_start) prompt_pos = y; + if (line->attrs.is_output_start) { oo.start = y; num_lines = prompt_pos - y; break; @@ -2790,7 +2790,7 @@ screen_selection_range_for_word(Screen *self, const index_type x, const index_ty start = x; end = x; while(true) { while(start > 0 && is_ok(start - 1)) start--; - if (start > 0 || !line->attrs.bits.continued || *y1 == 0) break; + if (start > 0 || !line->attrs.continued || *y1 == 0) break; line = visual_line_(self, *y1 - 1); if (!is_ok(self->columns - 1)) break; (*y1)--; start = self->columns - 1; @@ -2800,7 +2800,7 @@ screen_selection_range_for_word(Screen *self, const index_type x, const index_ty while(end < self->columns - 1 && is_ok(end + 1)) end++; if (end < self->columns - 1 || *y2 >= self->lines - 1) break; line = visual_line_(self, *y2 + 1); - if (!line->attrs.bits.continued || !is_ok(0)) break; + if (!line->attrs.continued || !is_ok(0)) break; (*y2)++; end = 0; } *s = start; *e = end; @@ -2968,7 +2968,7 @@ screen_mark_hyperlink(Screen *self, index_type x, index_type y) { static index_type continue_line_upwards(Screen *self, index_type top_line, SelectionBoundary *start, SelectionBoundary *end) { - while (top_line > 0 && visual_line_(self, top_line)->attrs.bits.continued) { + while (top_line > 0 && visual_line_(self, top_line)->attrs.continued) { if (!screen_selection_range_for_line(self, top_line - 1, &start->x, &end->x)) break; top_line--; } @@ -2977,7 +2977,7 @@ continue_line_upwards(Screen *self, index_type top_line, SelectionBoundary *star static index_type continue_line_downwards(Screen *self, index_type bottom_line, SelectionBoundary *start, SelectionBoundary *end) { - while (bottom_line < self->lines - 1 && visual_line_(self, bottom_line + 1)->attrs.bits.continued) { + while (bottom_line < self->lines - 1 && visual_line_(self, bottom_line + 1)->attrs.continued) { if (!screen_selection_range_for_line(self, bottom_line + 1, &start->x, &end->x)) break; bottom_line++; }