Function to check if cursor is at marked prompt

This commit is contained in:
Kovid Goyal 2021-08-14 12:08:31 +05:30
parent 28914d4450
commit 81654c9874
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 15 additions and 0 deletions

View File

@ -965,6 +965,9 @@ class Screen:
):
pass
def cursor_at_prompt(self) -> bool:
pass
def current_key_encoding_flags(self) -> int:
pass

View File

@ -3348,6 +3348,17 @@ dump_lines_with_attrs(Screen *self, PyObject *accum) {
Py_RETURN_NONE;
}
static PyObject*
cursor_at_prompt(Screen *self, PyObject *args UNUSED) {
if (self->cursor->y >= self->lines || !screen_is_cursor_visible(self) || self->linebuf != self->main_linebuf) { Py_RETURN_FALSE; }
int y = self->cursor->y;
while (y >= 0) {
linebuf_init_line(self->linebuf, y--);
if (self->linebuf->line->attrs.is_prompt_start) { Py_RETURN_TRUE; }
if (self->linebuf->line->attrs.is_output_start) { Py_RETURN_FALSE; }
}
Py_RETURN_FALSE;
}
#define MND(name, args) {#name, (PyCFunction)name, args, #name},
#define MODEFUNC(name) MND(name, METH_NOARGS) MND(set_##name, METH_O)
@ -3355,6 +3366,7 @@ dump_lines_with_attrs(Screen *self, PyObject *accum) {
static PyMethodDef methods[] = {
MND(line, METH_O)
MND(dump_lines_with_attrs, METH_O)
MND(cursor_at_prompt, METH_NOARGS)
MND(visual_line, METH_VARARGS)
MND(current_url_text, METH_NOARGS)
MND(draw, METH_O)