#!/usr/bin/env python # License: GPL v3 Copyright: 2018, Kovid Goyal import os import re from collections.abc import Callable, Sequence from functools import lru_cache, partial, wraps from string import Formatter as StringFormatter from typing import ( Any, NamedTuple, ) from .borders import Border, BorderColor from .constants import config_dir from .fast_data_types import ( BOTTOM_EDGE, DECAWM, Color, Region, Screen, cell_size_for_window, get_boss, get_options, pt_to_px, set_tab_bar_render_data, update_tab_bar_edge_colors, viewport_for_window, wcswidth, ) from .progress import ProgressState from .rgb import alpha_blend, color_as_sgr, color_from_int, to_color from .types import WindowGeometry, run_once from .typing_compat import EdgeLiteral, PowerlineStyle from .utils import color_as_int, log_error, sgr_sanitizer_pat class TabBarData(NamedTuple): title: str is_active: bool needs_attention: bool tab_id: int num_windows: int num_window_groups: int layout_name: str has_activity_since_last_focus: bool active_fg: int | None active_bg: int | None inactive_fg: int | None inactive_bg: int | None num_of_windows_with_progress: int total_progress: int last_focused_window_with_progress_id: int session_name: str active_session_name: str class DrawData(NamedTuple): leading_spaces: int sep: str trailing_spaces: int bell_on_tab: str alpha: Sequence[float] active_fg: Color active_bg: Color inactive_fg: Color inactive_bg: Color default_bg: Color title_template: str active_title_template: str | None tab_activity_symbol: str powerline_style: PowerlineStyle tab_bar_edge: EdgeLiteral max_tab_title_length: int os_window_id: int def tab_fg(self, tab: TabBarData) -> int: if tab.is_active: if tab.active_fg is not None: return tab.active_fg return int(self.active_fg) if tab.inactive_fg is not None: return tab.inactive_fg return int(self.inactive_fg) def tab_bg(self, tab: TabBarData) -> int: if tab.is_active: if tab.active_bg is not None: return tab.active_bg return int(self.active_bg) if tab.inactive_bg is not None: return tab.inactive_bg return int(self.inactive_bg) def as_rgb(x: int) -> int: return (x << 8) | 2 @lru_cache def report_template_failure(template: str, e: str) -> None: log_error(f'Invalid tab title template: "{template}" with error: {e}') @lru_cache def compile_template(template: str) -> Any: try: return compile('f"""' + template + '"""', '