From c6da374aa9e6aa22e5850dcb051aa2ae9c87f96d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 15 Mar 2018 11:15:35 +0530 Subject: [PATCH] Add a configurable keyboard shortcut and remote command to set the font size to a specific value Fixes #388 --- kitty/boss.py | 12 +++++------- kitty/config.py | 4 +++- kitty/kitty.conf | 1 + kitty/remote_control.py | 21 ++++++++++++++++++--- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/kitty/boss.py b/kitty/boss.py index 95a4361a8..abb98cd6e 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -288,19 +288,16 @@ class Boss: tm.resize() def increase_font_size(self): - self.change_font_size( + self.set_font_size( min( self.opts.font_size * 5, self.current_font_size + self.opts.font_size_delta)) def decrease_font_size(self): - self.change_font_size( - max( - MINIMUM_FONT_SIZE, self.current_font_size - - self.opts.font_size_delta)) + self.set_font_size(self.current_font_size - self.opts.font_size_delta) def restore_font_size(self): - self.change_font_size(self.opts.font_size) + self.set_font_size(self.opts.font_size) def _change_font_size(self, new_size=None, on_dpi_change=False): if new_size is not None: @@ -318,7 +315,8 @@ class Boss: tm.refresh_sprite_positions() glfw_post_empty_event() - def change_font_size(self, new_size): + def set_font_size(self, new_size): + new_size = max(MINIMUM_FONT_SIZE, new_size) if new_size == self.current_font_size: return self._change_font_size(new_size) diff --git a/kitty/config.py b/kitty/config.py index 48f9336c8..8187670ac 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -113,6 +113,8 @@ def parse_key_action(action): args = (max(0, int(rest)), ) elif func == 'goto_layout': args = [rest] + elif func == 'set_font_size': + args = (float(rest),) elif func in shlex_actions: args = shlex.split(rest) return KeyAction(func, args) @@ -351,7 +353,7 @@ def parse_config(lines, check_keys=True): Options, defaults = init_config(default_config_path, parse_config) actions = frozenset(a.func for a in defaults.keymap.values()) | frozenset( - 'combine send_text goto_tab goto_layout new_tab_with_cwd new_window_with_cwd new_os_window_with_cwd'. + 'combine send_text goto_tab goto_layout set_font_size new_tab_with_cwd new_window_with_cwd new_os_window_with_cwd'. split() ) no_op_actions = frozenset({'noop', 'no-op', 'no_op'}) diff --git a/kitty/kitty.conf b/kitty/kitty.conf index 7b2be10da..b13d44ebf 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -354,6 +354,7 @@ map ctrl+shift+, move_tab_backward # Miscellaneous map ctrl+shift+equal increase_font_size map ctrl+shift+minus decrease_font_size +# map ctrl+shift+f6 set_font_size 20.0 map ctrl+shift+backspace restore_font_size map ctrl+shift+f11 toggle_fullscreen map ctrl+shift+u input_unicode_character diff --git a/kitty/remote_control.py b/kitty/remote_control.py index 634bc5b80..bdd0f8379 100644 --- a/kitty/remote_control.py +++ b/kitty/remote_control.py @@ -16,10 +16,11 @@ from .tabs import SpecialWindow from .utils import non_blocking_read, parse_address_spec, read_with_timeout -def cmd(short_desc, desc=None, options_spec=None, no_response=False): +def cmd(short_desc, desc=None, options_spec=None, no_response=False, argspec='...'): def w(func): func.short_desc = short_desc + func.argspec = argspec func.desc = desc or short_desc func.name = func.__name__[4:].replace('_', '-') func.options_spec = options_spec @@ -31,7 +32,7 @@ def cmd(short_desc, desc=None, options_spec=None, no_response=False): def parse_subcommand_cli(func, args): - opts, items = parse_args(args[1:], (func.options_spec or '\n').format, '...', func.desc, '{} @ {}'.format(appname, func.name)) + opts, items = parse_args(args[1:], (func.options_spec or '\n').format, func.argspec, func.desc, '{} @ {}'.format(appname, func.name)) return opts, items @@ -42,7 +43,8 @@ def parse_subcommand_cli(func, args): ' of |_ tabs|. Each tab has its own |_ id|, a |_ title| and a list of |_ windows|.' ' Each window has an |_ id|, |_ title|, |_ current working directory|, |_ process id (PID)| and' ' |_ command-line| of the process running in the window.\n\n' - 'You can use these criteria to select windows/tabs for the other commands.'.format(appname=appname) + 'You can use these criteria to select windows/tabs for the other commands.'.format(appname=appname), + argspec='' ) def cmd_ls(global_opts, opts, args): pass @@ -54,6 +56,19 @@ def ls(boss, window): return data +@cmd( + 'Set the font size in all windows', + 'Sets the font size to the specified size, in pts.', + argspec='FONT_SIZE' +) +def cmd_set_font_size(global_opts, opts, args): + return {'size': float(args[0])} + + +def set_font_size(boss, window, payload): + boss.set_font_size(payload['size']) + + MATCH_WINDOW_OPTION = '''\ --match -m The window to match. Match specifications are of the form: