A nice error message when using shortcuts to change background_opacity without setting dynamic_background_opacity

Also change the default shortcuts
This commit is contained in:
Kovid Goyal 2018-05-23 09:14:10 +05:30
parent ad8e16aac0
commit 46b4f33850
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 77 additions and 19 deletions

View File

@ -44,10 +44,10 @@
:sc_scroll_page_down: pass:quotes[`ctrl+shift+page_down`]
:sc_scroll_page_up: pass:quotes[`ctrl+shift+page_up`]
:sc_second_window: pass:quotes[`ctrl+shift+2`]
:sc_set_background_opacity_0_1: pass:quotes[`ctrl+shift+a → shift+-`]
:sc_set_background_opacity_1: pass:quotes[`ctrl+shift+a → shift+1`]
:sc_set_background_opacity_default: pass:quotes[`ctrl+shift+a → shift+d`]
:sc_set_background_opacity_plus0_1: pass:quotes[`ctrl+shift+a → shift+=`]
:sc_set_background_opacity_0_1: pass:quotes[`ctrl+shift+a → l`]
:sc_set_background_opacity_1: pass:quotes[`ctrl+shift+a → 1`]
:sc_set_background_opacity_default: pass:quotes[`ctrl+shift+a → d`]
:sc_set_background_opacity_plus0_1: pass:quotes[`ctrl+shift+a → m`]
:sc_set_tab_title: pass:quotes[`ctrl+shift+alt+t`]
:sc_seventh_window: pass:quotes[`ctrl+shift+7`]
:sc_show_scrollback: pass:quotes[`ctrl+shift+h`]

View File

View File

@ -0,0 +1,46 @@
#!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
import sys
from kitty.cli import parse_args
from ..tui.operations import styled
OPTIONS = '''\
--title
default=ERROR
The title for the error message.
'''.format
def real_main(args):
error_message = sys.stdin.buffer.read().decode('utf-8')
sys.stdin = open('/dev/tty')
msg = 'Show an error message'
args, items = parse_args(args, OPTIONS, '', msg, 'hints')
print(styled(args.title, fg_intense=True, fg='red', bold=True))
print()
print(error_message)
print()
input('Press Enter to close.')
def main(args):
try:
real_main(args)
except KeyboardInterrupt:
pass
except Exception:
import traceback
traceback.print_exc()
input('Press Enter to close.')
def handle_result(args, data, target_window_id, boss):
pass
if __name__ == '__main__':
main(sys.argv)

View File

@ -369,6 +369,10 @@ def set_background_opacity(self, opacity):
window = self.active_window
if window is None or not opacity:
return
if not self.opts.dynamic_background_opacity:
return self.show_error(
_('Cannot change background opacity'),
_('You must set the dynamic_background_opacity option in kitty.conf to be able to change background opacity'))
os_window_id = window.os_window_id
if opacity[0] in '+-':
opacity = background_opacity_of(os_window_id)
@ -537,7 +541,7 @@ def get_output(self, source_window, num_lines=1):
output += str(s.linebuf.line(i))
return output
def _run_kitten(self, kitten, args=()):
def _run_kitten(self, kitten, args=(), input_data=None):
w = self.active_window
tab = self.active_tab
if w is not None and tab is not None and w.overlay_for is None:
@ -545,17 +549,22 @@ def _run_kitten(self, kitten, args=()):
from kittens.runner import create_kitten_handler
end_kitten = create_kitten_handler(kitten, orig_args)
args[0:0] = [config_dir, kitten]
type_of_input = end_kitten.type_of_input
if type_of_input in ('text', 'history', 'ansi', 'ansi-history', 'screen', 'screen-history', 'screen-ansi', 'screen-ansi-history'):
data = w.as_text(
as_ansi='ansi' in type_of_input,
add_history='history' in type_of_input,
add_wrap_markers='screen' in type_of_input
).encode('utf-8')
elif type_of_input is None:
data = None
if input_data is None:
type_of_input = end_kitten.type_of_input
if type_of_input in ('text', 'history', 'ansi', 'ansi-history', 'screen', 'screen-history', 'screen-ansi', 'screen-ansi-history'):
data = w.as_text(
as_ansi='ansi' in type_of_input,
add_history='history' in type_of_input,
add_wrap_markers='screen' in type_of_input
).encode('utf-8')
elif type_of_input is None:
data = None
else:
raise ValueError('Unknown type_of_input: {}'.format(type_of_input))
else:
raise ValueError('Unknown type_of_input: {}'.format(type_of_input))
data = input_data
if isinstance(data, str):
data = data.encode('utf-8')
copts = {k: self.opts[k] for k in ('select_by_word_characters', 'open_url_with')}
overlay_window = tab.new_special_window(
SpecialWindow(
@ -593,6 +602,9 @@ def set_tab_title(self):
args = ['--name=tab-title', '--message', _('Enter the new title for this tab below.'), 'do_set_tab_title', str(tab.id)]
self._run_kitten('ask', args)
def show_error(self, title, msg):
self._run_kitten('show_error', ['--title', title], input_data=msg)
def do_set_tab_title(self, title, tab_id):
tm = self.active_tab_manager
if tm is not None and title:

View File

@ -501,10 +501,10 @@ map kitty_mod+u input_unicode_character
map kitty_mod+f2 edit_config_file
# Open the kitty shell in a new window/tab/overlay/os_window to control kitty using commands.
map kitty_mod+escape kitty_shell window
map kitty_mod+a>shift+= set_background_opacity +0.1
map kitty_mod+a>shift+- set_background_opacity -0.1
map kitty_mod+a>shift+1 set_background_opacity 1
map kitty_mod+a>shift+d set_background_opacity default
map kitty_mod+a>m set_background_opacity +0.1
map kitty_mod+a>l set_background_opacity -0.1
map kitty_mod+a>1 set_background_opacity 1
map kitty_mod+a>d set_background_opacity default
# Sending arbitrary text on shortcut key presses
# You can tell kitty to send arbitrary (UTF-8) encoded text to