_run_kitten -> run_kitten_with_metadata

This commit is contained in:
Kovid Goyal 2022-05-28 11:00:25 +05:30
parent 27906ea853
commit 0893d7164a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 15 additions and 14 deletions

View File

@ -651,8 +651,9 @@ class Boss:
) -> None: ) -> None:
def callback_(res: Dict[str, Any], x: int, boss: Boss) -> None: def callback_(res: Dict[str, Any], x: int, boss: Boss) -> None:
callback(res.get('response') == 'y', *args) callback(res.get('response') == 'y', *args)
self._run_kitten('ask', ['--type=yesno', '--message', msg, '--default', 'y' if confirm_on_accept else 'n'], self.run_kitten_with_metadata(
window=window, custom_callback=callback_, default_data={'response': 'y' if confirm_on_cancel else 'n'}) 'ask', ['--type=yesno', '--message', msg, '--default', 'y' if confirm_on_accept else 'n'],
window=window, custom_callback=callback_, default_data={'response': 'y' if confirm_on_cancel else 'n'})
def choose( def choose(
self, msg: str, # can contain newlines and ANSI formatting self, msg: str, # can contain newlines and ANSI formatting
@ -668,7 +669,7 @@ class Boss:
cmd += ['-d', default] cmd += ['-d', default]
for c in choices: for c in choices:
cmd += ['-c', c] cmd += ['-c', c]
self._run_kitten('ask', cmd, window=window, custom_callback=callback_, default_data={'response': ''}) self.run_kitten_with_metadata('ask', cmd, window=window, custom_callback=callback_, default_data={'response': ''})
def get_line( def get_line(
self, msg: str, # can contain newlines and ANSI formatting self, msg: str, # can contain newlines and ANSI formatting
@ -680,7 +681,7 @@ class Boss:
def callback_(res: Dict[str, Any], x: int, boss: Boss) -> None: def callback_(res: Dict[str, Any], x: int, boss: Boss) -> None:
callback(res.get('response') or '') callback(res.get('response') or '')
cmd = ['--type', 'password' if is_password else 'line', '--message', msg, '--prompt', prompt] cmd = ['--type', 'password' if is_password else 'line', '--message', msg, '--prompt', prompt]
self._run_kitten('ask', cmd, window=window, custom_callback=callback_, default_data={'response': ''}) self.run_kitten_with_metadata('ask', cmd, window=window, custom_callback=callback_, default_data={'response': ''})
def confirm_tab_close(self, tab: Tab) -> None: def confirm_tab_close(self, tab: Tab) -> None:
x = get_options().confirm_os_window_close x = get_options().confirm_os_window_close
@ -1073,7 +1074,7 @@ class Boss:
w = self.active_window w = self.active_window
if w is None: if w is None:
return return
overlay_window = self._run_kitten('resize_window', args=[ overlay_window = self.run_kitten_with_metadata('resize_window', args=[
f'--horizontal-increment={get_options().window_resize_step_cells}', f'--horizontal-increment={get_options().window_resize_step_cells}',
f'--vertical-increment={get_options().window_resize_step_lines}' f'--vertical-increment={get_options().window_resize_step_lines}'
]) ])
@ -1419,10 +1420,10 @@ class Boss:
@ac('misc', 'Run the specified kitten. See :doc:`/kittens/custom` for details') @ac('misc', 'Run the specified kitten. See :doc:`/kittens/custom` for details')
def kitten(self, kitten: str, *kargs: str) -> None: def kitten(self, kitten: str, *kargs: str) -> None:
self._run_kitten(kitten, kargs) self.run_kitten_with_metadata(kitten, kargs)
def run_kitten(self, kitten: str, *args: str) -> None: def run_kitten(self, kitten: str, *args: str) -> None:
self._run_kitten(kitten, args) self.run_kitten_with_metadata(kitten, args)
def on_kitten_finish( def on_kitten_finish(
self, target_window_id: int, end_kitten: Callable[[Dict[str, Any], int, 'Boss'], None], self, target_window_id: int, end_kitten: Callable[[Dict[str, Any], int, 'Boss'], None],
@ -1437,7 +1438,7 @@ class Boss:
@ac('misc', 'Input an arbitrary unicode character. See :doc:`/kittens/unicode_input` for details.') @ac('misc', 'Input an arbitrary unicode character. See :doc:`/kittens/unicode_input` for details.')
def input_unicode_character(self) -> None: def input_unicode_character(self) -> None:
self._run_kitten('unicode_input') self.run_kitten_with_metadata('unicode_input')
@ac('tab', 'Change the title of the active tab') @ac('tab', 'Change the title of the active tab')
def set_tab_title(self) -> None: def set_tab_title(self) -> None:
@ -1446,7 +1447,7 @@ class Boss:
args = [ args = [
'--name=tab-title', '--message', _('Enter the new title for this tab below.'), '--name=tab-title', '--message', _('Enter the new title for this tab below.'),
'--default', tab.name or tab.title, 'do_set_tab_title', str(tab.id)] '--default', tab.name or tab.title, 'do_set_tab_title', str(tab.id)]
self._run_kitten('ask', args) self.run_kitten_with_metadata('ask', args)
def do_set_tab_title(self, title: str, tab_id: int) -> None: def do_set_tab_title(self, title: str, tab_id: int) -> None:
tm = self.active_tab_manager tm = self.active_tab_manager
@ -1463,7 +1464,7 @@ class Boss:
if ec != (None, None, None): if ec != (None, None, None):
import traceback import traceback
tb = traceback.format_exc() tb = traceback.format_exc()
self._run_kitten('show_error', args=['--title', title], input_data=json.dumps({'msg': msg, 'tb': tb})) self.run_kitten_with_metadata('show_error', args=['--title', title], input_data=json.dumps({'msg': msg, 'tb': tb}))
@ac('mk', 'Create a new marker') @ac('mk', 'Create a new marker')
def create_marker(self) -> None: def create_marker(self) -> None:
@ -1483,7 +1484,7 @@ class Boss:
except Exception as err: except Exception as err:
self.show_error(_('Invalid marker specification'), str(err)) self.show_error(_('Invalid marker specification'), str(err))
self._run_kitten('ask', [ self.run_kitten_with_metadata('ask', [
'--name=create-marker', '--message', '--name=create-marker', '--message',
_('Create marker, for example:\ntext 1 ERROR\nSee {}\n').format(website_url('marks')) _('Create marker, for example:\ntext 1 ERROR\nSee {}\n').format(website_url('marks'))
], ],
@ -1549,7 +1550,7 @@ class Boss:
@ac('misc', 'Click a URL using the keyboard') @ac('misc', 'Click a URL using the keyboard')
def open_url_with_hints(self) -> None: def open_url_with_hints(self) -> None:
self._run_kitten('hints') self.run_kitten_with_metadata('hints')
def drain_actions(self, actions: List[KeyAction], window_for_dispatch: Optional[Window] = None, dispatch_type: str = 'KeyPress') -> None: def drain_actions(self, actions: List[KeyAction], window_for_dispatch: Optional[Window] = None, dispatch_type: str = 'KeyPress') -> None:
@ -2139,7 +2140,7 @@ class Boss:
def done2(target_window_id: int, self: Boss) -> None: def done2(target_window_id: int, self: Boss) -> None:
callback(ans) callback(ans)
q = self._run_kitten( q = self.run_kitten_with_metadata(
'hints', args=( 'hints', args=(
'--ascending', '--customize-processing=::import::kitty.choose_entry', '--ascending', '--customize-processing=::import::kitty.choose_entry',
'--window-title', title, '--window-title', title,

View File

@ -41,7 +41,7 @@ class Kitten(RemoteCommand):
retval = None retval = None
for window in self.windows_for_match_payload(boss, window, payload_get): for window in self.windows_for_match_payload(boss, window, payload_get):
if window: if window:
retval = boss._run_kitten(payload_get('kitten'), args=tuple(payload_get('args') or ()), window=window) retval = boss.run_kitten_with_metadata(payload_get('kitten'), args=tuple(payload_get('args') or ()), window=window)
break break
if isinstance(retval, (str, bool)): if isinstance(retval, (str, bool)):
return retval return retval