From 863fff86201aaa2a032ce69e8370d7ae5ac02c49 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 24 Feb 2021 12:32:26 +0530 Subject: [PATCH] Cleanup previous PR --- docs/changelog.rst | 3 +++ kitty/tab_bar.py | 27 +++++++++++++-------------- kitty/typing.py | 1 + kitty/typing.pyi | 1 + 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 3adf9b461..3c8aa2b02 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -22,6 +22,9 @@ To update |kitty|, :doc:`follow the instructions `. - Allow setting colors when creating windows using the :doc:`launch ` command. +- A new option :opt:`tab_powerline_style` to control the appearance of the tab + bar when using the powerline tab bar style. + - diff kitten: Implement recursive diff over SSH (:iss:`3268`) - ssh kitten: Allow using python instead of the shell on the server, useful if diff --git a/kitty/tab_bar.py b/kitty/tab_bar.py index 949bcbfd1..50b847169 100644 --- a/kitty/tab_bar.py +++ b/kitty/tab_bar.py @@ -6,7 +6,6 @@ from functools import lru_cache from typing import Any, Dict, NamedTuple, Optional, Sequence, Tuple from .config import build_ansi_color_table -from .types import WindowGeometry from .fast_data_types import ( DECAWM, Screen, cell_size_for_window, pt_to_px, set_tab_bar_render_data, viewport_for_window @@ -14,6 +13,8 @@ from .fast_data_types import ( from .layout.base import Rect from .options_stub import Options from .rgb import Color, alpha_blend, color_as_sgr, color_from_int, to_color +from .types import WindowGeometry +from .typing import PowerlineStyle from .utils import color_as_int, log_error from .window import calculate_gl_geometry @@ -42,7 +43,7 @@ class DrawData(NamedTuple): title_template: str active_title_template: Optional[str] tab_activity_symbol: Optional[str] - powerline_style: str + powerline_style: PowerlineStyle def as_rgb(x: int) -> int: @@ -181,28 +182,26 @@ def draw_tab_with_fade(draw_data: DrawData, screen: Screen, tab: TabBarData, bef return end +powerline_symbols: Dict[PowerlineStyle, Tuple[str, str]] = { + 'slanted': ('', '╱'), + 'round': ('', '') +} + + def draw_tab_with_powerline(draw_data: DrawData, screen: Screen, tab: TabBarData, before: int, max_title_length: int, index: int, is_last: bool) -> int: tab_bg = as_rgb(color_as_int(draw_data.active_bg if tab.is_active else draw_data.inactive_bg)) tab_fg = as_rgb(color_as_int(draw_data.active_fg if tab.is_active else draw_data.inactive_fg)) inactive_bg = as_rgb(color_as_int(draw_data.inactive_bg)) default_bg = as_rgb(color_as_int(draw_data.default_bg)) - separator_symbol = '' - separator_alt_symbol = '' - if draw_data.powerline_style == 'slanted': - separator_symbol = '' - separator_alt_symbol = '╱' - elif draw_data.powerline_style == 'round': - separator_symbol = '' - separator_alt_symbol = '' - + separator_symbol, separator_alt_symbol = powerline_symbols.get(draw_data.powerline_style, ('', '')) min_title_length = 1 + 2 if screen.cursor.x + min_title_length >= screen.columns: screen.cursor.x -= 2 screen.cursor.bg = default_bg screen.cursor.fg = inactive_bg - screen.draw('{} '.format(separator_symbol)) + screen.draw(f'{separator_symbol} ') return screen.cursor.x start_draw = 2 @@ -210,7 +209,7 @@ def draw_tab_with_powerline(draw_data: DrawData, screen: Screen, tab: TabBarData screen.cursor.x -= 2 screen.cursor.fg = inactive_bg screen.cursor.bg = tab_bg - screen.draw('{} '.format(separator_symbol)) + screen.draw(f'{separator_symbol} ') screen.cursor.fg = tab_fg elif screen.cursor.x == 0: screen.cursor.bg = tab_bg @@ -236,7 +235,7 @@ def draw_tab_with_powerline(draw_data: DrawData, screen: Screen, tab: TabBarData screen.cursor.bg = inactive_bg screen.draw(separator_symbol) else: - screen.draw(' {}'.format(separator_alt_symbol)) + screen.draw(f' {separator_alt_symbol}') end = screen.cursor.x if end < screen.columns: diff --git a/kitty/typing.py b/kitty/typing.py index 0b3eb2e4b..f0f235fcc 100644 --- a/kitty/typing.py +++ b/kitty/typing.py @@ -18,5 +18,6 @@ TermManagerType = LoopType = Debug = GraphicsCommandType = None CompletedProcess = Tuple TypedDict = dict EdgeLiteral = str +PowerlineStyle = str MatchType = str Protocol = object diff --git a/kitty/typing.pyi b/kitty/typing.pyi index 379c8aa16..08e4b1fba 100644 --- a/kitty/typing.pyi +++ b/kitty/typing.pyi @@ -56,3 +56,4 @@ __all__ = ( 'FontConfigPattern', 'ScreenType', 'StartupCtx', 'KeyEventType', 'LayoutType', 'RemoteCommandType', 'SessionType', 'SessionTab', 'SpecialWindowInstance', 'TabType', 'ScreenSize', 'WindowType' ) +PowerlineStyle = Literal['angled', 'slanted', 'round']