DRYer
This commit is contained in:
parent
37f0cf86d0
commit
4fd8c7cfaa
@ -38,6 +38,7 @@ typedef unsigned int index_type;
|
|||||||
|
|
||||||
#define DATA_CELL_SIZE 6
|
#define DATA_CELL_SIZE 6
|
||||||
|
|
||||||
|
#define BLANK_CHAR 32
|
||||||
#define CHAR_MASK 0xFFFFFF
|
#define CHAR_MASK 0xFFFFFF
|
||||||
#define ATTRS_SHIFT 24
|
#define ATTRS_SHIFT 24
|
||||||
#define ATTRS_MASK_WITHOUT_WIDTH 0xFC000000
|
#define ATTRS_MASK_WITHOUT_WIDTH 0xFC000000
|
||||||
@ -312,7 +313,7 @@ PyTypeObject ChildMonitor_Type;
|
|||||||
for(index_type __i__ = (at); __i__ < (line)->xnum - (num); __i__++) { \
|
for(index_type __i__ = (at); __i__ < (line)->xnum - (num); __i__++) { \
|
||||||
COPY_CELL(line, __i__ + (num), line, __i__) \
|
COPY_CELL(line, __i__ + (num), line, __i__) \
|
||||||
} \
|
} \
|
||||||
if ((((line)->cells[(at)].ch >> ATTRS_SHIFT) & WIDTH_MASK) != 1) (line)->cells[(at)].ch = (1 << ATTRS_SHIFT) | 32;
|
if ((((line)->cells[(at)].ch >> ATTRS_SHIFT) & WIDTH_MASK) != 1) (line)->cells[(at)].ch = (1 << ATTRS_SHIFT) | BLANK_CHAR;
|
||||||
|
|
||||||
|
|
||||||
// Global functions
|
// Global functions
|
||||||
|
|||||||
@ -43,7 +43,7 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) {
|
|||||||
self->line->xnum = xnum;
|
self->line->xnum = xnum;
|
||||||
for(index_type y = 0; y < self->ynum; y++) {
|
for(index_type y = 0; y < self->ynum; y++) {
|
||||||
self->line->chars = start_of(self, y) + 1;
|
self->line->chars = start_of(self, y) + 1;
|
||||||
for (index_type i = 0; i < self->xnum; i++) self->line->chars[i] = (1 << ATTRS_SHIFT) | 32;
|
for (index_type i = 0; i < self->xnum; i++) self->line->chars[i] = (1 << ATTRS_SHIFT) | BLANK_CHAR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,7 @@ void linebuf_clear(LineBuf *self, char_type ch) {
|
|||||||
static PyObject*
|
static PyObject*
|
||||||
clear(LineBuf *self) {
|
clear(LineBuf *self) {
|
||||||
#define clear_doc "Clear all lines in this LineBuf"
|
#define clear_doc "Clear all lines in this LineBuf"
|
||||||
linebuf_clear(self, ' ');
|
linebuf_clear(self, BLANK_CHAR);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) {
|
|||||||
self->line->xnum = xnum;
|
self->line->xnum = xnum;
|
||||||
for(index_type i = 0; i < ynum; i++) {
|
for(index_type i = 0; i < ynum; i++) {
|
||||||
self->line_map[i] = i;
|
self->line_map[i] = i;
|
||||||
clear_chars_to(self, i, ' ');
|
clear_chars_to(self, i, BLANK_CHAR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ allocate_line_storage(Line *line, bool initialize) {
|
|||||||
if (initialize) {
|
if (initialize) {
|
||||||
line->cells = PyMem_Calloc(line->xnum, sizeof(Cell));
|
line->cells = PyMem_Calloc(line->xnum, sizeof(Cell));
|
||||||
if (line->cells == NULL) { PyErr_NoMemory(); return false; }
|
if (line->cells == NULL) { PyErr_NoMemory(); return false; }
|
||||||
clear_chars_in_line(line->cells, line->xnum, ' ');
|
clear_chars_in_line(line->cells, line->xnum, BLANK_CHAR);
|
||||||
} else {
|
} else {
|
||||||
line->cells = PyMem_Malloc(line->xnum * sizeof(Cell));
|
line->cells = PyMem_Malloc(line->xnum * sizeof(Cell));
|
||||||
if (line->cells == NULL) { PyErr_NoMemory(); return false; }
|
if (line->cells == NULL) { PyErr_NoMemory(); return false; }
|
||||||
@ -453,7 +453,7 @@ linebuf_rewrap(LineBuf *self, LineBuf *other, int *cursor_y_out, HistoryBuf *his
|
|||||||
for (first = self->ynum - 1; true; first--) {
|
for (first = self->ynum - 1; true; first--) {
|
||||||
Cell *cells = lineptr(self, first);
|
Cell *cells = lineptr(self, first);
|
||||||
for(i = 0; i < self->xnum; i++) {
|
for(i = 0; i < self->xnum; i++) {
|
||||||
if ((cells[i].ch & CHAR_MASK) != 32) { is_empty = false; break; }
|
if ((cells[i].ch & CHAR_MASK) != BLANK_CHAR) { is_empty = false; break; }
|
||||||
}
|
}
|
||||||
if (!is_empty || !first) break;
|
if (!is_empty || !first) break;
|
||||||
}
|
}
|
||||||
|
|||||||
10
kitty/line.c
10
kitty/line.c
@ -26,7 +26,7 @@ unsigned int
|
|||||||
line_length(Line *self) {
|
line_length(Line *self) {
|
||||||
index_type last = self->xnum - 1;
|
index_type last = self->xnum - 1;
|
||||||
for (index_type i = 0; i < self->xnum; i++) {
|
for (index_type i = 0; i < self->xnum; i++) {
|
||||||
if ((self->cells[last - i].ch & CHAR_MASK) != ' ') return self->xnum - i;
|
if ((self->cells[last - i].ch & CHAR_MASK) != BLANK_CHAR) return self->xnum - i;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ line_as_ansi(Line *self, Py_UCS4 *buf, index_type buflen) {
|
|||||||
int r;
|
int r;
|
||||||
if (!self->continued) { // Trim trailing spaces
|
if (!self->continued) { // Trim trailing spaces
|
||||||
for(r = self->xnum - 1; r >= 0; r--) {
|
for(r = self->xnum - 1; r >= 0; r--) {
|
||||||
if ((self->cells[r].ch & CHAR_MASK) != 32) break;
|
if ((self->cells[r].ch & CHAR_MASK) != BLANK_CHAR) break;
|
||||||
}
|
}
|
||||||
limit = r + 1;
|
limit = r + 1;
|
||||||
}
|
}
|
||||||
@ -312,7 +312,7 @@ static PyObject*
|
|||||||
clear_text(Line* self, PyObject *args) {
|
clear_text(Line* self, PyObject *args) {
|
||||||
#define clear_text_doc "clear_text(at, num, ch=' ') -> Clear characters in the specified range, preserving formatting."
|
#define clear_text_doc "clear_text(at, num, ch=' ') -> Clear characters in the specified range, preserving formatting."
|
||||||
unsigned int at, num;
|
unsigned int at, num;
|
||||||
int ch = 32;
|
int ch = BLANK_CHAR;
|
||||||
if (!PyArg_ParseTuple(args, "II|C", &at, &num, &ch)) return NULL;
|
if (!PyArg_ParseTuple(args, "II|C", &at, &num, &ch)) return NULL;
|
||||||
line_clear_text(self, at, num, ch);
|
line_clear_text(self, at, num, ch);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
@ -327,7 +327,7 @@ line_apply_cursor(Line *self, Cursor *cursor, unsigned int at, unsigned int num,
|
|||||||
|
|
||||||
for (index_type i = at; i < self->xnum && i < at + num; i++) {
|
for (index_type i = at; i < self->xnum && i < at + num; i++) {
|
||||||
if (clear_char) {
|
if (clear_char) {
|
||||||
self->cells[i].ch = 32 | attrs;
|
self->cells[i].ch = BLANK_CHAR | attrs;
|
||||||
self->cells[i].cc = 0;
|
self->cells[i].cc = 0;
|
||||||
} else {
|
} else {
|
||||||
char_type w = ((self->cells[i].ch >> ATTRS_SHIFT) & WIDTH_MASK) << ATTRS_SHIFT;
|
char_type w = ((self->cells[i].ch >> ATTRS_SHIFT) & WIDTH_MASK) << ATTRS_SHIFT;
|
||||||
@ -355,7 +355,7 @@ void line_right_shift(Line *self, unsigned int at, unsigned int num) {
|
|||||||
}
|
}
|
||||||
// Check if a wide character was split at the right edge
|
// Check if a wide character was split at the right edge
|
||||||
char_type w = (self->cells[self->xnum - 1].ch >> ATTRS_SHIFT) & WIDTH_MASK;
|
char_type w = (self->cells[self->xnum - 1].ch >> ATTRS_SHIFT) & WIDTH_MASK;
|
||||||
if (w != 1) self->cells[self->xnum - 1].ch = (1 << ATTRS_SHIFT) | 32;
|
if (w != 1) self->cells[self->xnum - 1].ch = (1 << ATTRS_SHIFT) | BLANK_CHAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
|
|||||||
@ -60,7 +60,7 @@ rewrap_inner(BufType *src, BufType *dest, const index_type src_limit, HistoryBuf
|
|||||||
src_x_limit = src->xnum;
|
src_x_limit = src->xnum;
|
||||||
if (!src_line_is_continued) {
|
if (!src_line_is_continued) {
|
||||||
// Trim trailing white-space since there is a hard line break at the end of this line
|
// Trim trailing white-space since there is a hard line break at the end of this line
|
||||||
while(src_x_limit && (src->line->cells[src_x_limit - 1].ch & CHAR_MASK) == 32) src_x_limit--;
|
while(src_x_limit && (src->line->cells[src_x_limit - 1].ch & CHAR_MASK) == BLANK_CHAR) src_x_limit--;
|
||||||
|
|
||||||
}
|
}
|
||||||
while (src_x < src_x_limit) {
|
while (src_x < src_x_limit) {
|
||||||
|
|||||||
@ -70,7 +70,7 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) {
|
|||||||
void
|
void
|
||||||
screen_reset(Screen *self) {
|
screen_reset(Screen *self) {
|
||||||
if (self->linebuf == self->alt_linebuf) screen_toggle_screen_buffer(self);
|
if (self->linebuf == self->alt_linebuf) screen_toggle_screen_buffer(self);
|
||||||
linebuf_clear(self->linebuf, ' ');
|
linebuf_clear(self->linebuf, BLANK_CHAR);
|
||||||
self->modes = empty_modes;
|
self->modes = empty_modes;
|
||||||
self->default_fg = 0; self->default_bg = 0;
|
self->default_fg = 0; self->default_bg = 0;
|
||||||
self->highlight_fg = 0; self->highlight_bg = 0;
|
self->highlight_fg = 0; self->highlight_bg = 0;
|
||||||
@ -369,7 +369,7 @@ void
|
|||||||
screen_toggle_screen_buffer(Screen *self) {
|
screen_toggle_screen_buffer(Screen *self) {
|
||||||
bool to_alt = self->linebuf == self->main_linebuf;
|
bool to_alt = self->linebuf == self->main_linebuf;
|
||||||
if (to_alt) {
|
if (to_alt) {
|
||||||
linebuf_clear(self->alt_linebuf, ' ');
|
linebuf_clear(self->alt_linebuf, BLANK_CHAR);
|
||||||
screen_save_cursor(self);
|
screen_save_cursor(self);
|
||||||
self->linebuf = self->alt_linebuf;
|
self->linebuf = self->alt_linebuf;
|
||||||
self->tabstops = self->alt_tabstops;
|
self->tabstops = self->alt_tabstops;
|
||||||
@ -777,7 +777,7 @@ void screen_erase_in_line(Screen *self, unsigned int how, bool private) {
|
|||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
linebuf_init_line(self->linebuf, self->cursor->y);
|
linebuf_init_line(self->linebuf, self->cursor->y);
|
||||||
if (private) {
|
if (private) {
|
||||||
line_clear_text(self->linebuf->line, s, n, ' ');
|
line_clear_text(self->linebuf->line, s, n, BLANK_CHAR);
|
||||||
} else {
|
} else {
|
||||||
line_apply_cursor(self->linebuf->line, self->cursor, s, n, true);
|
line_apply_cursor(self->linebuf->line, self->cursor, s, n, true);
|
||||||
}
|
}
|
||||||
@ -813,7 +813,7 @@ void screen_erase_in_display(Screen *self, unsigned int how, bool private) {
|
|||||||
for (unsigned int i=a; i < b; i++) {
|
for (unsigned int i=a; i < b; i++) {
|
||||||
linebuf_init_line(self->linebuf, i);
|
linebuf_init_line(self->linebuf, i);
|
||||||
if (private) {
|
if (private) {
|
||||||
line_clear_text(self->linebuf->line, 0, self->columns, ' ');
|
line_clear_text(self->linebuf->line, 0, self->columns, BLANK_CHAR);
|
||||||
} else {
|
} else {
|
||||||
line_apply_cursor(self->linebuf->line, self->cursor, 0, self->columns, true);
|
line_apply_cursor(self->linebuf->line, self->cursor, 0, self->columns, true);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user