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:
@@ -44,10 +44,10 @@
|
|||||||
:sc_scroll_page_down: pass:quotes[`ctrl+shift+page_down`]
|
:sc_scroll_page_down: pass:quotes[`ctrl+shift+page_down`]
|
||||||
:sc_scroll_page_up: pass:quotes[`ctrl+shift+page_up`]
|
:sc_scroll_page_up: pass:quotes[`ctrl+shift+page_up`]
|
||||||
:sc_second_window: pass:quotes[`ctrl+shift+2`]
|
:sc_second_window: pass:quotes[`ctrl+shift+2`]
|
||||||
:sc_set_background_opacity_0_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 → shift+1`]
|
:sc_set_background_opacity_1: pass:quotes[`ctrl+shift+a → 1`]
|
||||||
:sc_set_background_opacity_default: pass:quotes[`ctrl+shift+a → shift+d`]
|
:sc_set_background_opacity_default: pass:quotes[`ctrl+shift+a → d`]
|
||||||
:sc_set_background_opacity_plus0_1: pass:quotes[`ctrl+shift+a → shift+=`]
|
:sc_set_background_opacity_plus0_1: pass:quotes[`ctrl+shift+a → m`]
|
||||||
:sc_set_tab_title: pass:quotes[`ctrl+shift+alt+t`]
|
:sc_set_tab_title: pass:quotes[`ctrl+shift+alt+t`]
|
||||||
:sc_seventh_window: pass:quotes[`ctrl+shift+7`]
|
:sc_seventh_window: pass:quotes[`ctrl+shift+7`]
|
||||||
:sc_show_scrollback: pass:quotes[`ctrl+shift+h`]
|
:sc_show_scrollback: pass:quotes[`ctrl+shift+h`]
|
||||||
|
|||||||
0
kittens/show_error/__init__.py
Normal file
0
kittens/show_error/__init__.py
Normal file
46
kittens/show_error/main.py
Normal file
46
kittens/show_error/main.py
Normal 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)
|
||||||
@@ -369,6 +369,10 @@ class Boss:
|
|||||||
window = self.active_window
|
window = self.active_window
|
||||||
if window is None or not opacity:
|
if window is None or not opacity:
|
||||||
return
|
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
|
os_window_id = window.os_window_id
|
||||||
if opacity[0] in '+-':
|
if opacity[0] in '+-':
|
||||||
opacity = background_opacity_of(os_window_id)
|
opacity = background_opacity_of(os_window_id)
|
||||||
@@ -537,7 +541,7 @@ class Boss:
|
|||||||
output += str(s.linebuf.line(i))
|
output += str(s.linebuf.line(i))
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def _run_kitten(self, kitten, args=()):
|
def _run_kitten(self, kitten, args=(), input_data=None):
|
||||||
w = self.active_window
|
w = self.active_window
|
||||||
tab = self.active_tab
|
tab = self.active_tab
|
||||||
if w is not None and tab is not None and w.overlay_for is None:
|
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
|
from kittens.runner import create_kitten_handler
|
||||||
end_kitten = create_kitten_handler(kitten, orig_args)
|
end_kitten = create_kitten_handler(kitten, orig_args)
|
||||||
args[0:0] = [config_dir, kitten]
|
args[0:0] = [config_dir, kitten]
|
||||||
type_of_input = end_kitten.type_of_input
|
if input_data is None:
|
||||||
if type_of_input in ('text', 'history', 'ansi', 'ansi-history', 'screen', 'screen-history', 'screen-ansi', 'screen-ansi-history'):
|
type_of_input = end_kitten.type_of_input
|
||||||
data = w.as_text(
|
if type_of_input in ('text', 'history', 'ansi', 'ansi-history', 'screen', 'screen-history', 'screen-ansi', 'screen-ansi-history'):
|
||||||
as_ansi='ansi' in type_of_input,
|
data = w.as_text(
|
||||||
add_history='history' in type_of_input,
|
as_ansi='ansi' in type_of_input,
|
||||||
add_wrap_markers='screen' in type_of_input
|
add_history='history' in type_of_input,
|
||||||
).encode('utf-8')
|
add_wrap_markers='screen' in type_of_input
|
||||||
elif type_of_input is None:
|
).encode('utf-8')
|
||||||
data = None
|
elif type_of_input is None:
|
||||||
|
data = None
|
||||||
|
else:
|
||||||
|
raise ValueError('Unknown type_of_input: {}'.format(type_of_input))
|
||||||
else:
|
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')}
|
copts = {k: self.opts[k] for k in ('select_by_word_characters', 'open_url_with')}
|
||||||
overlay_window = tab.new_special_window(
|
overlay_window = tab.new_special_window(
|
||||||
SpecialWindow(
|
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)]
|
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)
|
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):
|
def do_set_tab_title(self, title, tab_id):
|
||||||
tm = self.active_tab_manager
|
tm = self.active_tab_manager
|
||||||
if tm is not None and title:
|
if tm is not None and title:
|
||||||
|
|||||||
@@ -501,10 +501,10 @@ map kitty_mod+u input_unicode_character
|
|||||||
map kitty_mod+f2 edit_config_file
|
map kitty_mod+f2 edit_config_file
|
||||||
# Open the kitty shell in a new window/tab/overlay/os_window to control kitty using commands.
|
# 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+escape kitty_shell window
|
||||||
map kitty_mod+a>shift+= set_background_opacity +0.1
|
map kitty_mod+a>m set_background_opacity +0.1
|
||||||
map kitty_mod+a>shift+- set_background_opacity -0.1
|
map kitty_mod+a>l set_background_opacity -0.1
|
||||||
map kitty_mod+a>shift+1 set_background_opacity 1
|
map kitty_mod+a>1 set_background_opacity 1
|
||||||
map kitty_mod+a>shift+d set_background_opacity default
|
map kitty_mod+a>d set_background_opacity default
|
||||||
|
|
||||||
# Sending arbitrary text on shortcut key presses
|
# Sending arbitrary text on shortcut key presses
|
||||||
# You can tell kitty to send arbitrary (UTF-8) encoded text to
|
# You can tell kitty to send arbitrary (UTF-8) encoded text to
|
||||||
|
|||||||
Reference in New Issue
Block a user