-
Notifications
You must be signed in to change notification settings - Fork 0
/
tab_bar.py
54 lines (42 loc) · 1.29 KB
/
tab_bar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
from kitty.fast_data_types import (
Screen,
)
from kitty.utils import color_as_int
from kitty.tab_bar import (
DrawData,
ExtraData,
TabBarData,
as_rgb,
draw_title,
)
# Draw tabs by splitting the full width of the window
def draw_tab(
draw_data: DrawData, screen: Screen, tab: TabBarData,
before: int, max_tab_length: int, index: int, is_last: bool,
extra_data: ExtraData
) -> int:
# Draw first space
screen.draw(' ')
# Draw title
draw_title(draw_data, screen, tab, index, max_tab_length)
title_length = screen.cursor.x - before
# Truncate the title if it's too long
if title_length + 1 > max_tab_length:
screen.cursor.x = before + max_tab_length - 1
screen.draw('… ')
else:
# Draw trailing spaces
if is_last:
# Draw the last tab to the end
screen.draw(' ' * (screen.columns - screen.cursor.x))
else:
# Draw to max_tab_length
screen.draw(' ' * (max_tab_length - title_length + 1))
end = screen.cursor.x
screen.cursor.bold = screen.cursor.italic = False
screen.cursor.fg = 0
if not is_last:
screen.cursor.bg = as_rgb(color_as_int(draw_data.inactive_bg))
screen.cursor.bg = 0
return end