mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-05-13 16:37:27 +00:00
Allow changing font size in a running terminal using keyboard shortcuts.
Fixes #57
This commit is contained in:
parent
0923d6ecee
commit
2cc20e4b27
5 changed files with 41 additions and 6 deletions
|
|
@ -14,6 +14,7 @@ from time import monotonic
|
|||
from queue import Queue, Empty
|
||||
from gettext import gettext as _
|
||||
|
||||
from .config import MINIMUM_FONT_SIZE
|
||||
from .constants import (
|
||||
viewport_size, set_boss, wakeup, cell_size, MODIFIER_KEYS,
|
||||
main_thread, mouse_button_pressed, mouse_cursor_pos
|
||||
|
|
@ -86,6 +87,7 @@ class Boss(Thread):
|
|||
self.pending_ui_thread_calls = Queue()
|
||||
self.write_dispatch_map = {}
|
||||
set_boss(self)
|
||||
self.current_font_size = opts.font_size
|
||||
cell_size.width, cell_size.height = set_font_family(opts)
|
||||
self.opts, self.args = opts, args
|
||||
self.glfw_window = glfw_window
|
||||
|
|
@ -228,6 +230,28 @@ class Boss(Thread):
|
|||
self.pending_resize = False
|
||||
glfw_post_empty_event()
|
||||
|
||||
def increase_font_size(self):
|
||||
self.change_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))
|
||||
|
||||
def restore_font_size(self):
|
||||
self.change_font_size(self.opts.font_size)
|
||||
|
||||
def change_font_size(self, new_size):
|
||||
if new_size == self.current_font_size:
|
||||
return
|
||||
self.current_font_size = new_size
|
||||
cell_size.width, cell_size.height = set_font_family(
|
||||
self.opts, override_font_size=self.current_font_size)
|
||||
self.sprites.do_layout(cell_size.width, cell_size.height)
|
||||
self.queue_action(self.resize_windows_after_font_size_change)
|
||||
|
||||
def resize_windows_after_font_size_change(self):
|
||||
self.tab_manager.resize()
|
||||
glfw_post_empty_event()
|
||||
|
||||
def tabbar_visibility_changed(self):
|
||||
self.tab_manager.resize(only_tabs=True)
|
||||
glfw_post_empty_event()
|
||||
|
|
|
|||
|
|
@ -17,10 +17,11 @@ from .layout import all_layouts
|
|||
from .utils import safe_print, to_color
|
||||
|
||||
key_pat = re.compile(r'([a-zA-Z][a-zA-Z0-9_-]*)\s+(.+)$')
|
||||
MINIMUM_FONT_SIZE = 6
|
||||
|
||||
|
||||
def to_font_size(x):
|
||||
return max(6, float(x))
|
||||
return max(MINIMUM_FONT_SIZE, float(x))
|
||||
|
||||
|
||||
cshapes = {
|
||||
|
|
@ -153,6 +154,7 @@ type_map = {
|
|||
'scrollback_pager': shlex.split,
|
||||
'scrollback_in_new_tab': to_bool,
|
||||
'font_size': to_font_size,
|
||||
'font_size_delta': float,
|
||||
'cursor_shape': to_cursor_shape,
|
||||
'cursor_opacity': to_opacity,
|
||||
'open_url_modifiers': to_open_url_modifiers,
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ def install_symbol_map(val, font_size, dpi):
|
|||
symbol_map[ch] = family_map[family]
|
||||
|
||||
|
||||
def set_font_family(opts, ignore_dpi_failure=False):
|
||||
def set_font_family(opts, override_font_size=None, ignore_dpi_failure=False):
|
||||
global cell_width, cell_height, baseline, CellTexture, WideCellTexture, underline_thickness, underline_position
|
||||
try:
|
||||
dpi = get_logical_dpi()
|
||||
|
|
@ -37,11 +37,12 @@ def set_font_family(opts, ignore_dpi_failure=False):
|
|||
if ans == 'auto' and (bold or italic):
|
||||
ans = get_family(False, False)
|
||||
return ans
|
||||
font_size = override_font_size or opts.font_size
|
||||
|
||||
for bold in (False, True):
|
||||
for italic in (False, True):
|
||||
main_font[(bold, italic)] = Face(get_family(bold, italic), bold, italic, True, opts.font_size, dpi)
|
||||
install_symbol_map(opts.symbol_map, opts.font_size, dpi)
|
||||
main_font[(bold, italic)] = Face(get_family(bold, italic), bold, italic, True, font_size, dpi)
|
||||
install_symbol_map(opts.symbol_map, font_size, dpi)
|
||||
mf = main_font[(False, False)]
|
||||
cell_width, cell_height = mf.cell_size()
|
||||
CellTexture = ctypes.c_ubyte * (cell_width * cell_height)
|
||||
|
|
|
|||
|
|
@ -71,10 +71,10 @@ def font_units_to_pixels(x, units_per_em, size_in_pts, dpi):
|
|||
return ceil_int(x * ((size_in_pts * dpi) / (72 * units_per_em)))
|
||||
|
||||
|
||||
def set_font_family(opts):
|
||||
def set_font_family(opts, override_font_size=None):
|
||||
global current_font_family, current_font_family_name, cff_size, cell_width, cell_height, CharTexture, baseline
|
||||
global underline_position, underline_thickness
|
||||
size_in_pts = opts.font_size
|
||||
size_in_pts = override_font_size or opts.font_size
|
||||
current_font_family = get_font_files(opts)
|
||||
current_font_family_name = opts.font_family
|
||||
dpi = get_logical_dpi()
|
||||
|
|
|
|||
|
|
@ -15,6 +15,10 @@ bold_italic_font auto
|
|||
# Font size (in pts)
|
||||
font_size 11.0
|
||||
|
||||
# The amount the font size is changed by (in pts) when increasing/decreasing
|
||||
# the font size in a running terminal.
|
||||
font_size_delta 2
|
||||
|
||||
# The foreground color
|
||||
foreground #dddddd
|
||||
|
||||
|
|
@ -215,6 +219,10 @@ map ctrl+shift+l next_layout
|
|||
map ctrl+shift+. move_tab_forward
|
||||
map ctrl+shift+, move_tab_backward
|
||||
|
||||
# Miscellaneous
|
||||
map ctrl+shift+equal increase_font_size
|
||||
map ctrl+shift+minus decrease_font_size
|
||||
map ctrl+shift+backspace restore_font_size
|
||||
|
||||
# Symbol mapping (special font for specified unicode code points). Map the
|
||||
# specified unicode codepoints to a particular font. Useful if you need special
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue