Implement @close-window

This commit is contained in:
Kovid Goyal 2018-01-09 15:27:12 +05:30
parent 6bf04e22cc
commit bced6f31b1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -158,6 +158,31 @@ def set_tab_title(boss, window, payload):
tab.set_title(payload['title']) tab.set_title(payload['title'])
@cmd(
'Close the specified window',
options_spec=MATCH_WINDOW_OPTION + '''\n
--self
type=bool-set
If specified close the window this command is run in, rather than the active window.
'''
)
def cmd_close_window(global_opts, opts, args):
return {'match': opts.match, 'self': opts.self}
def close_window(boss, window, payload):
match = payload['match']
if match:
windows = tuple(boss.match_windows(match))
if not windows:
raise ValueError('No matching windows for expression: {}'.format(match))
else:
windows = [window if window and payload['self'] else boss.active_window]
for window in windows:
if window:
boss.close_window(window)
cmap = {v.name: v for v in globals().values() if hasattr(v, 'is_cmd')} cmap = {v.name: v for v in globals().values() if hasattr(v, 'is_cmd')}