#!/usr/bin/env python3 # License: GPL v3 Copyright: 2018, Kovid Goyal import os from functools import lru_cache, partial, wraps from string import Formatter as StringFormatter from typing import ( Any, Callable, Dict, List, NamedTuple, Optional, Sequence, Tuple, Union ) from .borders import Border, BorderColor from .config import build_ansi_color_table from .constants import config_dir from .fast_data_types import ( DECAWM, Region, Screen, cell_size_for_window, get_options, pt_to_px, set_tab_bar_render_data, viewport_for_window, Color ) from .rgb import alpha_blend, color_as_sgr, color_from_int, to_color from .types import WindowGeometry, run_once from .typing 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 num_windows: int num_window_groups: int layout_name: str has_activity_since_last_focus: bool active_fg: Optional[int] active_bg: Optional[int] inactive_fg: Optional[int] inactive_bg: Optional[int] 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: Optional[str] tab_activity_symbol: str powerline_style: PowerlineStyle tab_bar_edge: EdgeLiteral 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 + '"""', '