mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-09-11 14:45:31 +03:00
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:
parent
ad8e16aac0
commit
46b4f33850
@ -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`]
|
||||
|
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 @@ 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,6 +549,7 @@ 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]
|
||||
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(
|
||||
@ -556,6 +561,10 @@ def _run_kitten(self, kitten, args=()):
|
||||
data = None
|
||||
else:
|
||||
raise ValueError('Unknown type_of_input: {}'.format(type_of_input))
|
||||
else:
|
||||
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:
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user