diff --git a/README.asciidoc b/README.asciidoc index a7156b5ff..d602cbf80 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -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`] diff --git a/kittens/show_error/__init__.py b/kittens/show_error/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/kittens/show_error/main.py b/kittens/show_error/main.py new file mode 100644 index 000000000..c8911d43f --- /dev/null +++ b/kittens/show_error/main.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +# vim:fileencoding=utf-8 +# License: GPL v3 Copyright: 2018, Kovid Goyal + +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) diff --git a/kitty/boss.py b/kitty/boss.py index 24eb4c8ca..3f6e3ad54 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -369,6 +369,10 @@ class Boss: 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 @@ class Boss: 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 @@ class Boss: 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 @@ class Boss: 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: diff --git a/kitty/kitty.conf b/kitty/kitty.conf index 3cc161c7b..2b693785b 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -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