mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-17 14:04:52 +02:00
Deprecate the adjust_baseline adjust_line_height and adjust_column_width options in favor of modify_font
Unifies handling and allow using pt units for those adjustments. Note that the behavior of percentage sizes for adjust baseline is backwards incompatible. It now uses the baseline value as the base rather than the cell height.
This commit is contained in:
@@ -18,6 +18,7 @@ definition = Definition(
|
||||
definition.add_deprecation('deprecated_hide_window_decorations_aliases', 'x11_hide_window_decorations', 'macos_hide_titlebar')
|
||||
definition.add_deprecation('deprecated_macos_show_window_title_in_menubar_alias', 'macos_show_window_title_in_menubar')
|
||||
definition.add_deprecation('deprecated_send_text', 'send_text')
|
||||
definition.add_deprecation('deprecated_adjust_line_height', 'adjust_line_height', 'adjust_column_width', 'adjust_baseline')
|
||||
|
||||
agr = definition.add_group
|
||||
egr = definition.end_group
|
||||
@@ -80,34 +81,6 @@ terminals.
|
||||
'''
|
||||
)
|
||||
|
||||
opt('adjust_line_height', '0',
|
||||
option_type='adjust_line_height', ctype='!adjust_line_height',
|
||||
long_text='''
|
||||
Change the size of each character cell kitty renders. You can use either
|
||||
numbers, which are interpreted as pixels or percentages (number followed by %),
|
||||
which are interpreted as percentages of the unmodified values. You can use
|
||||
negative pixels or percentages less than 100% to reduce sizes (but this might
|
||||
cause rendering artifacts).
|
||||
'''
|
||||
)
|
||||
|
||||
opt('adjust_column_width', '0',
|
||||
option_type='adjust_line_height', ctype='!adjust_column_width',
|
||||
)
|
||||
|
||||
opt('adjust_baseline', '0',
|
||||
option_type='adjust_baseline', ctype='!adjust_baseline',
|
||||
add_to_default=False,
|
||||
long_text='''
|
||||
Adjust the vertical alignment of text (the height in the cell at which text is
|
||||
positioned). You can use either numbers, which are interpreted as pixels or
|
||||
percentages (number followed by %), which are interpreted as the percentage of
|
||||
the line height. A positive value moves the baseline up, and a negative value
|
||||
moves them down. The underline and strikethrough positions are adjusted
|
||||
accordingly.
|
||||
'''
|
||||
)
|
||||
|
||||
opt('+symbol_map', 'U+E0A0-U+E0A3,U+E0C0-U+E0C7 PowerlineSymbols',
|
||||
option_type='symbol_map',
|
||||
add_to_default=False,
|
||||
@@ -227,6 +200,17 @@ No suffix means use pts. For example::
|
||||
modify_font underline_position -2
|
||||
modify_font underline_thickness 150%
|
||||
modify_font strikethrough_position 2px
|
||||
|
||||
Additionally, you can modify the size of the cell in which each font glyph is rendered and the baseline
|
||||
at which the glyph is placed in the cell. For example::
|
||||
|
||||
modify_font cell_width 80%
|
||||
modify_font cell_height -2px
|
||||
modify_font baseline 3
|
||||
|
||||
Note that modifying the baseline will automatically adjust the underline and strikethrough positions
|
||||
by the same amount. Increasing the baseline raises glyphs inside the cell and decreasing it lowers them.
|
||||
Decreasing the cell size might cause rendering artifacts, so use with care.
|
||||
''')
|
||||
|
||||
opt('box_drawing_scale', '0.001, 1, 1.5, 2',
|
||||
|
||||
26
kitty/options/parse.py
generated
26
kitty/options/parse.py
generated
@@ -6,10 +6,10 @@ from kitty.conf.utils import (
|
||||
unit_float
|
||||
)
|
||||
from kitty.options.utils import (
|
||||
action_alias, active_tab_title_template, adjust_baseline, adjust_line_height, allow_hyperlinks,
|
||||
allow_remote_control, bell_on_tab, box_drawing_scale, clear_all_mouse_actions, clear_all_shortcuts,
|
||||
clipboard_control, clone_source_strategies, config_or_absolute_path, copy_on_select,
|
||||
cursor_text_color, deprecated_hide_window_decorations_aliases,
|
||||
action_alias, active_tab_title_template, allow_hyperlinks, allow_remote_control, bell_on_tab,
|
||||
box_drawing_scale, clear_all_mouse_actions, clear_all_shortcuts, clipboard_control,
|
||||
clone_source_strategies, config_or_absolute_path, copy_on_select, cursor_text_color,
|
||||
deprecated_adjust_line_height, deprecated_hide_window_decorations_aliases,
|
||||
deprecated_macos_show_window_title_in_menubar_alias, deprecated_send_text, disable_ligatures,
|
||||
edge_width, env, font_features, hide_window_decorations, macos_option_as_alt, macos_titlebar_color,
|
||||
modify_font, narrow_symbols, optional_edge_width, parse_map, parse_mouse_map, paste_actions,
|
||||
@@ -42,15 +42,6 @@ class Parser:
|
||||
def active_tab_title_template(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
||||
ans['active_tab_title_template'] = active_tab_title_template(val)
|
||||
|
||||
def adjust_baseline(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
||||
ans['adjust_baseline'] = adjust_baseline(val)
|
||||
|
||||
def adjust_column_width(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
||||
ans['adjust_column_width'] = adjust_line_height(val)
|
||||
|
||||
def adjust_line_height(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
||||
ans['adjust_line_height'] = adjust_line_height(val)
|
||||
|
||||
def allow_cloning(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
||||
val = val.lower()
|
||||
if val not in self.choices_for_allow_cloning:
|
||||
@@ -1352,6 +1343,15 @@ class Parser:
|
||||
def send_text(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
||||
deprecated_send_text('send_text', val, ans)
|
||||
|
||||
def adjust_line_height(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
||||
deprecated_adjust_line_height('adjust_line_height', val, ans)
|
||||
|
||||
def adjust_column_width(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
||||
deprecated_adjust_line_height('adjust_column_width', val, ans)
|
||||
|
||||
def adjust_baseline(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
||||
deprecated_adjust_line_height('adjust_baseline', val, ans)
|
||||
|
||||
def map(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
||||
for k in parse_map(val):
|
||||
ans['map'].append(k)
|
||||
|
||||
45
kitty/options/to-c-generated.h
generated
45
kitty/options/to-c-generated.h
generated
@@ -31,45 +31,6 @@ convert_from_opts_force_ltr(PyObject *py_opts, Options *opts) {
|
||||
Py_DECREF(ret);
|
||||
}
|
||||
|
||||
static void
|
||||
convert_from_python_adjust_line_height(PyObject *val, Options *opts) {
|
||||
adjust_line_height(val, opts);
|
||||
}
|
||||
|
||||
static void
|
||||
convert_from_opts_adjust_line_height(PyObject *py_opts, Options *opts) {
|
||||
PyObject *ret = PyObject_GetAttrString(py_opts, "adjust_line_height");
|
||||
if (ret == NULL) return;
|
||||
convert_from_python_adjust_line_height(ret, opts);
|
||||
Py_DECREF(ret);
|
||||
}
|
||||
|
||||
static void
|
||||
convert_from_python_adjust_column_width(PyObject *val, Options *opts) {
|
||||
adjust_column_width(val, opts);
|
||||
}
|
||||
|
||||
static void
|
||||
convert_from_opts_adjust_column_width(PyObject *py_opts, Options *opts) {
|
||||
PyObject *ret = PyObject_GetAttrString(py_opts, "adjust_column_width");
|
||||
if (ret == NULL) return;
|
||||
convert_from_python_adjust_column_width(ret, opts);
|
||||
Py_DECREF(ret);
|
||||
}
|
||||
|
||||
static void
|
||||
convert_from_python_adjust_baseline(PyObject *val, Options *opts) {
|
||||
adjust_baseline(val, opts);
|
||||
}
|
||||
|
||||
static void
|
||||
convert_from_opts_adjust_baseline(PyObject *py_opts, Options *opts) {
|
||||
PyObject *ret = PyObject_GetAttrString(py_opts, "adjust_baseline");
|
||||
if (ret == NULL) return;
|
||||
convert_from_python_adjust_baseline(ret, opts);
|
||||
Py_DECREF(ret);
|
||||
}
|
||||
|
||||
static void
|
||||
convert_from_python_disable_ligatures(PyObject *val, Options *opts) {
|
||||
opts->disable_ligatures = PyLong_AsLong(val);
|
||||
@@ -1051,12 +1012,6 @@ convert_opts_from_python_opts(PyObject *py_opts, Options *opts) {
|
||||
if (PyErr_Occurred()) return false;
|
||||
convert_from_opts_force_ltr(py_opts, opts);
|
||||
if (PyErr_Occurred()) return false;
|
||||
convert_from_opts_adjust_line_height(py_opts, opts);
|
||||
if (PyErr_Occurred()) return false;
|
||||
convert_from_opts_adjust_column_width(py_opts, opts);
|
||||
if (PyErr_Occurred()) return false;
|
||||
convert_from_opts_adjust_baseline(py_opts, opts);
|
||||
if (PyErr_Occurred()) return false;
|
||||
convert_from_opts_disable_ligatures(py_opts, opts);
|
||||
if (PyErr_Occurred()) return false;
|
||||
convert_from_opts_modify_font(py_opts, opts);
|
||||
|
||||
@@ -129,6 +129,7 @@ static void
|
||||
modify_font(PyObject *mf, Options *opts) {
|
||||
#define S(which) { PyObject *v = PyDict_GetItemString(mf, #which); if (v) parse_font_mod_size(v, &opts->which.val, &opts->which.unit); }
|
||||
S(underline_position); S(underline_thickness); S(strikethrough_thickness); S(strikethrough_position);
|
||||
S(cell_height); S(cell_width); S(baseline);
|
||||
#undef S
|
||||
}
|
||||
|
||||
@@ -224,21 +225,3 @@ tab_bar_margin_height(PyObject *val, Options *opts) {
|
||||
opts->tab_bar_margin_height.outer = PyFloat_AsDouble(PyTuple_GET_ITEM(val, 0));
|
||||
opts->tab_bar_margin_height.inner = PyFloat_AsDouble(PyTuple_GET_ITEM(val, 1));
|
||||
}
|
||||
|
||||
#define read_adjust(name) { \
|
||||
if (PyFloat_Check(al)) { \
|
||||
opts->name##_frac = (float)PyFloat_AsDouble(al); \
|
||||
opts->name##_px = 0; \
|
||||
} else { \
|
||||
opts->name##_frac = 0; \
|
||||
opts->name##_px = (int)PyLong_AsLong(al); \
|
||||
} \
|
||||
}
|
||||
|
||||
static void
|
||||
adjust_line_height(PyObject *al, Options *opts) { read_adjust(adjust_line_height); }
|
||||
static void
|
||||
adjust_column_width(PyObject *al, Options *opts) { read_adjust(adjust_column_width); }
|
||||
static void
|
||||
adjust_baseline(PyObject *al, Options *opts) { read_adjust(adjust_baseline); }
|
||||
#undef read_adjust
|
||||
|
||||
6
kitty/options/types.py
generated
6
kitty/options/types.py
generated
@@ -52,9 +52,6 @@ option_names = ( # {{{
|
||||
'active_tab_font_style',
|
||||
'active_tab_foreground',
|
||||
'active_tab_title_template',
|
||||
'adjust_baseline',
|
||||
'adjust_column_width',
|
||||
'adjust_line_height',
|
||||
'allow_cloning',
|
||||
'allow_hyperlinks',
|
||||
'allow_remote_control',
|
||||
@@ -467,9 +464,6 @@ class Options:
|
||||
active_tab_font_style: typing.Tuple[bool, bool] = (True, True)
|
||||
active_tab_foreground: Color = Color(0, 0, 0)
|
||||
active_tab_title_template: typing.Optional[str] = None
|
||||
adjust_baseline: typing.Union[int, float] = 0
|
||||
adjust_column_width: typing.Union[int, float] = 0
|
||||
adjust_line_height: typing.Union[int, float] = 0
|
||||
allow_cloning: choices_for_allow_cloning = 'ask'
|
||||
allow_hyperlinks: int = 1
|
||||
allow_remote_control: str = 'n'
|
||||
|
||||
@@ -449,26 +449,6 @@ def parse_shortcut(sc: str) -> SingleKey:
|
||||
return SingleKey(mods, is_native, key or 0)
|
||||
|
||||
|
||||
def adjust_line_height(x: str) -> Union[int, float]:
|
||||
if x.endswith('%'):
|
||||
ans = float(x[:-1].strip()) / 100.0
|
||||
if ans < 0:
|
||||
log_error('Percentage adjustments of cell sizes must be positive numbers')
|
||||
return 0
|
||||
return ans
|
||||
return int(x)
|
||||
|
||||
|
||||
def adjust_baseline(x: str) -> Union[int, float]:
|
||||
if x.endswith('%'):
|
||||
ans = float(x[:-1].strip()) / 100.0
|
||||
if abs(ans) > 1:
|
||||
log_error('Percentage adjustments of the baseline cannot exceed 100%')
|
||||
return 0
|
||||
return ans
|
||||
return int(x)
|
||||
|
||||
|
||||
def to_font_size(x: str) -> float:
|
||||
return max(MINIMUM_FONT_SIZE, float(x))
|
||||
|
||||
@@ -1203,3 +1183,16 @@ def deprecated_send_text(key: str, val: str, ans: Dict[str, Any]) -> None:
|
||||
key_str = f'{sc} send_text {mode} {text}'
|
||||
for k in parse_map(key_str):
|
||||
ans['map'].append(k)
|
||||
|
||||
|
||||
def deprecated_adjust_line_height(key: str, x: str, opts_dict: Dict[str, Any]) -> None:
|
||||
fm = {'adjust_line_height': 'cell_height', 'adjust_baseline': 'baseline', 'adjust_column_width': 'cell_width'}[key]
|
||||
mtype = getattr(ModificationType, fm)
|
||||
if x.endswith('%'):
|
||||
ans = float(x[:-1].strip())
|
||||
if ans < 0:
|
||||
log_error(f'Percentage adjustments of {key} must be positive numbers')
|
||||
return
|
||||
opts_dict['modify_font'][fm] = FontModification(mtype, ModificationValue(ans, ModificationUnit.percent))
|
||||
else:
|
||||
opts_dict['modify_font'][fm] = FontModification(mtype, ModificationValue(int(x), ModificationUnit.pixel))
|
||||
|
||||
Reference in New Issue
Block a user