@resize-window now has a useful return code

This commit is contained in:
Kovid Goyal 2018-05-18 00:01:31 +05:30
parent 3875ee021a
commit 05ec174868
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 10 additions and 5 deletions

View File

@ -21,7 +21,7 @@ class MatchError(ValueError):
ValueError.__init__(self, 'No matching {} for expression: {}'.format(target, expression))
def cmd(short_desc, desc=None, options_spec=None, no_response=False, argspec='...'):
def cmd(short_desc, desc=None, options_spec=None, no_response=False, argspec='...', string_return_is_error=False):
def w(func):
func.short_desc = short_desc
@ -32,6 +32,7 @@ def cmd(short_desc, desc=None, options_spec=None, no_response=False, argspec='..
func.is_cmd = True
func.impl = lambda: globals()[func.__name__[4:]]
func.no_response = no_response
func.string_return_is_error = string_return_is_error
return func
return w
@ -299,7 +300,8 @@ reset the layout to its default configuration.
type=bool-set
If specified close the window this command is run in, rather than the active window.
''',
argspec=''
argspec='',
string_return_is_error=True
)
def cmd_resize_window(global_opts, opts, args):
return {'match': opts.match, 'increment': opts.increment, 'axis': opts.axis, 'self': opts.self}

View File

@ -130,5 +130,8 @@ def main(args):
if response.get('tb'):
print(response['tb'], file=sys.stderr)
raise SystemExit(response['error'])
if 'data' in response:
print(response['data'])
data = response.get('data')
if data is not None:
if func.string_return_is_error and isinstance(data, str):
raise SystemExit(data)
print(data)

View File

@ -166,7 +166,7 @@ class Tab: # {{{
increment_as_percent = self.current_layout.bias_increment_for_cell(is_horizontal) * increment
if self.current_layout.modify_size_of_window(self.windows, window_id, increment_as_percent, is_horizontal):
self.relayout()
return ''
return
return 'Could not resize'
def reset_window_sizes(self):