Track cursor color as a property of Screen not Cursor
This means that the savepoint functionality will not restore cursor color
This commit is contained in:
parent
3b71a016a6
commit
b58ecde740
@ -309,7 +309,7 @@ class CharGrid:
|
|||||||
elif which is DynamicColor.default_bg:
|
elif which is DynamicColor.default_bg:
|
||||||
self.screen.default_bg = val
|
self.screen.default_bg = val
|
||||||
elif which is DynamicColor.cursor_color:
|
elif which is DynamicColor.cursor_color:
|
||||||
self.screen.cursor.color = val
|
self.screen.cursor_color = val
|
||||||
elif which is DynamicColor.highlight_fg:
|
elif which is DynamicColor.highlight_fg:
|
||||||
self.screen.highlight_fg = val
|
self.screen.highlight_fg = val
|
||||||
elif which is DynamicColor.highlight_bg:
|
elif which is DynamicColor.highlight_bg:
|
||||||
@ -511,7 +511,7 @@ class CharGrid:
|
|||||||
ul = cursor_program.uniform_location
|
ul = cursor_program.uniform_location
|
||||||
left = sg.xstart + cursor.x * sg.dx
|
left = sg.xstart + cursor.x * sg.dx
|
||||||
top = sg.ystart - cursor.y * sg.dy
|
top = sg.ystart - cursor.y * sg.dy
|
||||||
cc = self.screen.cursor.color
|
cc = self.screen.cursor_color
|
||||||
col = color_from_int(cc >> 8) if cc & 1 else self.opts.cursor
|
col = color_from_int(cc >> 8) if cc & 1 else self.opts.cursor
|
||||||
shape = cursor.shape or self.default_cursor.shape
|
shape = cursor.shape or self.default_cursor.shape
|
||||||
alpha = self.opts.cursor_opacity
|
alpha = self.opts.cursor_opacity
|
||||||
|
|||||||
@ -24,15 +24,15 @@ dealloc(Cursor* self) {
|
|||||||
|
|
||||||
#define EQ(x) (a->x == b->x)
|
#define EQ(x) (a->x == b->x)
|
||||||
static int __eq__(Cursor *a, Cursor *b) {
|
static int __eq__(Cursor *a, Cursor *b) {
|
||||||
return EQ(bold) && EQ(italic) && EQ(strikethrough) && EQ(reverse) && EQ(decoration) && EQ(fg) && EQ(bg) && EQ(decoration_fg) && EQ(x) && EQ(y) && EQ(shape) && EQ(blink) && EQ(color);
|
return EQ(bold) && EQ(italic) && EQ(strikethrough) && EQ(reverse) && EQ(decoration) && EQ(fg) && EQ(bg) && EQ(decoration_fg) && EQ(x) && EQ(y) && EQ(shape) && EQ(blink);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BOOL(x) ((x) ? Py_True : Py_False)
|
#define BOOL(x) ((x) ? Py_True : Py_False)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
repr(Cursor *self) {
|
repr(Cursor *self) {
|
||||||
return PyUnicode_FromFormat(
|
return PyUnicode_FromFormat(
|
||||||
"Cursor(x=%u, y=%u, shape=%d, blink=%R, color=#%08x, fg=#%08x, bg=#%08x, bold=%R, italic=%R, reverse=%R, strikethrough=%R, decoration=%d, decoration_fg=#%08x)",
|
"Cursor(x=%u, y=%u, shape=%d, blink=%R, fg=#%08x, bg=#%08x, bold=%R, italic=%R, reverse=%R, strikethrough=%R, decoration=%d, decoration_fg=#%08x)",
|
||||||
self->x, self->y, self->shape, BOOL(self->blink), self->color, self->fg, self->bg, BOOL(self->bold), BOOL(self->italic), BOOL(self->reverse), BOOL(self->strikethrough), self->decoration, self->decoration_fg
|
self->x, self->y, self->shape, BOOL(self->blink), self->fg, self->bg, BOOL(self->bold), BOOL(self->italic), BOOL(self->reverse), BOOL(self->strikethrough), self->decoration, self->decoration_fg
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,12 +52,11 @@ void cursor_reset(Cursor *self) {
|
|||||||
cursor_reset_display_attrs(self);
|
cursor_reset_display_attrs(self);
|
||||||
self->x = 0; self->y = 0;
|
self->x = 0; self->y = 0;
|
||||||
self->shape = 0; self->blink = false;
|
self->shape = 0; self->blink = false;
|
||||||
self->color = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cursor_copy_to(Cursor *src, Cursor *dest) {
|
void cursor_copy_to(Cursor *src, Cursor *dest) {
|
||||||
#define CCY(x) dest->x = src->x;
|
#define CCY(x) dest->x = src->x;
|
||||||
CCY(x); CCY(y); CCY(shape); CCY(blink); CCY(color);
|
CCY(x); CCY(y); CCY(shape); CCY(blink);
|
||||||
CCY(bold); CCY(italic); CCY(strikethrough); CCY(reverse); CCY(decoration); CCY(fg); CCY(bg); CCY(decoration_fg);
|
CCY(bold); CCY(italic); CCY(strikethrough); CCY(reverse); CCY(decoration); CCY(fg); CCY(bg); CCY(decoration_fg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,11 +64,6 @@ static PyObject*
|
|||||||
copy(Cursor *self);
|
copy(Cursor *self);
|
||||||
#define copy_doc "Create a clone of this cursor"
|
#define copy_doc "Create a clone of this cursor"
|
||||||
|
|
||||||
static PyObject* color_get(Cursor *self, void UNUSED *closure) {
|
|
||||||
if (!(self->color & 0xFF)) { Py_RETURN_NONE; }
|
|
||||||
return Py_BuildValue("BBB", (self->color >> 24) & 0xFF, (self->color >> 16) & 0xFF, (self->color >> 8) & 0xFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Boilerplate {{{
|
// Boilerplate {{{
|
||||||
|
|
||||||
BOOL_GETSET(Cursor, bold)
|
BOOL_GETSET(Cursor, bold)
|
||||||
@ -82,7 +76,6 @@ static PyMemberDef members[] = {
|
|||||||
{"x", T_UINT, offsetof(Cursor, x), 0, "x"},
|
{"x", T_UINT, offsetof(Cursor, x), 0, "x"},
|
||||||
{"y", T_UINT, offsetof(Cursor, y), 0, "y"},
|
{"y", T_UINT, offsetof(Cursor, y), 0, "y"},
|
||||||
{"shape", T_UBYTE, offsetof(Cursor, shape), 0, "shape"},
|
{"shape", T_UBYTE, offsetof(Cursor, shape), 0, "shape"},
|
||||||
{"color", T_ULONG, offsetof(Cursor, color), 0, "color"},
|
|
||||||
{"decoration", T_UBYTE, offsetof(Cursor, decoration), 0, "decoration"},
|
{"decoration", T_UBYTE, offsetof(Cursor, decoration), 0, "decoration"},
|
||||||
{"fg", T_ULONG, offsetof(Cursor, fg), 0, "fg"},
|
{"fg", T_ULONG, offsetof(Cursor, fg), 0, "fg"},
|
||||||
{"bg", T_ULONG, offsetof(Cursor, bg), 0, "bg"},
|
{"bg", T_ULONG, offsetof(Cursor, bg), 0, "bg"},
|
||||||
@ -96,7 +89,6 @@ static PyGetSetDef getseters[] = {
|
|||||||
GETSET(reverse)
|
GETSET(reverse)
|
||||||
GETSET(strikethrough)
|
GETSET(strikethrough)
|
||||||
GETSET(blink)
|
GETSET(blink)
|
||||||
{"color", (getter) color_get, NULL, "color", NULL},
|
|
||||||
{NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -188,7 +188,7 @@ typedef struct {
|
|||||||
bool bold, italic, reverse, strikethrough, blink;
|
bool bold, italic, reverse, strikethrough, blink;
|
||||||
unsigned int x, y;
|
unsigned int x, y;
|
||||||
uint8_t decoration, shape;
|
uint8_t decoration, shape;
|
||||||
unsigned long fg, bg, decoration_fg, color;
|
unsigned long fg, bg, decoration_fg;
|
||||||
|
|
||||||
} Cursor;
|
} Cursor;
|
||||||
PyTypeObject Cursor_Type;
|
PyTypeObject Cursor_Type;
|
||||||
@ -289,7 +289,7 @@ typedef struct {
|
|||||||
unsigned int parser_state, parser_text_start, parser_buf_pos;
|
unsigned int parser_state, parser_text_start, parser_buf_pos;
|
||||||
bool parser_has_pending_text;
|
bool parser_has_pending_text;
|
||||||
uint8_t read_buf[READ_BUF_SZ];
|
uint8_t read_buf[READ_BUF_SZ];
|
||||||
uint32_t default_fg, default_bg, highlight_fg, highlight_bg;
|
uint32_t default_fg, default_bg, highlight_fg, highlight_bg, cursor_color;
|
||||||
|
|
||||||
} Screen;
|
} Screen;
|
||||||
PyTypeObject Screen_Type;
|
PyTypeObject Screen_Type;
|
||||||
|
|||||||
@ -46,6 +46,7 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) {
|
|||||||
self->margin_top = 0; self->margin_bottom = self->lines - 1;
|
self->margin_top = 0; self->margin_bottom = self->lines - 1;
|
||||||
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;
|
||||||
|
self->cursor_color = 0;
|
||||||
RESET_CHARSETS;
|
RESET_CHARSETS;
|
||||||
self->callbacks = callbacks; Py_INCREF(callbacks);
|
self->callbacks = callbacks; Py_INCREF(callbacks);
|
||||||
self->cursor = alloc_cursor();
|
self->cursor = alloc_cursor();
|
||||||
@ -72,6 +73,7 @@ screen_reset(Screen *self) {
|
|||||||
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;
|
||||||
|
self->cursor_color = 0;
|
||||||
RESET_CHARSETS;
|
RESET_CHARSETS;
|
||||||
self->margin_top = 0; self->margin_bottom = self->lines - 1;
|
self->margin_top = 0; self->margin_bottom = self->lines - 1;
|
||||||
screen_normal_keypad_mode(self);
|
screen_normal_keypad_mode(self);
|
||||||
@ -1312,6 +1314,7 @@ static PyMemberDef members[] = {
|
|||||||
{"default_bg", T_ULONG, offsetof(Screen, default_bg), 0, "default_bg"},
|
{"default_bg", T_ULONG, offsetof(Screen, default_bg), 0, "default_bg"},
|
||||||
{"highlight_fg", T_ULONG, offsetof(Screen, highlight_fg), 0, "highlight_fg"},
|
{"highlight_fg", T_ULONG, offsetof(Screen, highlight_fg), 0, "highlight_fg"},
|
||||||
{"highlight_bg", T_ULONG, offsetof(Screen, highlight_bg), 0, "highlight_bg"},
|
{"highlight_bg", T_ULONG, offsetof(Screen, highlight_bg), 0, "highlight_bg"},
|
||||||
|
{"cursor_color", T_ULONG, offsetof(Screen, cursor_color), 0, "cursor_color"},
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user