mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-18 14:18:16 +00:00
Allow narrower vertical tab bars
When tab_title_max_length is set, size the vertical tab bar to fit the decorations drawn by the current tab_bar_style instead of always adding eight cells. Also allow powerline tabs in vertical tab bars to show a title in a narrow tab bar, since the separator has a column of its own. Fixes #10680
This commit is contained in:
parent
277ff7f1e1
commit
bea239edb1
6 changed files with 71 additions and 8 deletions
|
|
@ -265,6 +265,10 @@ Detailed list of changes
|
|||
status bars, file trees, etc. Create them with :code:`launch --type=window-dock`
|
||||
or :code:`launch --type=tab-dock`, see :ref:`docks`
|
||||
|
||||
- Vertical tab bars: When :opt:`tab_title_max_length` is set, size the tab bar
|
||||
to fit the decorations of the current :opt:`tab_bar_style` rather than always
|
||||
adding eight cells, allowing much narrower tab bars (:iss:`10680`)
|
||||
|
||||
|
||||
- quick-access-terminal kitten: A new :option:`kitty +kitten quick_access_terminal --if-running`
|
||||
option to run a program in a new tab or window of an already running quick
|
||||
|
|
|
|||
|
|
@ -2364,7 +2364,10 @@ opt(
|
|||
The maximum number of cells that can be used to render the text in a tab.
|
||||
A value of zero means that no limit is applied. For vertical tab bars, kitty
|
||||
uses a default sidebar width sized for about twenty title cells when this is
|
||||
left unset.
|
||||
left unset. When it is set, the sidebar is made just wide enough to fit titles
|
||||
of this length along with the decorations drawn by :opt:`tab_bar_style`. With
|
||||
the :code:`fade` style, use fewer values in :opt:`tab_fade` for a narrower
|
||||
sidebar.
|
||||
""",
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -763,8 +763,11 @@ vertical_tab_bar_cols(const OSWindow *os_window, long margin_outer, long margin_
|
|||
long available_width = (long)os_window->viewport_width - margin_outer - margin_inner;
|
||||
if (available_width <= 0) return 0;
|
||||
unsigned available_cols = MAX(1u, (unsigned)available_width / cell_width);
|
||||
unsigned title_cols = OPT(tab_title_max_length) > 0 ? (unsigned)OPT(tab_title_max_length) : 20u;
|
||||
unsigned desired_cols = title_cols + 8u;
|
||||
// Without an explicit title length use a default sidebar wide enough for
|
||||
// about twenty title cells, otherwise fit the title and whatever
|
||||
// decorations the tab bar style draws around it.
|
||||
unsigned desired_cols = 28u;
|
||||
if (OPT(tab_title_max_length) > 0) desired_cols = MAX((unsigned)OPT(tab_title_max_length) + OPT(vertical_tab_bar.padding), OPT(vertical_tab_bar.min_cols));
|
||||
unsigned soft_max = available_cols / 3u;
|
||||
if (soft_max < 6u) soft_max = available_cols;
|
||||
return MAX(1u, MIN(available_cols, MIN(desired_cols, MAX(1u, soft_max))));
|
||||
|
|
@ -1088,6 +1091,45 @@ PYWRAP0(get_options) {
|
|||
return global_state.options_object;
|
||||
}
|
||||
|
||||
static bool
|
||||
set_vertical_tab_bar_padding(PyObject *py_opts, Options *opts) {
|
||||
// The number of cells each tab bar style draws around the title in a
|
||||
// vertical tab bar, see the draw_tab_with_* functions in tab_bar.py.
|
||||
// Custom styles can draw anything, so give them generous room.
|
||||
opts->vertical_tab_bar.padding = 8;
|
||||
opts->vertical_tab_bar.min_cols = 1;
|
||||
RAII_PyObject(style, PyObject_GetAttrString(py_opts, "tab_bar_style"));
|
||||
if (!style) return false;
|
||||
if (PyUnicode_CompareWithASCIIString(style, "fade") == 0) {
|
||||
RAII_PyObject(fade, PyObject_GetAttrString(py_opts, "tab_fade"));
|
||||
if (!fade) return false;
|
||||
Py_ssize_t n = PyObject_Length(fade);
|
||||
if (n < 0) return false;
|
||||
// Fade cells on both sides of the title, the trailing ones are only
|
||||
// drawn when they end before the last column
|
||||
opts->vertical_tab_bar.padding = 2 * (unsigned)n + (n < 2 ? 1 : 0);
|
||||
} else if (PyUnicode_CompareWithASCIIString(style, "powerline") == 0) {
|
||||
// Leading space, trailing space and the separator
|
||||
opts->vertical_tab_bar.padding = 3;
|
||||
} else if (PyUnicode_CompareWithASCIIString(style, "slant") == 0) {
|
||||
// Separators and spaces on both sides of the title, tabs narrower
|
||||
// than six cells show only an ellipsis
|
||||
opts->vertical_tab_bar.padding = 4;
|
||||
opts->vertical_tab_bar.min_cols = 6;
|
||||
} else if (PyUnicode_CompareWithASCIIString(style, "separator") == 0) {
|
||||
// The spaces in tab_separator, plus the column reserved at the end
|
||||
RAII_PyObject(sep, PyObject_GetAttrString(py_opts, "tab_separator"));
|
||||
if (!sep) return false;
|
||||
Py_ssize_t len = PyUnicode_GetLength(sep);
|
||||
if (len < 0) return false;
|
||||
unsigned spaces = 0;
|
||||
for (Py_ssize_t i = 0; i < len && PyUnicode_READ_CHAR(sep, i) == ' '; i++) spaces++;
|
||||
for (Py_ssize_t i = len - 1; i >= (Py_ssize_t)spaces && PyUnicode_READ_CHAR(sep, i) == ' '; i--) spaces++;
|
||||
opts->vertical_tab_bar.padding = spaces + 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
PYWRAP1(set_options) {
|
||||
PyObject *opts;
|
||||
int is_wayland = 0, debug_rendering = 0, debug_font_fallback = 0;
|
||||
|
|
@ -1106,6 +1148,7 @@ PYWRAP1(set_options) {
|
|||
global_state.debug_font_fallback = debug_font_fallback ? true : false;
|
||||
if (!convert_opts_from_python_opts(opts, &global_state.opts)) return NULL;
|
||||
if (!set_wheel_mappings(opts, &global_state.opts)) return NULL;
|
||||
if (!set_vertical_tab_bar_padding(opts, &global_state.opts)) return NULL;
|
||||
push_modifier_remap_to_glfw();
|
||||
Py_XDECREF(global_state.options_object);
|
||||
global_state.options_object = Py_NewRef(opts);
|
||||
|
|
|
|||
|
|
@ -155,6 +155,9 @@ typedef struct Options {
|
|||
size_t count;
|
||||
} detect_url_regex;
|
||||
bool tab_bar_hidden;
|
||||
struct {
|
||||
unsigned padding, min_cols;
|
||||
} vertical_tab_bar;
|
||||
double font_size;
|
||||
struct {
|
||||
double outer, inner;
|
||||
|
|
|
|||
|
|
@ -655,9 +655,11 @@ def draw_tab_with_powerline(
|
|||
needs_soft_separator = False
|
||||
|
||||
separator_symbol, soft_separator_symbol = powerline_symbols.get(draw_data.powerline_style, ('', ''))
|
||||
min_title_length = 1 + 2
|
||||
start_draw = 2
|
||||
is_vertical = draw_data.tab_bar_edge in ('left', 'right')
|
||||
# Vertical tabs draw their separator in a column of its own, so they need
|
||||
# room only for the leading space and a single character of the title.
|
||||
min_title_length = 1 if is_vertical else 1 + 2
|
||||
start_draw = 2
|
||||
first_row = screen.cursor.y
|
||||
|
||||
if screen.cursor.x == 0:
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ class TestTabBar(BaseTest):
|
|||
self.ae(tb.tab_id_at(5, 110), 1)
|
||||
self.ae(tb.tab_id_at(5, 150), 2)
|
||||
|
||||
def vertical_tab_bar(self, num_tabs: int = 2, height: int = 160, **opts: object) -> TabBar:
|
||||
def vertical_tab_bar(self, num_tabs: int = 2, height: int = 160, width: int = 120, **opts: object) -> TabBar:
|
||||
self.set_options(
|
||||
{
|
||||
'tab_bar_edge': LEFT_EDGE,
|
||||
|
|
@ -204,8 +204,8 @@ class TestTabBar(BaseTest):
|
|||
**opts,
|
||||
}
|
||||
)
|
||||
central = region(120, 0, 400, height)
|
||||
tab_bar = region(0, 0, 120, height)
|
||||
central = region(width, 0, 400, height)
|
||||
tab_bar = region(0, 0, width, height)
|
||||
with (
|
||||
patch('kitty.tab_bar.cell_size_for_window', return_value=(10, 20)),
|
||||
patch('kitty.tab_bar.viewport_for_window', return_value=(central, tab_bar, 400, height, 10, 20)),
|
||||
|
|
@ -221,6 +221,14 @@ class TestTabBar(BaseTest):
|
|||
s = tb.screen
|
||||
return [str(s.line(i)).rstrip() for i in range(s.lines)]
|
||||
|
||||
def test_vertical_tab_bar_narrow_powerline(self) -> None:
|
||||
# A short title fits in a narrow vertical tab bar, since the separator
|
||||
# is drawn in a column of its own
|
||||
sep = powerline_symbols['round'][0]
|
||||
tb = self.vertical_tab_bar(width=40, tab_bar_style='powerline', tab_powerline_style='round', tab_title_template='{index}', tab_title_max_length=1)
|
||||
self.ae(tb.screen.columns, 4)
|
||||
self.ae(self.screen_lines(tb)[:3], [f' 1 {sep}', '', f' 2 {sep}'])
|
||||
|
||||
def test_vertical_tab_bar_multiline_titles(self) -> None:
|
||||
# newlines are ignored unless tab_title_max_lines allows them, and the
|
||||
# dropped lines are marked with an ellipsis
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue