From 66a7c3bc4d6aa6dc41a126e6fa3c55c3f0380938 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 30 Oct 2021 12:15:37 +0530 Subject: [PATCH] Simplify handling of --no-response --- kitty/cli_stub.py | 2 +- kitty/rc/focus_tab.py | 2 -- kitty/rc/focus_window.py | 2 -- kitty/rc/last_used_layout.py | 2 -- kitty/rc/launch.py | 2 -- kitty/rc/new_window.py | 2 -- kitty/rc/resize_os_window.py | 2 -- kitty/rc/set_background_image.py | 2 -- kitty/remote_control.py | 8 +++----- 9 files changed, 4 insertions(+), 20 deletions(-) diff --git a/kitty/cli_stub.py b/kitty/cli_stub.py index e207ef5c6..c14f83549 100644 --- a/kitty/cli_stub.py +++ b/kitty/cli_stub.py @@ -31,7 +31,7 @@ def generate_stub() -> None: do(options_spec(), 'LaunchCLIOptions') from .remote_control import global_options_spec - do(global_options_spec(), 'RCOptions', extra_fields=['no_command_response: typing.Optional[bool]']) + do(global_options_spec(), 'RCOptions') from kittens.ask.main import option_text do(option_text(), 'AskCLIOptions') diff --git a/kitty/rc/focus_tab.py b/kitty/rc/focus_tab.py index 054b87cfb..161461ebd 100644 --- a/kitty/rc/focus_tab.py +++ b/kitty/rc/focus_tab.py @@ -32,8 +32,6 @@ using this option means that you will not be notified of failures. argspec = '' def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType: - if opts.no_response: - global_opts.no_command_response = True return {'match': opts.match} def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType: diff --git a/kitty/rc/focus_window.py b/kitty/rc/focus_window.py index 3392647e3..4998caa46 100644 --- a/kitty/rc/focus_window.py +++ b/kitty/rc/focus_window.py @@ -32,8 +32,6 @@ the command will exit with a success code. ''' def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType: - if opts.no_response: - global_opts.no_command_response = True return {'match': opts.match, 'no_response': opts.no_response} def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType: diff --git a/kitty/rc/last_used_layout.py b/kitty/rc/last_used_layout.py index a56f46358..d9ddb45f9 100644 --- a/kitty/rc/last_used_layout.py +++ b/kitty/rc/last_used_layout.py @@ -37,8 +37,6 @@ the command will exit with a success code. ''' + '\n\n\n' + MATCH_TAB_OPTION def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType: - if opts.no_response: - global_opts.no_command_response = True return {'match': opts.match, 'all': opts.all} def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType: diff --git a/kitty/rc/launch.py b/kitty/rc/launch.py index 69dca3cac..ddc43651b 100644 --- a/kitty/rc/launch.py +++ b/kitty/rc/launch.py @@ -63,8 +63,6 @@ instead of the active tab argspec = '[CMD ...]' def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType: - if opts.no_response: - global_opts.no_command_response = True ans = {'args': args or []} for attr, val in opts.__dict__.items(): ans[attr] = val diff --git a/kitty/rc/new_window.py b/kitty/rc/new_window.py index 05a92b631..f0387c69f 100644 --- a/kitty/rc/new_window.py +++ b/kitty/rc/new_window.py @@ -78,8 +78,6 @@ the id of the new window will not be printed out. argspec = '[CMD ...]' def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType: - if opts.no_response: - global_opts.no_command_response = True return {'match': opts.match, 'title': opts.title, 'cwd': opts.cwd, 'new_tab': opts.new_tab, 'tab_title': opts.tab_title, 'window_type': opts.window_type, 'no_response': opts.no_response, diff --git a/kitty/rc/resize_os_window.py b/kitty/rc/resize_os_window.py index 2dba0f008..5ab7c7f06 100644 --- a/kitty/rc/resize_os_window.py +++ b/kitty/rc/resize_os_window.py @@ -74,8 +74,6 @@ using this option means that you will not be notified of failures. argspec = '' def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType: - if opts.no_response: - global_opts.no_command_response = True return { 'match': opts.match, 'action': opts.action, 'unit': opts.unit, 'width': opts.width, 'height': opts.height, 'self': opts.self, diff --git a/kitty/rc/set_background_image.py b/kitty/rc/set_background_image.py index 9d7c4dfe4..bbb2f1598 100644 --- a/kitty/rc/set_background_image.py +++ b/kitty/rc/set_background_image.py @@ -67,8 +67,6 @@ failed, the command will exit with a success code. def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType: if len(args) != 1: self.fatal('Must specify path to exactly one PNG image') - if opts.no_response: - global_opts.no_command_response = True path = args[0] ret = { 'match': opts.match, diff --git a/kitty/remote_control.py b/kitty/remote_control.py index fdc931c03..1a80ccdae 100644 --- a/kitty/remote_control.py +++ b/kitty/remote_control.py @@ -162,7 +162,6 @@ def create_basic_command(name: str, payload: Any = None, no_response: bool = Fal def main(args: List[str]) -> None: global_opts, items = parse_rc_args(args) - global_opts.no_command_response = None if not items: from kitty.shell import main as smain @@ -179,10 +178,9 @@ def main(args: List[str]) -> None: payload = c.message_to_kitty(global_opts, opts, items) except ParsingOfArgsFailed as err: exit(str(err)) - if global_opts.no_command_response is not None: - no_response = global_opts.no_command_response # type: ignore - else: - no_response = c.no_response + no_response = c.no_response + if hasattr(opts, 'no_response'): + no_response = opts.no_response send = create_basic_command(cmd, payload=payload, no_response=no_response) if not global_opts.to and 'KITTY_LISTEN_ON' in os.environ: global_opts.to = os.environ['KITTY_LISTEN_ON']