kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
24.44k stars 979 forks source link

Kitty 0.33.0 breaks custom tab bar #7242

Closed esn89 closed 7 months ago

esn89 commented 7 months ago

Describe the bug

Kitty 0.33.0 breaks the custom tab bar by not rendering it.

To Reproduce Steps to reproduce the behavior:

  1. Add this into file into ~/.config/kittytab_bar.py:
from kitty.boss import get_boss
from kitty.fast_data_types import Screen, get_options
from kitty.utils import color_as_int
from kitty.tab_bar import (
    DrawData,
    ExtraData,
    Formatter,
    TabBarData,
    as_rgb,
    draw_attributed_string,
    draw_title,
)
import subprocess
from subprocess import PIPE

opts = get_options()
icon_fg = as_rgb(color_as_int(opts.background))
icon_bg = as_rgb(color_as_int(opts.color6))

date_fgcolor = as_rgb(color_as_int(opts.color1))
# date_bgcolor = as_rgb(color_as_int(opts.color9))
date_bgcolor = as_rgb(color_as_int(opts.color0))

separator_fg = as_rgb(color_as_int(opts.color9))

bat_text_color = as_rgb(color_as_int(opts.color15))
background_color = as_rgb(color_as_int(opts.background))
white = as_rgb(color_as_int(opts.color7))

SEPARATOR_SYMBOL, SOFT_SEPARATOR_SYMBOL = ("", "")
RIGHT_SEPARATOR_SYMBOL, RIGHT_SOFT_SEPARATOR_SYMBOL = ("", "")
LEFT_SEPARATOR_SYMBOL, RIGHT_SOFT_SEPARATOR_SYMBOL = ("", "")
RIGHT_MARGIN = 0
ICON = " "

def _draw_icon(screen: Screen, index: int) -> int:
    if index != 1:
        return 0
    fg, bg = screen.cursor.fg, screen.cursor.bg
    screen.cursor.fg = icon_fg
    screen.cursor.bg = icon_bg
    screen.draw(ICON)
    screen.cursor.fg, screen.cursor.bg = fg, bg
    screen.cursor.x = len(ICON)
    return screen.cursor.x

def _draw_left_status(
    draw_data: DrawData,
    screen: Screen,
    tab: TabBarData,
    before: int,
    max_title_length: int,
    index: int,
    is_last: bool,
    extra_data: ExtraData,
) -> int:
    if screen.cursor.x >= screen.columns - right_status_length:
        return screen.cursor.x
    tab_bg = screen.cursor.bg
    tab_fg = screen.cursor.fg
    default_bg = as_rgb(int(draw_data.default_bg))
    if extra_data.next_tab:
        next_tab_bg = as_rgb(draw_data.tab_bg(extra_data.next_tab))
        needs_soft_separator = next_tab_bg == tab_bg
    else:
        next_tab_bg = default_bg
        needs_soft_separator = False
    if screen.cursor.x <= len(ICON):
        screen.cursor.x = len(ICON)
    screen.draw(" ")
    screen.cursor.bg = tab_bg

    draw_title(draw_data, screen, tab, index)
    if not needs_soft_separator:
        screen.draw(" ")
        screen.cursor.fg = tab_bg
        screen.cursor.bg = next_tab_bg
        screen.draw(SEPARATOR_SYMBOL)
    else:
        prev_fg = screen.cursor.fg
        if tab_bg == tab_fg:
            screen.cursor.fg = default_bg
        elif tab_bg != default_bg:
            c1 = draw_data.inactive_bg.contrast(draw_data.default_bg)
            c2 = draw_data.inactive_bg.contrast(draw_data.inactive_fg)
            if c1 < c2:
                screen.cursor.fg = default_bg
        screen.cursor.fg = prev_fg # separator_fg
        screen.draw(" " + SOFT_SEPARATOR_SYMBOL)
    end = screen.cursor.x
    return end

def _draw_right_status(screen: Screen, is_last: bool, cells: list) -> int:
    if not is_last:
        return 0
    draw_attributed_string(Formatter.reset, screen)
    screen.cursor.x = screen.columns - right_status_length
    screen.cursor.fg = 0
    for bgColor, fgColor, status in cells:
        screen.cursor.fg = fgColor
        screen.cursor.bg = bgColor
        screen.draw(status)
    screen.cursor.bg = 0
    return screen.cursor.x

def _redraw_tab_bar(_):
    tm = get_boss().active_tab_manager
    if tm is not None:
        tm.mark_tab_bar_dirty()

right_status_length = -1

def draw_tab(
    draw_data: DrawData,
    screen: Screen,
    tab: TabBarData,
    before: int,
    max_title_length: int,
    index: int,
    is_last: bool,
    extra_data: ExtraData,
) -> int:
    global right_status_length
    # date = datetime.now().strftime(" %d.%m.%Y")
    # date2 = datetime.now().strftime("%d.%m")
    # cells = [(date_bgcolor, date_fgcolor, date), (date_fgcolor, date_bgcolor, date2)]
    # right_status_length = RIGHT_MARGIN
    # for cell in cells:
    #     right_status_length += len(str(cell[3]))

    ICON + " " + SEPARATOR_SYMBOL
    cells = []
    cells.append((icon_fg, icon_bg, LEFT_SEPARATOR_SYMBOL))
    cells.append((icon_bg, icon_fg, " "))
    cells.append((date_bgcolor, icon_fg, " evan"))
    cells.append((background_color, date_bgcolor, RIGHT_SEPARATOR_SYMBOL))
    cells.append((background_color, date_bgcolor, "  "))
    # cells.append((icon_bg, icon_fg, ""))
    cells.append((icon_fg, white, LEFT_SEPARATOR_SYMBOL))
    cells.append((white, icon_fg, "⎈ "))
    cells.append((date_bgcolor, icon_fg, f" {getGKE()}"))
    cells.append((background_color, date_bgcolor, RIGHT_SEPARATOR_SYMBOL))
    right_status_length = RIGHT_MARGIN
    for cell in cells:
        right_status_length += len(str(cell[2]))

    _draw_icon(screen, index)
    _draw_left_status(
        draw_data,
        screen,
        tab,
        before,
        max_title_length,
        index,
        is_last,
        extra_data,
    )
    _draw_right_status(
        screen,
        is_last,
        cells,
    )
    return screen.cursor.x

def getGKE():
    result = subprocess.Popen(["cat", "/tmp/k8"], stdout=PIPE, stderr=PIPE)
    stdout, stderr = result.communicate()
    return stdout.decode()
  1. Add the following to ~/.config/kitty/kitty.conf
    tab_bar_edge top
    tab_bar_style custom
    tab_bar_align center
    tab_bar_margin_width       5.0
    tab_bar_margin_height      7.5 7.5
    tab_bar_min_tabs           1
  2. Start kitty

Screenshots

0.32.2:

pic

0.33.0:

pic

Environment details

kitty 0.33.0 (04f8cb6d30) created by Kovid Goyal
Darwin M-J6HX003X0L 23.4.0 Darwin Kernel Version 23.4.0: Wed Feb 21 21:45:49 PST 2024; root:xnu-10063.101.15~2/RELEASE_ARM64_T6020 arm64
ProductName:            macOS ProductVersion:           14.4 BuildVersion:              23E214
Frozen: True
Paths:
  kitty: /Applications/kitty.app/Contents/MacOS/kitty
  base dir: /Applications/kitty.app/Contents/Resources/kitty
  extensions dir: /Applications/kitty.app/Contents/Resources/Python/lib/kitty-extensions
  system shell: /bin/zsh
Loaded config files:
  /Users/me/.config/kitty/kitty.conf

Config options different from defaults:
active_tab_font_style              (False, False)
active_tab_title_template          {index} 
allow_remote_control               yes
bold_font                          PragmataPro Mono Liga Bold
bold_italic_font                   PragmataPro Mono Liga Bold Italic
cursor_blink_interval              0.0
draw_minimal_borders               False
enabled_layouts                    ['stack', 'grid', 'fat']
font_family                        PragmataPro Mono Liga Regular
font_size                          17.0
hide_window_decorations            2
inactive_text_alpha                0.81
italic_font                        PragmataPro Mono Liga Italic
kitty_mod                          cmd
macos_custom_beam_cursor           True
macos_option_as_alt                3
macos_quit_when_last_window_closed True
macos_show_window_title_in         none
macos_titlebar_color               724777218
scrollback_pager_history_size      4194304
shell                              /bin/zsh --login
startup_session                    /Users/me/.config/kitty/kitstart.conf
symbol_map:
        U+ea65 - U+ea65 → codicon Regular
        U+ea8b - U+ea8b → codicon Regular
        U+ead0 - U+ead0 → codicon Regular
        U+eb29 - U+eb29 → codicon Regular
        U+eb2d - U+eb2d → codicon Regular
        U+eb5b - U+eb5b → codicon Regular
        U+eb5d - U+eb5d → codicon Regular
        U+eb5f - U+eb5f → codicon Regular
        U+eb60 - U+eb60 → codicon Regular
        U+eb61 - U+eb61 → codicon Regular
kovidgoyal commented 7 months ago

Run kitty from another terminal and look at its stdout/stderr that should tell you what internal API has changed and therefore what adjustment you need to make to your custom tab bar. And I will note that your custom tab bar works for me as shown in attached screenshot. screenshot

esn89 commented 7 months ago

Hi @kovidgoyal ,

I have started kitty from a terminal like you said, but I do not see output at all:

https://imgur.com/a/PuJW0L6

kovidgoyal commented 7 months ago

Then your tab bar is either not being picked up or is not generating any errors. Put some prints into it and see the output in kitty stdout.

esn89 commented 7 months ago

Turns out, rebooting my computer did the trick