Cleanup handling of types of kitten input
This commit is contained in:
parent
c96e6822e1
commit
80b5f31256
@ -88,19 +88,41 @@ function, telling kitty what kind of input your kitten would like. For example:
|
|||||||
|
|
||||||
|
|
||||||
This will send the plain text of the active window to the kitten's
|
This will send the plain text of the active window to the kitten's
|
||||||
:file:`STDIN`. For text with formatting escape codes, use ``ansi``
|
:file:`STDIN`. There are many other types of input you can ask for,
|
||||||
instead. If you want line wrap markers as well, use ``screen-ansi``
|
described in the table below:
|
||||||
or just ``screen``. For the scrollback buffer as well, use
|
|
||||||
``history``, ``ansi-history`` or ``screen-history``. To get
|
.. table:: Types of input to kittens
|
||||||
the currently selected text, use ``selection``. To get the output
|
:align: left
|
||||||
of the first command run in the shell on screen, use ``first-output``
|
|
||||||
or ``first-output-ansi`` or ``first-output-screen-ansi``. To get the output
|
=========================== =======================================================================================================
|
||||||
of the last command run in the shell, use ``output`` or ``output-ansi``
|
Keyword Type of :file:`STDIN` input
|
||||||
or ``output-screen-ansi``. To get the first command output below the last
|
=========================== =======================================================================================================
|
||||||
scrolled position via scroll_to_prompt, use ``last-visited-output`` or
|
``text`` Plain text of active window
|
||||||
``last-visited-output-ansi`` or ``last-visited-output-screen-ansi``. Note that
|
``ansi`` Formatted text of active window
|
||||||
using ``first-output`` or ``output`` or ``last-visited-output`` requires
|
``screen`` Plain text of active window with line wrap markers
|
||||||
:ref:`shell_integration`.
|
``screen-ansi`` Formatted text of active window with line wrap markers
|
||||||
|
|
||||||
|
``history`` Plain text of active window and its scrollback
|
||||||
|
``ansi-history`` Formatted text of active window and its scrollback
|
||||||
|
``screen-history`` Plain text of active window and its scrollback with line wrap markers
|
||||||
|
``screen-ansi-history`` Formatted text of active window and its scrollback with line wrap markers
|
||||||
|
|
||||||
|
``output`` Plain text of the output from the last run command
|
||||||
|
``output-screen`` Plain text of the output from the last run command with wrap markers
|
||||||
|
``output-ansi`` Formatted text of the output from the last run command
|
||||||
|
``output-screen-ansi`` Formatted text of the output from the last run command with wrap markers
|
||||||
|
|
||||||
|
``selection`` The text currently selected with the mouse
|
||||||
|
=========================== =======================================================================================================
|
||||||
|
|
||||||
|
In addition to ``output``, that gets the output of the last run command,
|
||||||
|
``last_visited_output`` gives the output of the command last jumped to
|
||||||
|
and ``first_output`` gives the output of the first command currently on screen.
|
||||||
|
These can also be combined with ``screen`` and ``ansi`` for formatting.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
For the types based on the output of a command,
|
||||||
|
:ref:`shell_integration` is required.
|
||||||
|
|
||||||
|
|
||||||
Using kittens to script kitty, without any terminal UI
|
Using kittens to script kitty, without any terminal UI
|
||||||
|
|||||||
@ -1311,26 +1311,17 @@ class Boss:
|
|||||||
args[0:0] = [config_dir, kitten]
|
args[0:0] = [config_dir, kitten]
|
||||||
if input_data is None:
|
if input_data is None:
|
||||||
type_of_input = end_kitten.type_of_input
|
type_of_input = end_kitten.type_of_input
|
||||||
if type_of_input in ('text', 'history', 'ansi', 'ansi-history', 'screen', 'screen-history', 'screen-ansi', 'screen-ansi-history'):
|
q = type_of_input.split('-') if type_of_input else []
|
||||||
data: Optional[bytes] = w.as_text(
|
if not q:
|
||||||
as_ansi='ansi' in type_of_input,
|
data: Optional[bytes] = None
|
||||||
add_history='history' in type_of_input,
|
elif q[0] in ('text', 'history', 'ansi', 'screen'):
|
||||||
add_wrap_markers='screen' in type_of_input
|
data = w.as_text(as_ansi='ansi' in q, add_history='history' in q, add_wrap_markers='screen' in q).encode('utf-8')
|
||||||
).encode('utf-8')
|
|
||||||
elif type_of_input == 'selection':
|
elif type_of_input == 'selection':
|
||||||
sel = self.data_for_at(which='@selection', window=w)
|
sel = self.data_for_at(which='@selection', window=w)
|
||||||
data = sel.encode('utf-8') if sel else None
|
data = sel.encode('utf-8') if sel else None
|
||||||
elif type_of_input is None:
|
elif q[0] in ('output', 'first_output', 'last_visited_output'):
|
||||||
data = None
|
func = {'output': w.last_cmd_output, 'first_output': w.first_cmd_output_on_screen, 'last_visited_output': w.last_visited_cmd_output}[q[0]]
|
||||||
elif type_of_input in ('first-output', 'first-output-screen', 'first-output-screen-ansi', 'first-output-ansi'):
|
data = func(as_ansi='ansi' in q, add_wrap_markers='screen' in q).encode('utf-8')
|
||||||
q = type_of_input.split('-')
|
|
||||||
data = w.first_cmd_output_on_screen(as_ansi='ansi' in q, add_wrap_markers='screen' in q).encode('utf-8')
|
|
||||||
elif type_of_input in ('output', 'output-screen', 'output-screen-ansi', 'output-ansi'):
|
|
||||||
q = type_of_input.split('-')
|
|
||||||
data = w.last_cmd_output(as_ansi='ansi' in q, add_wrap_markers='screen' in q).encode('utf-8')
|
|
||||||
elif type_of_input in ('last-visited-output', 'last-visited-output-screen', 'last-visited-output-screen-ansi', 'last-visited-output-ansi'):
|
|
||||||
q = type_of_input.split('-')
|
|
||||||
data = w.last_visited_cmd_output(as_ansi='ansi' in q, add_wrap_markers='screen' in q).encode('utf-8')
|
|
||||||
else:
|
else:
|
||||||
raise ValueError(f'Unknown type_of_input: {type_of_input}')
|
raise ValueError(f'Unknown type_of_input: {type_of_input}')
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user