Add type annotations to rc protocol field definitions

This commit is contained in:
Kovid Goyal 2022-08-11 22:14:33 +05:30
parent 6be3ae9efc
commit f42d2c63a6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
35 changed files with 147 additions and 142 deletions

View File

@ -277,7 +277,7 @@ def write_remote_control_protocol_docs() -> None: # {{{
from kitty.rc.base import (
RemoteCommand, all_command_names, command_for_name
)
field_pat = re.compile(r'\s*([a-zA-Z0-9_+]+)\s*:\s*(.+)')
field_pat = re.compile(r'\s*([a-zA-Z0-9_+/]+)\s*:\s*(.+)')
def format_cmd(p: Callable[..., None], name: str, cmd: RemoteCommand) -> None:
p(name)
@ -289,7 +289,7 @@ def write_remote_control_protocol_docs() -> None: # {{{
if m is None:
p(line)
else:
fields.append((m.group(1), m.group(2)))
fields.append((m.group(1).split('/')[0], m.group(2)))
if fields:
p('\nFields are:\n')
for (name, desc) in fields:

View File

@ -16,8 +16,8 @@ if TYPE_CHECKING:
class CloseTab(RemoteCommand):
'''
match: Which tab to close
self: Boolean indicating whether to close the tab of the window the command is run in
match/str: Which tab to close
self/bool: Boolean indicating whether to close the tab of the window the command is run in
'''
short_desc = 'Close the specified tabs'

View File

@ -15,8 +15,8 @@ if TYPE_CHECKING:
class CloseWindow(RemoteCommand):
'''
match: Which window to close
self: Boolean indicating whether to close the window the command is run in
match/str: Which window to close
self/bool: Boolean indicating whether to close the window the command is run in
'''
short_desc = 'Close the specified windows'

View File

@ -17,9 +17,9 @@ if TYPE_CHECKING:
class CreateMarker(RemoteCommand):
'''
match: Which window to create the marker in
self: Boolean indicating whether to create marker in the window the command is run in
marker_spec: A list or arguments that define the marker specification, for example: ['text', '1', 'ERROR']
match/str: Which window to create the marker in
self/bool: Boolean indicating whether to create marker in the window the command is run in
marker_spec/list.str: A list or arguments that define the marker specification, for example: ['text', '1', 'ERROR']
'''
short_desc = 'Create a marker that highlights specified text'

View File

@ -15,9 +15,9 @@ if TYPE_CHECKING:
class DetachTab(RemoteCommand):
'''
match: Which tab to detach
target_tab: Which tab to move the detached tab to the OS window it is run in
self: Boolean indicating whether to detach the tab the command is run in
match/str: Which tab to detach
target_tab/str: Which tab to move the detached tab to the OS window it is run in
self/bool: Boolean indicating whether to detach the tab the command is run in
'''
short_desc = 'Detach the specified tabs and place them in a different/new OS window'

View File

@ -16,9 +16,9 @@ if TYPE_CHECKING:
class DetachWindow(RemoteCommand):
'''
match: Which window to detach
target_tab: Which tab to move the detached window to
self: Boolean indicating whether to detach the window the command is run in
match/str: Which window to detach
target_tab/str: Which tab to move the detached window to
self/bool: Boolean indicating whether to detach the window the command is run in
'''
short_desc = 'Detach the specified windows and place them in a different/new tab'

View File

@ -16,10 +16,10 @@ if TYPE_CHECKING:
class DisableLigatures(RemoteCommand):
'''
strategy+: One of :code:`never`, :code:`always` or :code:`cursor`
match_window: Window to change opacity in
match_tab: Tab to change opacity in
all: Boolean indicating operate on all windows
strategy+/choices.never.always.cursor: One of :code:`never`, :code:`always` or :code:`cursor`
match_window/str: Window to change opacity in
match_tab/str: Tab to change opacity in
all/bool: Boolean indicating operate on all windows
'''
short_desc = 'Control ligature rendering'

View File

@ -12,7 +12,7 @@ from .base import (
class Env(RemoteCommand):
'''
env+: Dictionary of environment variables to values. Empty values cause the variable to be removed.
env+/dict.str: Dictionary of environment variables to values. Empty values cause the variable to be removed.
'''
short_desc = 'Change environment variables seen by future children'

View File

@ -16,7 +16,7 @@ if TYPE_CHECKING:
class FocusTab(RemoteCommand):
'''
match: The tab to focus
match/str: The tab to focus
'''
short_desc = 'Focus the specified tab'

View File

@ -17,7 +17,7 @@ if TYPE_CHECKING:
class FocusWindow(RemoteCommand):
'''
match: The window to focus
match/str: The window to focus
'''
short_desc = 'Focus the specified window'

View File

@ -19,8 +19,8 @@ if TYPE_CHECKING:
class GetColors(RemoteCommand):
'''
match: The window to get the colors for
configured: Boolean indicating whether to get configured or current colors
match/str: The window to get the colors for
configured/bool: Boolean indicating whether to get configured or current colors
'''
short_desc = 'Get terminal colors'

View File

@ -16,14 +16,15 @@ if TYPE_CHECKING:
class GetText(RemoteCommand):
'''
match: The window to get text from
extent: One of :code:`screen`, :code:`first_cmd_output_on_screen`, :code:`last_cmd_output`, \
:code:`last_visited_cmd_output`, :code:`all`, or :code:`selection`
ansi: Boolean, if True send ANSI formatting codes
cursor: Boolean, if True send cursor position/style as ANSI codes
wrap_markers: Boolean, if True add wrap markers to output
clear_selection: Boolean, if True clear the selection in the matched window
self: Boolean, if True use window the command was run in
match/str: The window to get text from
extent/choices.screen.first_cmd_output_on_screen.last_cmd_output.last_visited_cmd_output.all.selection: \
One of :code:`screen`, :code:`first_cmd_output_on_screen`, :code:`last_cmd_output`, \
:code:`last_visited_cmd_output`, :code:`all`, or :code:`selection`
ansi/bool: Boolean, if True send ANSI formatting codes
cursor/bool: Boolean, if True send cursor position/style as ANSI codes
wrap_markers/bool: Boolean, if True add wrap markers to output
clear_selection/bool: Boolean, if True clear the selection in the matched window
self/bool: Boolean, if True use window the command was run in
'''
short_desc = 'Get text from the specified window'

View File

@ -20,8 +20,8 @@ def layout_names() -> Iterable[str]:
class GotoLayout(RemoteCommand):
'''
layout+: The new layout name
match: Which tab to change the layout of
layout+/str: The new layout name
match/str: Which tab to change the layout of
'''
short_desc = 'Set the window layout'

View File

@ -15,9 +15,9 @@ if TYPE_CHECKING:
class Kitten(RemoteCommand):
'''
kitten+: The name of the kitten to run
args: Arguments to pass to the kitten as a list
match: The window to run the kitten over
kitten+/str: The name of the kitten to run
args/list.str: Arguments to pass to the kitten as a list
match/str: The window to run the kitten over
'''
short_desc = 'Run a kitten'

View File

@ -15,8 +15,8 @@ if TYPE_CHECKING:
class LastUsedLayout(RemoteCommand):
'''
match: Which tab to change the layout of
all: Boolean to match all tabs
match/str: Which tab to change the layout of
all/bool: Boolean to match all tabs
'''
short_desc = 'Switch to the last used layout'

View File

@ -22,29 +22,30 @@ if TYPE_CHECKING:
class Launch(RemoteCommand):
'''
args+: The command line to run in the new window, as a list, use an empty list to run the default shell
match: The tab to open the new window in
window_title: Title for the new window
cwd: Working directory for the new window
env: List of environment variables of the form NAME=VALUE
tab_title: Title for the new tab
type: The type of window to open
keep_focus: Boolean indicating whether the current window should retain focus or not
copy_colors: Boolean indicating whether to copy the colors from the current window
copy_cmdline: Boolean indicating whether to copy the cmdline from the current window
copy_env: Boolean indicating whether to copy the environ from the current window
hold: Boolean indicating whether to keep window open after cmd exits
location: Where in the tab to open the new window
allow_remote_control: Boolean indicating whether to allow remote control from the new window
stdin_source: Where to get stdin for thew process from
stdin_add_formatting: Boolean indicating whether to add formatting codes to stdin
stdin_add_line_wrap_markers: Boolean indicating whether to add line wrap markers to stdin
no_response: Boolean indicating whether to send back the window id
marker: Specification for marker for new window, for example: "text 1 ERROR"
logo: Path to window logo
logo_position: Window logo position as string or empty string to use default
logo_alpha: Window logo alpha or -1 to use default
self: Boolean, if True use tab the command was run in
args+/list.str: The command line to run in the new window, as a list, use an empty list to run the default shell
match/str: The tab to open the new window in
window_title/str: Title for the new window
cwd/str: Working directory for the new window
env/list.str: List of environment variables of the form NAME=VALUE
tab_title/str: Title for the new tab
type/choices.window.tab.os-window.overlay.background.clipboard.primary: The type of window to open
keep_focus/bool: Boolean indicating whether the current window should retain focus or not
copy_colors/bool: Boolean indicating whether to copy the colors from the current window
copy_cmdline/bool: Boolean indicating whether to copy the cmdline from the current window
copy_env/bool: Boolean indicating whether to copy the environ from the current window
hold/bool: Boolean indicating whether to keep window open after cmd exits
location/choices.first.after.before.neighbor.last.vsplit.hsplit.split.default: Where in the tab to open the new window
allow_remote_control/bool: Boolean indicating whether to allow remote control from the new window
stdin_source/choices.none.@selection.@screen.@screen_scrollback.@alternate.@alternate_scrollback.\
@first_cmd_output_on_screen.@last_cmd_output.@last_visited_cmd_output: Where to get stdin for the process from
stdin_add_formatting/bool: Boolean indicating whether to add formatting codes to stdin
stdin_add_line_wrap_markers/bool: Boolean indicating whether to add line wrap markers to stdin
no_response/bool: Boolean indicating whether to send back the window id
marker/str: Specification for marker for new window, for example: "text 1 ERROR"
logo/str: Path to window logo
logo_position/str: Window logo position as string or empty string to use default
logo_alpha/float: Window logo alpha or -1 to use default
self/bool: Boolean, if True use tab the command was run in
'''
short_desc = 'Run an arbitrary process in a new window/tab'

View File

@ -17,7 +17,7 @@ if TYPE_CHECKING:
class LS(RemoteCommand):
'''
all_env_vars: Whether to send all environment variables for every window rather than just differing ones
all_env_vars/bool: Whether to send all environment variables for every window rather than just differing ones
'''
short_desc = 'List all tabs/windows'

View File

@ -15,15 +15,15 @@ if TYPE_CHECKING:
class NewWindow(RemoteCommand):
'''
args+: The command line to run in the new window, as a list, use an empty list to run the default shell
match: The tab to open the new window in
title: Title for the new window
cwd: Working directory for the new window
keep_focus: Boolean indicating whether the current window should retain focus or not
window_type: One of :code:`kitty` or :code:`os`
new_tab: Boolean indicating whether to open a new tab
tab_title: Title for the new tab
no_response: Boolean indicating whether to send back the window id
args+/list.str: The command line to run in the new window, as a list, use an empty list to run the default shell
match/str: The tab to open the new window in
title/str: Title for the new window
cwd/str: Working directory for the new window
keep_focus/bool: Boolean indicating whether the current window should retain focus or not
window_type/choices.kitty.os: One of :code:`kitty` or :code:`os`
new_tab/bool: Boolean indicating whether to open a new tab
tab_title/str: Title for the new tab
no_response/bool: Boolean indicating whether to send back the window id
'''
short_desc = 'Open new window'

View File

@ -16,8 +16,8 @@ if TYPE_CHECKING:
class RemoveMarker(RemoteCommand):
'''
match: Which window to remove the marker from
self: Boolean indicating whether to detach the window the command is run in
match/str: Which window to remove the marker from
self/bool: Boolean indicating whether to detach the window the command is run in
'''
short_desc = 'Remove the currently set marker, if any.'

View File

@ -14,13 +14,13 @@ if TYPE_CHECKING:
class ResizeOSWindow(RemoteCommand):
'''
match: Which window to resize
self: Boolean indicating whether to close the window the command is run in
incremental: Boolean indicating whether to adjust the size incrementally
action: One of :code:`resize, toggle-fullscreen` or :code:`toggle-maximized`
unit: One of :code:`cells` or :code:`pixels`
width: Integer indicating desired window width
height: Integer indicating desired window height
match/str: Which window to resize
self/bool: Boolean indicating whether to close the window the command is run in
incremental/bool: Boolean indicating whether to adjust the size incrementally
action/choices.resize.toggle-fullscreen.toggle-maximized: One of :code:`resize, toggle-fullscreen` or :code:`toggle-maximized`
unit/choices.cells.pixels: One of :code:`cells` or :code:`pixels`
width/int: Integer indicating desired window width
height/int: Integer indicating desired window height
'''
short_desc = 'Resize the specified OS Windows'

View File

@ -14,10 +14,10 @@ if TYPE_CHECKING:
class ResizeWindow(RemoteCommand):
'''
match: Which window to resize
self: Boolean indicating whether to resize the window the command is run in
increment: Integer specifying the resize increment
axis: One of :code:`horizontal, vertical` or :code:`reset`
match/str: Which window to resize
self/bool: Boolean indicating whether to resize the window the command is run in
increment/int: Integer specifying the resize increment
axis/choices.horizontal.vertical.reset: One of :code:`horizontal, vertical` or :code:`reset`
'''
short_desc = 'Resize the specified windows'

View File

@ -16,11 +16,11 @@ if TYPE_CHECKING:
class ScrollWindow(RemoteCommand):
'''
amount+: The amount to scroll, a two item list with the first item being \
amount+/list.scroll_amount: The amount to scroll, a two item list with the first item being \
either a number or the keywords, start and end. \
And the second item being either 'p' for pages or 'l' for lines or 'u'
for unscrolling by lines.
match: The window to scroll
match/str: The window to scroll
'''
short_desc = 'Scroll the specified windows'

View File

@ -18,11 +18,11 @@ if TYPE_CHECKING:
class SelectWindow(RemoteCommand):
'''
match: The tab to open the new window in
self: Boolean, if True use tab the command was run in
title: A title for this selection
exclude_active: Exclude the currently active window from the list to pick
reactivate_prev_tab: Reactivate the previously activated tab when finished
match/str: The tab to open the new window in
self/bool: Boolean, if True use tab the command was run in
title/str: A title for this selection
exclude_active/bool: Exclude the currently active window from the list to pick
reactivate_prev_tab/bool: Reactivate the previously activated tab when finished
'''
short_desc = 'Visually select a window in the specified tab'

View File

@ -64,12 +64,12 @@ class FocusChangedSession(SessionAction):
class SendText(RemoteCommand):
'''
data+: The data being sent. Can be either: text: followed by text or base64: followed by standard base64 encoded bytes
match: A string indicating the window to send text to
match_tab: A string indicating the tab to send text to
all: A boolean indicating all windows should be matched.
exclude_active: A boolean that prevents sending text to the active window
session_id: A string that identifies a "broadcast session"
data+/send_text: The data being sent. Can be either: text: followed by text or base64: followed by standard base64 encoded bytes
match/str: A string indicating the window to send text to
match_tab/str: A string indicating the tab to send text to
all/bool: A boolean indicating all windows should be matched.
exclude_active/bool: A boolean that prevents sending text to the active window
session_id/internal: A string that identifies a "broadcast session"
'''
short_desc = 'Send arbitrary text to specified windows'
desc = (

View File

@ -18,15 +18,18 @@ if TYPE_CHECKING:
from kitty.cli_stub import SetBackgroundImageRCOptions as CLIOptions
layout_choices = 'tiled,scaled,mirror-tiled,clamped,configured'
class SetBackgroundImage(RemoteCommand):
'''
data+: Chunk of at most 512 bytes of PNG data, base64 encoded. Must send an empty chunk to indicate end of image. \
f'''
data+/image_data: Chunk of at most 512 bytes of PNG data, base64 encoded. Must send an empty chunk to indicate end of image. \
Or the special value - to indicate image must be removed.
match: Window to change opacity in
layout: The image layout
all: Boolean indicating operate on all windows
configured: Boolean indicating if the configured value should be changed
match/str: Window to change opacity in
layout/choices.{layout_choices.replace(",", ".")}: The image layout
all/bool: Boolean indicating operate on all windows
configured/bool: Boolean indicating if the configured value should be changed
'''
short_desc = 'Set the background image'
@ -35,7 +38,7 @@ class SetBackgroundImage(RemoteCommand):
' will be used as the background. If you specify the special value :code:`none` then any existing image will'
' be removed.'
)
options_spec = '''\
options_spec = f'''\
--all -a
type=bool-set
By default, background image is only changed for the currently active OS window. This option will
@ -49,7 +52,7 @@ Change the configured background image which is used for new OS windows.
--layout
type=choices
choices=tiled,scaled,mirror-tiled,clamped,configured
choices={layout_choices}
How the image should be displayed. A value of :code:`configured` will use the configured value.

View File

@ -17,10 +17,10 @@ if TYPE_CHECKING:
class SetBackgroundOpacity(RemoteCommand):
'''
opacity+: A number between 0.1 and 1
match_window: Window to change opacity in
match_tab: Tab to change opacity in
all: Boolean indicating operate on all windows
opacity+/float: A number between 0.1 and 1
match_window/str: Window to change opacity in
match_tab/str: Tab to change opacity in
all/bool: Boolean indicating operate on all windows
'''
short_desc = 'Set the background opacity'

View File

@ -55,12 +55,12 @@ def parse_colors(args: Iterable[str]) -> Dict[str, Optional[int]]:
class SetColors(RemoteCommand):
'''
colors+: An object mapping names to colors as 24-bit RGB integers or null for nullable colors
match_window: Window to change colors in
match_tab: Tab to change colors in
all: Boolean indicating change colors everywhere or not
configured: Boolean indicating whether to change the configured colors. Must be True if reset is True
reset: Boolean indicating colors should be reset to startup values
colors+/dict.colors: An object mapping names to colors as 24-bit RGB integers or null for nullable colors
match_window/str: Window to change colors in
match_tab/str: Tab to change colors in
all/bool: Boolean indicating change colors everywhere or not
configured/bool: Boolean indicating whether to change the configured colors. Must be True if reset is True
reset/bool: Boolean indicating colors should be reset to startup values
'''
short_desc = 'Set terminal colors'

View File

@ -23,9 +23,9 @@ def layout_names() -> Iterable[str]:
class SetEnabledLayouts(RemoteCommand):
'''
layouts+: The list of layout names
match: Which tab to change the layout of
configured: Boolean indicating whether to change the configured value
layouts+/list.str: The list of layout names
match/str: Which tab to change the layout of
configured/bool: Boolean indicating whether to change the configured value
'''
short_desc = 'Set the enabled layouts in tabs'

View File

@ -14,9 +14,9 @@ if TYPE_CHECKING:
class SetFontSize(RemoteCommand):
'''
size+: The new font size in pts (a positive number)
all: Boolean whether to change font size in the current window or all windows
increment_op: The string ``+`` or ``-`` to interpret size as an increment
size+/float: The new font size in pts (a positive number)
all/bool: Boolean whether to change font size in the current window or all windows
increment_op/choices.+.-: The string ``+`` or ``-`` to interpret size as an increment
'''
short_desc = 'Set the font size in the active top-level OS window'

View File

@ -40,11 +40,11 @@ def patch_configured_edges(opts: 'Options', s: Dict[str, Optional[float]]) -> No
class SetSpacing(RemoteCommand):
'''
settings+: An object mapping margins/paddings using canonical form {'margin-top': 50, 'padding-left': null} etc
match_window: Window to change paddings and margins in
match_tab: Tab to change paddings and margins in
all: Boolean indicating change paddings and margins everywhere or not
configured: Boolean indicating whether to change the configured paddings and margins. Must be True if reset is True
settings+/dict.spacing: An object mapping margins/paddings using canonical form {'margin-top': 50, 'padding-left': null} etc
match_window/str: Window to change paddings and margins in
match_tab/str: Tab to change paddings and margins in
all/bool: Boolean indicating change paddings and margins everywhere or not
configured/bool: Boolean indicating whether to change the configured paddings and margins. Must be True if reset is True
'''
short_desc = 'Set window paddings and margins'

View File

@ -38,9 +38,9 @@ def parse_colors(args: ArgsType) -> Dict[str, Optional[int]]:
class SetTabColor(RemoteCommand):
'''
colors+: An object mapping names to colors as 24-bit RGB integers. A color value of null indicates it should be unset.
match: Which tab to change the color of
self: Boolean indicating whether to use the tab of the window the command is run in
colors+/dict.colors: An object mapping names to colors as 24-bit RGB integers. A color value of null indicates it should be unset.
match/str: Which tab to change the color of
self/bool: Boolean indicating whether to use the tab of the window the command is run in
'''
short_desc = 'Change the color of the specified tabs in the tab bar'

View File

@ -16,8 +16,8 @@ if TYPE_CHECKING:
class SetTabTitle(RemoteCommand):
'''
title+: The new title
match: Which tab to change the title of
title+/str: The new title
match/str: Which tab to change the title of
'''
short_desc = 'Set the tab title'

View File

@ -21,12 +21,12 @@ if TYPE_CHECKING:
class SetWindowLogo(RemoteCommand):
'''
data+: Chunk of at most 512 bytes of PNG data, base64 encoded. Must send an empty chunk to indicate end of image. \
data+/image_data: Chunk of at most 512 bytes of PNG data, base64 encoded. Must send an empty chunk to indicate end of image. \
Or the special value :code:`-` to indicate image must be removed.
position: The logo position as a string, empty string means default
alpha: The logo alpha between :code:`0` and :code:`1`. :code:`-1` means use default
match: Which window to change the logo in
self: Boolean indicating whether to act on the window the command is run in
position/str: The logo position as a string, empty string means default
alpha/float: The logo alpha between :code:`0` and :code:`1`. :code:`-1` means use default
match/str: Which window to change the logo in
self/bool: Boolean indicating whether to act on the window the command is run in
'''
short_desc = 'Set the window logo'

View File

@ -15,9 +15,9 @@ if TYPE_CHECKING:
class SetWindowTitle(RemoteCommand):
'''
title: The new title
match: Which windows to change the title in
temporary: Boolean indicating if the change is temporary or permanent
title/str: The new title
match/str: Which windows to change the title in
temporary/bool: Boolean indicating if the change is temporary or permanent
'''
short_desc = 'Set the window title'

View File

@ -15,8 +15,8 @@ if TYPE_CHECKING:
class SignalChild(RemoteCommand):
'''
signals: The signals, a list of names, such as :code:`SIGTERM`, :code:`SIGKILL`, :code:`SIGUSR1`, etc.
match: Which windows to send the signals to
signals/list.str: The signals, a list of names, such as :code:`SIGTERM`, :code:`SIGKILL`, :code:`SIGUSR1`, etc.
match/str: Which windows to send the signals to
'''
short_desc = 'Send a signal to the foreground process in the specified windows'