Skip to content

Commit

Permalink
kitty: simplify tab bar rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
geodimm committed Nov 10, 2023
1 parent 1c948e5 commit 311c441
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 38 deletions.
1 change: 1 addition & 0 deletions kitty/kitty.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ tab_bar_margin_height 9 0
tab_bar_align center
tab_bar_style custom
tab_bar_background none
active_tab_font_style bold

# Fonts
font_size 12.0
Expand Down
59 changes: 21 additions & 38 deletions kitty/tab_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
MAGNIFYING_GLASS_ICON = '󰍉'
LEFT_SEP, RIGHT_SEP = ('', '')

HOME = os.path.expanduser('~')


def draw_tab(
draw_data: DrawData,
Expand All @@ -20,46 +18,31 @@ def draw_tab(
is_last: bool,
extra_data: ExtraData
) -> int:
orig_fg = screen.cursor.fg
orig_bg = screen.cursor.bg

def draw_sep(which: str) -> None:
screen.cursor.bg = as_rgb(color_as_int(draw_data.default_bg))
screen.cursor.fg = orig_bg
screen.draw(which)
screen.cursor.bg = orig_bg
screen.cursor.fg = orig_fg

if max_title_length <= 1:
screen.draw('…')
elif max_title_length == 2:
screen.draw('…|')
elif max_title_length < 6:
draw_sep(LEFT_SEP)
screen.draw((' ' if max_title_length == 5 else '') + '…' + (' ' if max_title_length >= 4 else ''))
draw_sep(RIGHT_SEP)
else:
draw_sep(LEFT_SEP)
active_wd = ''
while active_wd == '':
active_wd = os.path.basename(TabAccessor(tab.tab_id).active_wd)

draw_separator(draw_data, screen, LEFT_SEP)
screen.draw(' ')
screen.draw(active_wd)
if tab.layout_name == 'stack':
screen.draw(' ')
# draw_title(draw_data, screen, tab, index)
ta = TabAccessor(tab.tab_id)
screen.draw(os.path.basename(ta.active_wd))
if tab.layout_name == 'stack':
screen.draw(' ' + MAGNIFYING_GLASS_ICON)

extra = screen.cursor.x - before - max_title_length
if extra >= 0:
screen.cursor.x -= extra + 3
screen.draw('…')
elif extra == -1:
screen.cursor.x -= 2
screen.draw('…')
screen.draw(' ')
draw_sep(RIGHT_SEP)
draw_sep(' ')
screen.draw(MAGNIFYING_GLASS_ICON)

screen.draw(' ')
draw_separator(draw_data, screen, RIGHT_SEP + ' ')
return screen.cursor.x


def as_rgb(x: int) -> int:
return (x << 8) | 2


def draw_separator(draw_data: DrawData, screen: Screen, separator: str) -> None:
orig_bg = screen.cursor.bg
orig_fg = screen.cursor.fg
screen.cursor.bg = as_rgb(color_as_int(draw_data.default_bg))
screen.cursor.fg = orig_bg
screen.draw(separator)
screen.cursor.bg = orig_bg
screen.cursor.fg = orig_fg

0 comments on commit 311c441

Please sign in to comment.