diff --git a/kitty/screen.c b/kitty/screen.c index 1291f30ec..006935690 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -932,6 +932,14 @@ reset_mode(Screen *self, PyObject *args) { Py_RETURN_NONE; } +static PyObject* +_select_graphic_rendition(Screen *self, PyObject *args) { + unsigned int params[256] = {0}; + for (int i = 0; i < PyTuple_GET_SIZE(args); i++) { params[i] = PyLong_AsUnsignedLong(PyTuple_GET_ITEM(args, i)); } + select_graphic_rendition(self, params, PyList_GET_SIZE(args)); + Py_RETURN_NONE; +} + static PyObject* set_mode(Screen *self, PyObject *args) { int private = false; @@ -1139,6 +1147,7 @@ static PyMethodDef methods[] = { MND(mouse_move_tracking_enabled, METH_NOARGS) MND(mouse_in_sgr_mode, METH_NOARGS) {"update_cell_data", (PyCFunction)screen_update_cell_data, METH_VARARGS, ""}, + {"select_graphic_rendition", (PyCFunction)_select_graphic_rendition, METH_VARARGS, ""}, {NULL} /* Sentinel */ }; diff --git a/kitty_tests/screen.py b/kitty_tests/screen.py index 8e56d00fa..9dc5a64d3 100644 --- a/kitty_tests/screen.py +++ b/kitty_tests/screen.py @@ -313,3 +313,17 @@ class TestScreen(BaseTest): c = chr(ord('I') + l - 2) self.ae(c + ' ' * (s.columns - 2) + c.lower(), str(s.line(l))) s.reset_mode(DECOM) + + def test_sgr(self): + s = self.create_screen() + s.select_graphic_rendition(0, 1, 37, 42) + s.draw('a') + c = s.line(0).cursor_from(0) + self.assertTrue(c.bold) + self.ae(c.bg, (2 << 8) | 1) + s.cursor_position(2, 1) + s.select_graphic_rendition(0, 35) + s.draw('b') + c = s.line(1).cursor_from(0) + self.ae(c.fg, (5 << 8) | 1) + self.ae(c.bg, 0)