DRYer
This commit is contained in:
parent
d4dd226d8f
commit
4a9a021b2c
@ -147,10 +147,7 @@ init_line(HistoryBuf *self, index_type num, Line *l) {
|
|||||||
// Initialize the line l, setting its pointer to the offsets for the line at index (buffer position) num
|
// Initialize the line l, setting its pointer to the offsets for the line at index (buffer position) num
|
||||||
l->cpu_cells = cpu_lineptr(self, num);
|
l->cpu_cells = cpu_lineptr(self, num);
|
||||||
l->gpu_cells = gpu_lineptr(self, num);
|
l->gpu_cells = gpu_lineptr(self, num);
|
||||||
l->continued = *attrptr(self, num) & CONTINUED_MASK;
|
copy_line_attrs_to_line(*attrptr(self, num), l);
|
||||||
l->has_dirty_text = *attrptr(self, num) & TEXT_DIRTY_MASK ? true : false;
|
|
||||||
l->is_output_start = *attrptr(self, num) & OUTPUT_START_MASK ? true : false;
|
|
||||||
l->is_prompt_start = *attrptr(self, num) & PROMPT_START_MASK ? true : false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -250,7 +247,7 @@ void
|
|||||||
historybuf_add_line(HistoryBuf *self, const Line *line, ANSIBuf *as_ansi_buf) {
|
historybuf_add_line(HistoryBuf *self, const Line *line, ANSIBuf *as_ansi_buf) {
|
||||||
index_type idx = historybuf_push(self, as_ansi_buf);
|
index_type idx = historybuf_push(self, as_ansi_buf);
|
||||||
copy_line(line, self->line);
|
copy_line(line, self->line);
|
||||||
*attrptr(self, idx) = (line->continued & CONTINUED_MASK) | (line->has_dirty_text ? TEXT_DIRTY_MASK : 0) | (line->is_output_start ? OUTPUT_START_MASK : 0) | (line->is_output_start ? PROMPT_START_MASK : 0);
|
*attrptr(self, idx) = line_attrs_from_line(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@ -532,7 +529,7 @@ HistoryBuf *alloc_historybuf(unsigned int lines, unsigned int columns, unsigned
|
|||||||
|
|
||||||
#define is_src_line_continued(src_y) (map_src_index(src_y) < src->ynum - 1 ? (*attrptr(src, map_src_index(src_y + 1)) & CONTINUED_MASK) : 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_MASK) : false)
|
||||||
|
|
||||||
#define next_dest_line(cont) *attrptr(dest, historybuf_push(dest, as_ansi_buf)) = (cont ? CONTINUED_MASK : 0) | (src->line->is_output_start ? OUTPUT_START_MASK : 0) | (src->line->is_prompt_start ? PROMPT_START_MASK : 0); dest->line->continued = cont;
|
#define next_dest_line(cont) *attrptr(dest, historybuf_push(dest, as_ansi_buf)) = (cont ? CONTINUED_MASK : 0) | line_attrs_from_line(src->line); dest->line->continued = cont;
|
||||||
|
|
||||||
#define first_dest_line next_dest_line(false);
|
#define first_dest_line next_dest_line(false);
|
||||||
|
|
||||||
|
|||||||
@ -141,10 +141,7 @@ void
|
|||||||
linebuf_init_line(LineBuf *self, index_type idx) {
|
linebuf_init_line(LineBuf *self, index_type idx) {
|
||||||
self->line->ynum = idx;
|
self->line->ynum = idx;
|
||||||
self->line->xnum = self->xnum;
|
self->line->xnum = self->xnum;
|
||||||
self->line->continued = self->line_attrs[idx] & CONTINUED_MASK ? true : false;
|
copy_line_attrs_to_line(self->line_attrs[idx], self->line);
|
||||||
self->line->has_dirty_text = self->line_attrs[idx] & TEXT_DIRTY_MASK ? true : false;
|
|
||||||
self->line->is_prompt_start = self->line_attrs[idx] & PROMPT_START_MASK ? true : false;
|
|
||||||
self->line->is_output_start = self->line_attrs[idx] & OUTPUT_START_MASK ? true : false;
|
|
||||||
init_line(self, self->line, self->line_map[idx]);
|
init_line(self, self->line, self->line_map[idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,10 +229,7 @@ create_line_copy_inner(LineBuf* self, index_type y) {
|
|||||||
src.xnum = self->xnum; line->xnum = self->xnum;
|
src.xnum = self->xnum; line->xnum = self->xnum;
|
||||||
if (!allocate_line_storage(line, 0)) { Py_CLEAR(line); return PyErr_NoMemory(); }
|
if (!allocate_line_storage(line, 0)) { Py_CLEAR(line); return PyErr_NoMemory(); }
|
||||||
line->ynum = y;
|
line->ynum = y;
|
||||||
line->continued = self->line_attrs[y] & CONTINUED_MASK ? true : false;
|
copy_line_attrs_to_line(self->line_attrs[y], line);
|
||||||
line->has_dirty_text = self->line_attrs[y] & TEXT_DIRTY_MASK ? true : false;
|
|
||||||
line->is_output_start = self->line_attrs[y] & OUTPUT_START_MASK ? true : false;
|
|
||||||
line->is_prompt_start = self->line_attrs[y] & PROMPT_START_MASK ? true : false;
|
|
||||||
init_line(self, &src, self->line_map[y]);
|
init_line(self, &src, self->line_map[y]);
|
||||||
copy_line(&src, line);
|
copy_line(&src, line);
|
||||||
return (PyObject*)line;
|
return (PyObject*)line;
|
||||||
@ -257,10 +251,7 @@ copy_line_to(LineBuf *self, PyObject *args) {
|
|||||||
if (!PyArg_ParseTuple(args, "IO!", &y, &Line_Type, &dest)) return NULL;
|
if (!PyArg_ParseTuple(args, "IO!", &y, &Line_Type, &dest)) return NULL;
|
||||||
src.xnum = self->xnum; dest->xnum = self->xnum;
|
src.xnum = self->xnum; dest->xnum = self->xnum;
|
||||||
dest->ynum = y;
|
dest->ynum = y;
|
||||||
dest->continued = self->line_attrs[y] & CONTINUED_MASK;
|
copy_line_attrs_to_line(self->line_attrs[y], dest);
|
||||||
dest->has_dirty_text = self->line_attrs[y] & TEXT_DIRTY_MASK;
|
|
||||||
dest->is_output_start = self->line_attrs[y] & OUTPUT_START_MASK;
|
|
||||||
dest->is_prompt_start = self->line_attrs[y] & PROMPT_START_MASK;
|
|
||||||
init_line(self, &src, self->line_map[y]);
|
init_line(self, &src, self->line_map[y]);
|
||||||
copy_line(&src, dest);
|
copy_line(&src, dest);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
@ -419,7 +410,7 @@ void
|
|||||||
linebuf_copy_line_to(LineBuf *self, Line *line, index_type where) {
|
linebuf_copy_line_to(LineBuf *self, Line *line, index_type where) {
|
||||||
init_line(self, self->line, self->line_map[where]);
|
init_line(self, self->line, self->line_map[where]);
|
||||||
copy_line(line, self->line);
|
copy_line(line, self->line);
|
||||||
self->line_attrs[where] = TEXT_DIRTY_MASK | (line->continued ? CONTINUED_MASK : 0) | (line->is_output_start ? OUTPUT_START_MASK : 0) | (line->is_prompt_start ? PROMPT_START_MASK : 0);
|
self->line_attrs[where] = TEXT_DIRTY_MASK | line_attrs_from_line(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
|
|||||||
@ -67,6 +67,22 @@ left_shift_line(Line *line, index_type at, index_type num) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
copy_line_attrs_to_line(const line_attrs_type attrs, Line *line) {
|
||||||
|
#define S(a, m) line->a = (attrs & m) ? true: false
|
||||||
|
S(continued, CONTINUED_MASK); S(has_dirty_text, TEXT_DIRTY_MASK);
|
||||||
|
S(is_prompt_start, PROMPT_START_MASK); S(is_output_start, OUTPUT_START_MASK);
|
||||||
|
#undef S
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline line_attrs_type
|
||||||
|
line_attrs_from_line(const Line *line) {
|
||||||
|
#define S(a, m) (line->a ? m : 0)
|
||||||
|
return S(continued, CONTINUED_MASK) | S(has_dirty_text, TEXT_DIRTY_MASK) | S(is_prompt_start, PROMPT_START_MASK) | S(is_output_start, OUTPUT_START_MASK);
|
||||||
|
#undef S
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef Line*(get_line_func)(void *, int);
|
typedef Line*(get_line_func)(void *, int);
|
||||||
void line_clear_text(Line *self, unsigned int at, unsigned int num, char_type ch);
|
void line_clear_text(Line *self, unsigned int at, unsigned int num, char_type ch);
|
||||||
void line_apply_cursor(Line *self, Cursor *cursor, unsigned int at, unsigned int num, bool clear_char);
|
void line_apply_cursor(Line *self, Cursor *cursor, unsigned int at, unsigned int num, bool clear_char);
|
||||||
|
|||||||
@ -16,10 +16,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef init_dest_line
|
#ifndef init_dest_line
|
||||||
#define init_dest_line(dest_y) init_line(dest, dest->line, dest->line_map[dest_y]); dest->line->continued = dest->line_attrs[dest_y] & CONTINUED_MASK ? true : false; dest->line->is_output_start = dest->line_attrs[dest_y] & OUTPUT_START_MASK ? true : false; dest->line->is_prompt_start = dest->line_attrs[dest_y] & PROMPT_START_MASK ? true : false;
|
#define init_dest_line(dest_y) init_line(dest, dest->line, dest->line_map[dest_y]); copy_line_attrs_to_line(dest->line_attrs[dest_y], dest->line);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define set_dest_line_attrs(dest_y, continued) dest->line_attrs[dest_y] = (continued ? CONTINUED_MASK : 0) | (src->line->is_output_start ? OUTPUT_START_MASK : 0) | (src->line->is_prompt_start ? PROMPT_START_MASK : 0);
|
#define set_dest_line_attrs(dest_y, continued) dest->line_attrs[dest_y] = (continued ? CONTINUED_MASK : 0) | line_attrs_from_line(src->line);
|
||||||
|
|
||||||
#ifndef first_dest_line
|
#ifndef first_dest_line
|
||||||
#define first_dest_line init_dest_line(0); set_dest_line_attrs(0, false)
|
#define first_dest_line init_dest_line(0); set_dest_line_attrs(0, false)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user