Simplify handling of --no-response

This commit is contained in:
Kovid Goyal 2021-10-30 12:15:37 +05:30
parent 3553b3ce3d
commit 66a7c3bc4d
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
9 changed files with 4 additions and 20 deletions

View file

@ -31,7 +31,7 @@ def do(otext=None, cls: str = 'CLIOptions', extra_fields: Sequence[str] = ()):
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')

View file

@ -32,8 +32,6 @@ class FocusTab(RemoteCommand):
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:

View file

@ -32,8 +32,6 @@ class FocusWindow(RemoteCommand):
'''
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:

View file

@ -37,8 +37,6 @@ class LastUsedLayout(RemoteCommand):
''' + '\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:

View file

@ -63,8 +63,6 @@ class Launch(RemoteCommand):
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

View file

@ -78,8 +78,6 @@ class NewWindow(RemoteCommand):
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,

View file

@ -74,8 +74,6 @@ class ResizeOSWindow(RemoteCommand):
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,

View file

@ -67,8 +67,6 @@ class SetBackgroundImage(RemoteCommand):
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,

View file

@ -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']