mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-15 04:57:52 +02:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be5185ab1a | ||
|
|
01c289e440 | ||
|
|
db2d14d9ed | ||
|
|
c504b96b60 | ||
|
|
15c4b1961e | ||
|
|
2cc20e4b27 |
@@ -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()
|
||||
|
||||
@@ -19,10 +19,30 @@ def write(x):
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def set_title(*args):
|
||||
pass
|
||||
|
||||
|
||||
def set_icon(*args):
|
||||
pass
|
||||
|
||||
|
||||
def screen_bell():
|
||||
pass
|
||||
|
||||
|
||||
def screen_cursor_position(y, x):
|
||||
write(CSI + '%s;%sH' % (y, x))
|
||||
|
||||
|
||||
def screen_cursor_forward(amt):
|
||||
write(CSI + '%sC' % amt)
|
||||
|
||||
|
||||
def screen_cursor_back1(amt):
|
||||
write(CSI + '%sD' % amt)
|
||||
|
||||
|
||||
def screen_designate_charset(which, to):
|
||||
which = '()'[int(which)]
|
||||
to = chr(int(to))
|
||||
@@ -57,6 +77,10 @@ def screen_erase_in_display(how, private):
|
||||
write(CSI + ('?' if private else '') + str(how) + 'J')
|
||||
|
||||
|
||||
def screen_erase_in_line(how, private):
|
||||
write(CSI + ('?' if private else '') + str(how) + 'K')
|
||||
|
||||
|
||||
def screen_cursor_up2(count):
|
||||
write(CSI + '%dA' % count)
|
||||
|
||||
@@ -65,6 +89,10 @@ def screen_carriage_return():
|
||||
write('\r')
|
||||
|
||||
|
||||
def screen_linefeed():
|
||||
write('\n')
|
||||
|
||||
|
||||
def screen_backspace():
|
||||
write('\x08')
|
||||
|
||||
@@ -77,8 +105,8 @@ def replay(raw):
|
||||
for line in raw.splitlines():
|
||||
if line.strip():
|
||||
cmd, rest = line.partition(' ')[::2]
|
||||
if cmd == 'draw':
|
||||
draw(rest)
|
||||
if cmd in {'draw', 'set_title', 'set_icon'}:
|
||||
globals()[cmd](rest)
|
||||
else:
|
||||
rest = map(int, rest.split()) if rest else ()
|
||||
globals()[cmd](*rest)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -15,7 +15,7 @@ from .fast_data_types import (
|
||||
GLFW_KEY_LEFT_SUPER, GLFW_KEY_RIGHT_SUPER)
|
||||
|
||||
appname = 'kitty'
|
||||
version = (0, 2, 1)
|
||||
version = (0, 2, 2)
|
||||
str_version = '.'.join(map(str, version))
|
||||
_plat = sys.platform.lower()
|
||||
isosx = 'darwin' in _plat
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -98,6 +98,11 @@ def option_parser():
|
||||
default=None,
|
||||
help=_('Replay previously dumped commands')
|
||||
)
|
||||
a(
|
||||
'--dump-bytes',
|
||||
help=_('Path to file in which to store the raw bytes received from the'
|
||||
' child process. Useful for debugging.')
|
||||
)
|
||||
a(
|
||||
'--debug-gl',
|
||||
action='store_true',
|
||||
|
||||
@@ -519,16 +519,16 @@ accumulate_osc(Screen *screen, uint32_t ch, PyObject DUMP_UNUSED *dump_callback)
|
||||
switch(ch) {
|
||||
case ST:
|
||||
return true;
|
||||
case ESC_ST:
|
||||
if (screen->parser_buf_pos > 0 && screen->parser_buf[screen->parser_buf_pos - 1] == ESC) {
|
||||
screen->parser_buf_pos--;
|
||||
return true;
|
||||
}
|
||||
case BEL:
|
||||
return true;
|
||||
case NUL:
|
||||
case DEL:
|
||||
break;
|
||||
case ESC_ST:
|
||||
if (screen->parser_buf_pos > 0 && screen->parser_buf[screen->parser_buf_pos - 1] == ESC) {
|
||||
screen->parser_buf_pos--;
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
if (screen->parser_buf_pos >= PARSER_BUF_SZ - 1) {
|
||||
REPORT_ERROR("OSC sequence too long, truncating.");
|
||||
@@ -753,6 +753,11 @@ FNAME(read_bytes)(PyObject UNUSED *self, PyObject *args) {
|
||||
/* PyObject_Print(Py_BuildValue("y#", screen->read_buf, len), stderr, 0); */
|
||||
break;
|
||||
}
|
||||
#ifdef DUMP_COMMANDS
|
||||
if (len > 0) {
|
||||
Py_XDECREF(PyObject_CallFunction(dump_callback, "sy#", "bytes", screen->read_buf, len)); PyErr_Clear();
|
||||
}
|
||||
#endif
|
||||
_parse_bytes(screen, screen->read_buf, len, dump_callback);
|
||||
if(len > 0) { Py_RETURN_TRUE; }
|
||||
Py_RETURN_FALSE;
|
||||
|
||||
@@ -39,7 +39,9 @@ class Window:
|
||||
self.child_fd = child.child_fd
|
||||
self.start_visual_bell_at = None
|
||||
self.screen = Screen(self, 24, 80, opts.scrollback_lines)
|
||||
self.read_bytes = partial(read_bytes_dump, self.dump_commands) if args.dump_commands else read_bytes
|
||||
self.read_bytes = partial(read_bytes_dump, self.dump_commands) if args.dump_commands or args.dump_bytes else read_bytes
|
||||
if args.dump_bytes:
|
||||
self.dump_bytes_to = open(args.dump_bytes, 'ab')
|
||||
self.draw_dump_buf = []
|
||||
self.write_buf = memoryview(b'')
|
||||
self.char_grid = CharGrid(self.screen, opts)
|
||||
@@ -347,6 +349,9 @@ class Window:
|
||||
self.draw_dump_buf = []
|
||||
else:
|
||||
self.draw_dump_buf.append(a[1])
|
||||
elif a[0] == 'bytes':
|
||||
self.dump_bytes_to.write(a[1])
|
||||
self.dump_bytes_to.flush()
|
||||
else:
|
||||
if self.draw_dump_buf:
|
||||
safe_print('draw', ''.join(self.draw_dump_buf))
|
||||
|
||||
@@ -156,9 +156,9 @@ class TestParser(BaseTest):
|
||||
s = self.create_screen()
|
||||
pb = partial(self.parse_bytes_dump, s)
|
||||
c = s.callbacks
|
||||
pb('a\033]2;xyz\x9cbcde', 'a', ('set_title', 'xyz'), 'bcde')
|
||||
pb('a\033]2;x\\ryz\x9cbcde', 'a', ('set_title', 'x\\ryz'), 'bcde')
|
||||
self.ae(str(s.line(0)), 'abcde')
|
||||
self.ae(c.titlebuf, 'xyz')
|
||||
self.ae(c.titlebuf, 'x\\ryz')
|
||||
c.clear()
|
||||
pb('\033]\x07', ('set_title', ''), ('set_icon', ''))
|
||||
self.ae(c.titlebuf, ''), self.ae(c.iconbuf, '')
|
||||
@@ -181,4 +181,4 @@ class TestParser(BaseTest):
|
||||
pb = partial(self.parse_bytes_dump, s)
|
||||
for prefix in '\033_', '\033^', '\u009e', '\u009f':
|
||||
for suffix in '\u009c', '\033\\':
|
||||
pb('a{}+++{}bcde'.format(prefix, suffix), 'abcde')
|
||||
pb('a{}+\\++{}bcde'.format(prefix, suffix), 'abcde')
|
||||
|
||||
Reference in New Issue
Block a user