From 0d4237f80273cb3dd963fafe33b866081d95d81c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 12 Jul 2021 14:54:44 +0530 Subject: [PATCH] Mark prompt lines --- kitty/data-types.h | 8 ++++++-- kitty/line-buf.c | 13 +++++++++++++ kitty/lineops.h | 2 ++ kitty/screen.c | 16 +++++++++++++++- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/kitty/data-types.h b/kitty/data-types.h index 523ab80fc..c7ded49c0 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -83,8 +83,12 @@ typedef enum { TILING, SCALED, MIRRORED } BackgroundImageLayout; #define COL_MASK 0xFFFFFFFF #define DECORATION_FG_CODE 58 #define CHAR_IS_BLANK(ch) ((ch) == 32 || (ch) == 0) -#define CONTINUED_MASK 1 -#define TEXT_DIRTY_MASK 2 +enum { + CONTINUED_MASK=1, + TEXT_DIRTY_MASK=2, + PROMPT_START_MASK=4, + OUTPUT_START_MASK=8 +}; #define FG 1 #define BG 2 diff --git a/kitty/line-buf.c b/kitty/line-buf.c index 61c1700ec..8367f6391 100644 --- a/kitty/line-buf.c +++ b/kitty/line-buf.c @@ -56,6 +56,19 @@ linebuf_mark_line_as_not_continued(LineBuf *self, index_type y) { self->line_attrs[y] &= ~CONTINUED_MASK; } +void +linebuf_mark_line_as_prompt_start(LineBuf *self, index_type y) { + self->line_attrs[y] |= PROMPT_START_MASK; + self->line_attrs[y] &= ~OUTPUT_START_MASK; +} + +void +linebuf_mark_line_as_output_start(LineBuf *self, index_type y) { + self->line_attrs[y] &= ~PROMPT_START_MASK; + self->line_attrs[y] |= OUTPUT_START_MASK; +} + + static PyObject* clear(LineBuf *self, PyObject *a UNUSED) { diff --git a/kitty/lineops.h b/kitty/lineops.h index 5e93f2dbe..589877e8a 100644 --- a/kitty/lineops.h +++ b/kitty/lineops.h @@ -99,6 +99,8 @@ void linebuf_rewrap(LineBuf *self, LineBuf *other, index_type *, index_type *, H void linebuf_mark_line_dirty(LineBuf *self, index_type y); void linebuf_mark_line_clean(LineBuf *self, index_type y); void linebuf_mark_line_as_not_continued(LineBuf *self, index_type y); +void linebuf_mark_line_as_prompt_start(LineBuf *self, index_type y); +void linebuf_mark_line_as_output_start(LineBuf *self, index_type y); unsigned int linebuf_char_width_at(LineBuf *self, index_type x, index_type y); void linebuf_refresh_sprite_positions(LineBuf *self); void historybuf_add_line(HistoryBuf *self, const Line *line, ANSIBuf*); diff --git a/kitty/screen.c b/kitty/screen.c index 17e29d92a..8bfc74ecf 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -1712,7 +1712,21 @@ clipboard_control(Screen *self, int code, PyObject *data) { void shell_prompt_marking(Screen *self, PyObject *data) { - printf("prompt_marking: x=%d y=%d ", self->cursor->x, self->cursor->y); PyObject_Print(data, stdout, 0); printf("\n"); + if (PyUnicode_READY(data) != 0) { PyErr_Clear(); return; } + if (PyUnicode_GET_LENGTH(data) > 0 && self->cursor->y < self->lines) { + Py_UCS4 ch = PyUnicode_READ_CHAR(data, 0); + switch (ch) { + case 'A': + linebuf_mark_line_as_prompt_start(self->linebuf, self->cursor->y); break; + case 'C': + linebuf_mark_line_as_output_start(self->linebuf, self->cursor->y); break; + } + } + if (global_state.debug_rendering) { + fprintf(stderr, "prompt_marking: x=%d y=%d op=", self->cursor->x, self->cursor->y); + PyObject_Print(data, stderr, 0); + fprintf(stderr, "\n"); + } } void