diff --git a/kitty/screen.c b/kitty/screen.c index 3c8e18d35..ffc7afc5d 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -1034,7 +1034,7 @@ screen_current_char_width(Screen *self) { } bool -screen_is_cursor_visible(Screen *self) { +screen_is_cursor_visible(const Screen *self) { return self->modes.mDECTCEM; } @@ -1347,7 +1347,7 @@ screen_cursor_to_line(Screen *self, unsigned int line) { int screen_cursor_at_a_shell_prompt(const Screen *self) { - if (self->cursor->y >= self->lines || self->linebuf != self->main_linebuf) return false; + if (self->cursor->y >= self->lines || self->linebuf != self->main_linebuf || !screen_is_cursor_visible(self)) return -1; for (index_type y=self->cursor->y + 1; y-- > 0; ) { linebuf_init_line(self->linebuf, y); if (self->linebuf->line->attrs.is_output_start) return -1; @@ -3358,13 +3358,8 @@ dump_lines_with_attrs(Screen *self, PyObject *accum) { 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; } - } + int y = screen_cursor_at_a_shell_prompt(self); + if (y > -1) { Py_RETURN_TRUE; } Py_RETURN_FALSE; } diff --git a/kitty/screen.h b/kitty/screen.h index 7d443d823..cb1f0dfea 100644 --- a/kitty/screen.h +++ b/kitty/screen.h @@ -213,7 +213,7 @@ bool screen_is_selection_dirty(Screen *self); bool screen_has_selection(Screen*); bool screen_invert_colors(Screen *self); void screen_update_cell_data(Screen *self, void *address, FONTS_DATA_HANDLE, bool cursor_has_moved); -bool screen_is_cursor_visible(Screen *self); +bool screen_is_cursor_visible(const Screen *self); bool screen_selection_range_for_line(Screen *self, index_type y, index_type *start, index_type *end); bool screen_selection_range_for_word(Screen *self, const index_type x, const index_type y, index_type *, index_type *, index_type *start, index_type *end, bool); void screen_start_selection(Screen *self, index_type x, index_type y, bool, bool, SelectionExtendMode);