Code to add markers to Screen
This commit is contained in:
parent
0e448347cd
commit
0b3602f764
3 changed files with 40 additions and 1 deletions
|
|
@ -68,6 +68,8 @@ typedef enum { NONE, MENUBAR, WINDOW, ALL } WindowTitleIn;
|
|||
#define REVERSE_SHIFT 6
|
||||
#define STRIKE_SHIFT 7
|
||||
#define DIM_SHIFT 8
|
||||
#define MARK_SHIFT 9
|
||||
#define MARK_MASK 3
|
||||
#define COL_MASK 0xFFFFFFFF
|
||||
#define UTF8_ACCEPT 0
|
||||
#define UTF8_REJECT 1
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) {
|
|||
self->callbacks = callbacks; Py_INCREF(callbacks);
|
||||
self->test_child = test_child; Py_INCREF(test_child);
|
||||
self->cursor = alloc_cursor();
|
||||
self->markers.callbacks = PyList_New(0);
|
||||
self->color_profile = alloc_color_profile();
|
||||
self->main_linebuf = alloc_linebuf(lines, columns); self->alt_linebuf = alloc_linebuf(lines, columns);
|
||||
self->linebuf = self->main_linebuf;
|
||||
|
|
@ -115,7 +116,11 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) {
|
|||
self->pending_mode.wait_time = 2.0;
|
||||
self->disable_ligatures = OPT(disable_ligatures);
|
||||
self->main_tabstops = PyMem_Calloc(2 * self->columns, sizeof(bool));
|
||||
if (self->cursor == NULL || self->main_linebuf == NULL || self->alt_linebuf == NULL || self->main_tabstops == NULL || self->historybuf == NULL || self->main_grman == NULL || self->alt_grman == NULL || self->color_profile == NULL) {
|
||||
if (
|
||||
self->cursor == NULL || self->main_linebuf == NULL || self->alt_linebuf == NULL ||
|
||||
self->main_tabstops == NULL || self->historybuf == NULL || self->main_grman == NULL ||
|
||||
self->alt_grman == NULL || self->color_profile == NULL || self->markers.callbacks == NULL
|
||||
) {
|
||||
Py_CLEAR(self); return NULL;
|
||||
}
|
||||
self->alt_tabstops = self->main_tabstops + self->columns * sizeof(bool);
|
||||
|
|
@ -278,6 +283,7 @@ dealloc(Screen* self) {
|
|||
Py_CLEAR(self->alt_linebuf);
|
||||
Py_CLEAR(self->historybuf);
|
||||
Py_CLEAR(self->color_profile);
|
||||
Py_CLEAR(self->markers.callbacks);
|
||||
PyMem_Free(self->overlay_line.cpu_cells);
|
||||
PyMem_Free(self->overlay_line.gpu_cells);
|
||||
PyMem_Free(self->main_tabstops);
|
||||
|
|
@ -2241,6 +2247,30 @@ send_escape_code_to_child(Screen *self, PyObject *args) {
|
|||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
add_marker(Screen *self, PyObject *marker) {
|
||||
if (!PyCallable_Check(marker)) {
|
||||
PyErr_SetString(PyExc_TypeError, "marker must be a callable");
|
||||
return NULL;
|
||||
}
|
||||
if (!PySequence_Contains(self->markers.callbacks, marker)) {
|
||||
if (PyList_Append(self->markers.callbacks, marker) != 0) return NULL;
|
||||
self->markers.dirty = true;
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
remove_marker(Screen *self, PyObject *marker) {
|
||||
Py_ssize_t idx = PySequence_Index(self->markers.callbacks, marker);
|
||||
if (idx > -1) {
|
||||
PySequence_DelItem(self->markers.callbacks, idx);
|
||||
self->markers.dirty = true;
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
paste(Screen *self, PyObject *bytes) {
|
||||
if (!PyBytes_Check(bytes)) { PyErr_SetString(PyExc_TypeError, "Must paste() bytes"); return NULL; }
|
||||
|
|
@ -2340,6 +2370,8 @@ static PyMethodDef methods[] = {
|
|||
MND(paste, METH_O)
|
||||
MND(paste_bytes, METH_O)
|
||||
MND(copy_colors_from, METH_O)
|
||||
MND(add_marker, METH_O)
|
||||
MND(remove_marker, METH_O)
|
||||
{"select_graphic_rendition", (PyCFunction)_select_graphic_rendition, METH_VARARGS, ""},
|
||||
|
||||
{NULL} /* Sentinel */
|
||||
|
|
|
|||
|
|
@ -109,6 +109,11 @@ typedef struct {
|
|||
} pending_mode;
|
||||
DisableLigature disable_ligatures;
|
||||
|
||||
struct {
|
||||
PyObject *callbacks;
|
||||
bool dirty;
|
||||
} markers;
|
||||
|
||||
} Screen;
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue