This commit is contained in:
Kovid Goyal 2021-10-14 14:31:11 +05:30
parent ed5accd702
commit a653233050
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 22 additions and 9 deletions

View File

@ -157,7 +157,7 @@ screen_reset(Screen *self) {
memset(self->main_key_encoding_flags, 0, sizeof(self->main_key_encoding_flags));
memset(self->alt_key_encoding_flags, 0, sizeof(self->alt_key_encoding_flags));
self->display_window_number = 0;
self->redraws_multiline_prompts = false;
self->prompt_redraw_settings.val = 0;
self->last_graphic_char = 0;
self->main_savepoint.is_valid = false;
self->alt_savepoint.is_valid = false;
@ -284,6 +284,7 @@ index_selection(const Screen *self, Selections *selections, bool up) {
static void
prevent_current_prompt_from_rewrapping(Screen *self) {
if (!self->prompt_redraw_settings.redraws_prompts_at_all) return;
int y = self->cursor->y;
while (y >= 0) {
linebuf_init_line(self->main_linebuf, y);
@ -293,7 +294,7 @@ prevent_current_prompt_from_rewrapping(Screen *self) {
y--;
}
if (y < 0) return;
if (!self->redraws_multiline_prompts && self->cursor->y > (unsigned) y) return; // bash does not redraw multiline prompts
if (!self->prompt_redraw_settings.redraws_multiline_prompts && self->cursor->y > (unsigned) y) return; // bash does not redraw multiline prompts
// we have identified a prompt at which the cursor is present, the shell
// will redraw this prompt. However when doing so it gets confused if the
// cursor vertical position relative to the first prompt line changes. This
@ -1917,10 +1918,15 @@ shell_prompt_marking(Screen *self, PyObject *data) {
case 'A': {
linebuf_mark_line_as_prompt_start(self->linebuf, self->cursor->y);
size_t l = PyUnicode_GET_LENGTH(data);
self->prompt_redraw_settings.redraws_multiline_prompts = 1;
self->prompt_redraw_settings.redraws_prompts_at_all = 1;
if (l > 8) {
DECREF_AFTER_FUNCTION PyObject *q = PyUnicode_FromString(";does_not_redraw_multiline_prompt");
self->redraws_multiline_prompts = (!q || PyUnicode_Find(data, q, 1, PyUnicode_GET_LENGTH(data), 1) < 0);
} else self->redraws_multiline_prompts = true;
const char *buf = PyUnicode_AsUTF8(data);
if (buf) {
if (strstr(buf, ";does_not_redraw_multiline_prompt")) self->prompt_redraw_settings.redraws_multiline_prompts = 0;
if (strstr(buf, ";does_not_redraw_prompts")) self->prompt_redraw_settings.redraws_prompts_at_all = 0;
}
}
} break;
case 'C':
linebuf_mark_line_as_output_start(self->linebuf, self->cursor->y); break;

View File

@ -131,7 +131,13 @@ typedef struct {
struct {
monotonic_t start, duration;
} ignore_bells;
bool redraws_multiline_prompts;
union {
struct {
unsigned int redraws_multiline_prompts: 1;
unsigned int redraws_prompts_at_all: 1;
};
unsigned int val;
} prompt_redraw_settings;
unsigned int display_window_number;
} Screen;

View File

@ -172,13 +172,14 @@ def real_main(global_opts: RCOptions) -> None:
print('The ID of the previously active window is: {}'.format(awid))
pre_prompt = set_window_title('The kitty shell') + set_cursor_shape('bar')
pre_prompt += '\x1b]133;A\x1b\\'
pre_prompt += '\x1b]133;A;does_not_redraw_prompts\x1b\\'
while True:
try:
print(end=pre_prompt)
try:
scmdline = input(f'{pre_prompt}{kitty_face} ')
scmdline = input(f'{kitty_face} ')
except UnicodeEncodeError:
scmdline = input('{pre_prompt}kitty> ')
scmdline = input('kitty> ')
except EOFError:
break
except KeyboardInterrupt: