When showing last command output and similar cursor less text with the scrollback pager set CURSOR_LINE and CURSOR_COLUMN to 0

This commit is contained in:
Kovid Goyal 2021-10-27 14:20:33 +05:30
parent 212af78032
commit 13928d4d35
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 9 additions and 8 deletions

View File

@ -1096,11 +1096,11 @@ class Boss:
s.shutdown(socket.SHUT_RDWR)
s.close()
def display_scrollback(self, window: Window, data: Union[bytes, str], input_line_number: int = 0, title: str = '') -> None:
def display_scrollback(self, window: Window, data: Union[bytes, str], input_line_number: int = 0, title: str = '', report_cursor: bool = True) -> None:
def prepare_arg(x: str) -> str:
x = x.replace('INPUT_LINE_NUMBER', str(input_line_number))
x = x.replace('CURSOR_LINE', str(window.screen.cursor.y + 1))
x = x.replace('CURSOR_COLUMN', str(window.screen.cursor.x + 1))
x = x.replace('CURSOR_LINE', str(window.screen.cursor.y + 1) if report_cursor else '0')
x = x.replace('CURSOR_COLUMN', str(window.screen.cursor.x + 1) if report_cursor else '0')
return x
cmd = list(map(prepare_arg, get_options().scrollback_pager))
@ -2003,7 +2003,7 @@ class Boss:
w = self.active_window
if w:
output = '\n'.join(f'{k}={v}' for k, v in os.environ.items())
self.display_scrollback(w, output, title=_('Current kitty env vars'))
self.display_scrollback(w, output, title=_('Current kitty env vars'), report_cursor=False)
def open_file(self, path: str) -> None:
if path == ":cocoa::application launched::":
@ -2031,7 +2031,7 @@ class Boss:
output = debug_config(get_options())
set_clipboard_string(re.sub(r'\x1b.+?m', '', output))
output += '\n\x1b[35mThis debug output has been copied to the clipboard\x1b[m'
self.display_scrollback(w, output, title=_('Current kitty options'))
self.display_scrollback(w, output, title=_('Current kitty options'), report_cursor=False)
@ac('misc', 'Discard this event completely ignoring it')
def discard_event(self) -> None:

View File

@ -288,7 +288,8 @@ passed as STDIN to this program. If you change it, make sure the program you use
can handle ANSI escape sequences for colors and text formatting.
INPUT_LINE_NUMBER in the command line above will be replaced by an integer
representing which line should be at the top of the screen. Similarly
CURSOR_LINE and CURSOR_COLUMN will be replaced by the current cursor position.
CURSOR_LINE and CURSOR_COLUMN will be replaced by the current cursor position or
set to 0 if there is no cursor, for example, when showing the last command output.
'''
)

View File

@ -601,7 +601,7 @@ class Window:
strings: List[str] = []
self.screen.dump_lines_with_attrs(strings.append)
text = ''.join(strings)
get_boss().display_scrollback(self, text, title='Dump of lines')
get_boss().display_scrollback(self, text, title='Dump of lines', report_cursor=False)
def write_to_child(self, data: Union[str, bytes]) -> None:
if data:
@ -1078,7 +1078,7 @@ class Window:
def show_last_command_output(self) -> None:
text = self.last_cmd_output(as_ansi=True, add_wrap_markers=True)
text = text.replace('\r\n', '\n').replace('\r', '\n')
get_boss().display_scrollback(self, text, title='Last command output')
get_boss().display_scrollback(self, text, title='Last command output', report_cursor=False)
def paste_bytes(self, text: Union[str, bytes]) -> None:
# paste raw bytes without any processing