From 6a53897c179ef8a3b0384eb6592fbea99fe4b0e3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 9 May 2025 07:39:06 +0530 Subject: [PATCH] change_font_size: allow multiplying/dividing the current font size in addition to incrementing it Fixes #8616 --- docs/changelog.rst | 2 ++ kitty/boss.py | 12 +++++++++++- kitty/options/definition.py | 5 +++++ kitty/options/utils.py | 2 +- kitty/rc/set_font_size.py | 4 ++-- tools/cmd/at/set_font_size.go | 3 ++- 6 files changed, 23 insertions(+), 5 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index a8480a5ba..48331405d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -158,6 +158,8 @@ Detailed list of changes - Launch action: Allow using an env var that resolves to a full command-line as the program to launch (:pull:`8613`) +- :ac:`change_font_size` allow multiplying/dividing the current font size in addition to incrementing it (:iss:`8616`) + 0.41.1 [2025-04-03] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/boss.py b/kitty/boss.py index ef0b482df..250072e1a 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -1358,7 +1358,17 @@ class Boss: new_size = get_options().font_size else: if increment_operation: - new_size += (1 if increment_operation == '+' else -1) * amt + match increment_operation: + case '+': + new_size += amt + case '-': + new_size -= amt + case '*': + new_size *= amt + case '/': + new_size /= amt + case _: + pass # no-op else: new_size = amt new_size = max(MINIMUM_FONT_SIZE, min(new_size, get_options().font_size * 5)) diff --git a/kitty/options/definition.py b/kitty/options/definition.py index fd8d26ff2..585d39425 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -4182,6 +4182,11 @@ To setup shortcuts for specific font sizes:: To setup shortcuts to change only the current OS window's font size:: map kitty_mod+f6 change_font_size current 10.0 + +To setup shortcuts to multiply/divide the font size: + + map kitty_mod+f6 change_font_size all *2.0 + map kitty_mod+f6 change_font_size all /2.0 ''') # }}} diff --git a/kitty/options/utils.py b/kitty/options/utils.py index d9616480b..c674d1686 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -199,7 +199,7 @@ def parse_change_font_size(func: str, rest: str) -> tuple[str, tuple[bool, str | c_all = vals[0].lower() == 'all' sign: str | None = None amt = vals[1] - if amt[0] in '+-': + if amt[0] in '+-*/': sign = amt[0] amt = amt[1:] return func, (c_all, sign, float(amt.strip())) diff --git a/kitty/rc/set_font_size.py b/kitty/rc/set_font_size.py index f92a52ad1..2ac95808f 100644 --- a/kitty/rc/set_font_size.py +++ b/kitty/rc/set_font_size.py @@ -13,7 +13,7 @@ class SetFontSize(RemoteCommand): protocol_spec = __doc__ = ''' size+/float: The new font size in pts (a positive number). If absent is assumed to be zero which means reset to default. all/bool: Boolean whether to change font size in the current window or all windows - increment_op/choices.+.-: The string ``+`` or ``-`` to interpret size as an increment + increment_op/choices.+.-.*./: The string ``+``, ``-``, ``*`` or ``/`` to interpret size as an increment ''' short_desc = 'Set the font size in the active top-level OS window' @@ -22,7 +22,7 @@ class SetFontSize(RemoteCommand): ' that in kitty all sub-windows in the same OS window' ' must have the same font size. A value of zero' ' resets the font size to default. Prefixing the value' - ' with a :code:`+` or :code:`-` increments the font size by the specified' + ' with a :code:`+`, :code:`-`, :code:`*` or :code:`/` changes the font size by the specified' ' amount. Use -- before using - to have it not mistaken for a option. For example:' ' kitten @ set-font-size -- -2' ) diff --git a/tools/cmd/at/set_font_size.go b/tools/cmd/at/set_font_size.go index a307dc80f..16875c1ce 100644 --- a/tools/cmd/at/set_font_size.go +++ b/tools/cmd/at/set_font_size.go @@ -3,11 +3,12 @@ package at import ( + "bytes" "strconv" ) func parse_set_font_size(arg string, payload *set_font_size_json_type) error { - if len(arg) > 0 && (arg[0] == '+' || arg[0] == '-') { + if len(arg) > 0 && (bytes.IndexByte([]byte{'+', '-', '/', '*'}, arg[0]) > -1) { payload.Increment_op = arg[:1] arg = arg[1:] }