kitty @ get-text add an option to also get the current cursor position and state as ANSI escape codes

Fixes #3625
This commit is contained in:
Kovid Goyal
2021-05-15 09:27:28 +05:30
parent 3bf9130b0a
commit fcd206891f
5 changed files with 55 additions and 15 deletions

View File

@@ -20,6 +20,7 @@ class GetText(RemoteCommand):
match: The tab to focus
extent: One of :code:`screen`, :code:`all`, or :code:`selection`
ansi: Boolean, if True send ANSI formatting codes
cursor: Boolean, if True send cursor position/style as ANSI codes
self: Boolean, if True use window command was run in
'''
@@ -39,6 +40,11 @@ include the formatting escape codes for colors/bold/italic/etc. Note that when
getting the current selection, the result is always plain text.
--add-cursor
type=bool-set
Add ANSI escape codes specifying the cursor position and style to the end of the text.
--self
type=bool-set
If specified get text from the window this command is run in, rather than the active window.
@@ -46,14 +52,18 @@ If specified get text from the window this command is run in, rather than the ac
argspec = ''
def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType:
return {'match': opts.match, 'extent': opts.extent, 'ansi': opts.ansi, 'self': opts.self}
return {'match': opts.match, 'extent': opts.extent, 'ansi': opts.ansi, 'self': opts.self, 'cursor': opts.add_cursor}
def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType:
window = self.windows_for_match_payload(boss, window, payload_get)[0]
if payload_get('extent') == 'selection':
ans = window.text_for_selection()
else:
ans = window.as_text(as_ansi=bool(payload_get('ansi')), add_history=payload_get('extent') == 'all')
ans = window.as_text(
as_ansi=bool(payload_get('ansi')),
add_history=payload_get('extent') == 'all',
add_cursor=bool(payload_get('cursor')),
)
return ans