Implement OSC codes to change foreground and background colors

This commit is contained in:
Kovid Goyal
2016-11-19 12:50:50 +05:30
parent 0ccdebe7f0
commit 04d8e8f619
4 changed files with 29 additions and 9 deletions

View File

@@ -246,8 +246,14 @@ class Boss(Thread):
self.pending_icon_change = new_icon
glfw.glfwPostEmptyEvent()
def change_default_color(self, which, value):
self.pending_color_changes[which] = value
def set_dynamic_color(self, code, value):
wmap = {10: 'fg', 11: 'bg', 110: 'fg', 111: 'bg'}
for val in value.decode('utf-8').split(';'):
w = wmap.get(code)
if w is not None:
if code >= 110:
val = None
self.pending_color_changes[w] = val
self.queue_action(self.apply_change_colors)
def apply_change_colors(self):

View File

@@ -343,8 +343,9 @@ void screen_delete_lines(Screen *self, unsigned int count/*=1*/);
void screen_delete_characters(Screen *self, unsigned int count);
void screen_erase_characters(Screen *self, unsigned int count);
void screen_set_margins(Screen *self, unsigned int top, unsigned int bottom);
void set_title(Screen *self, const uint8_t *buf, unsigned int sz);
void set_icon(Screen *self, const uint8_t *buf, unsigned int sz);
void set_title(Screen *self, const char *buf, unsigned int sz);
void set_icon(Screen *self, const char *buf, unsigned int sz);
void set_dynamic_color(Screen *self, unsigned int code, const char *buf, unsigned int sz);
void report_device_attributes(Screen *self, unsigned int UNUSED mode, bool UNUSED secondary);
void select_graphic_rendition(Screen *self, unsigned int *params, unsigned int count);
void report_device_status(Screen *self, unsigned int which, bool UNUSED);

View File

@@ -430,7 +430,7 @@ static inline void handle_osc(Screen *screen, PyObject UNUSED *dump_callback) {
if (screen->parser_buf[0] && screen->parser_buf[1]) code = (unsigned int)atoi((const char*)screen->parser_buf + 2);
#define DISPATCH_OSC(name) \
REPORT_COMMAND(name, sz); \
name(screen, screen->parser_buf + start, sz);
name(screen, (const char*)(screen->parser_buf + start), sz);
switch(code) {
case 0:
@@ -443,6 +443,13 @@ static inline void handle_osc(Screen *screen, PyObject UNUSED *dump_callback) {
case 2:
DISPATCH_OSC(set_title);
break;
case 10:
case 11:
case 110:
case 111:
REPORT_COMMAND(set_dynamic_color, code, sz);
set_dynamic_color(screen, code, (const char*)(screen->parser_buf + start), sz);
break;
default:
REPORT_ERROR("Unknown OSC code: %u", code);
}

View File

@@ -849,12 +849,18 @@ void screen_set_cursor(Screen *self, unsigned int mode, uint8_t secondary) {
}
}
void set_title(Screen *self, const uint8_t *buf, unsigned int sz) {
callback("title_changed", self, (const char*)buf, sz);
void set_title(Screen *self, const char *buf, unsigned int sz) {
callback("title_changed", self, buf, sz);
}
void set_icon(Screen *self, const uint8_t *buf, unsigned int sz) {
callback("icon_changed", self, (const char*)buf, sz);
void set_icon(Screen *self, const char *buf, unsigned int sz) {
callback("icon_changed", self, buf, sz);
}
void set_dynamic_color(Screen *self, unsigned int code, const char *buf, unsigned int sz) {
if (sz) PyObject_CallMethod(self->callbacks, "set_dynamic_color", "Iy#", code, buf, sz);
if (PyErr_Occurred()) PyErr_Print();
PyErr_Clear();
}
// }}}