Skip to content

Commit

Permalink
Kitty: almost a done with cooler theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Icy-Thought committed Mar 9, 2024
1 parent ea51204 commit f9f1df5
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 136 deletions.
152 changes: 48 additions & 104 deletions config/kitty/catppuccin-bar.py
Original file line number Diff line number Diff line change
@@ -1,126 +1,78 @@
# Author: megalithic
# https://github.com/megalithic/dotfiles/blob/main/config/kitty/tab_bar.py
# Author: moonlightsh
# https://github.com/kovidgoyal/kitty/discussions/4447#discussioncomment-7771377

import datetime
import json
import os
import subprocess
from collections import defaultdict
from kitty.fast_data_types import Screen, get_options
from kitty.tab_bar import (
DrawData,
ExtraData,
TabBarData,
as_rgb,
draw_tab_with_powerline,
)

from kitty.boss import get_boss
from kitty.fast_data_types import Screen, add_timer
from kitty.rgb import Color
from kitty.tab_bar import (DrawData, ExtraData, Formatter, TabBarData, as_rgb,
draw_attributed_string, draw_title)
from kitty.utils import color_as_int

timer_id = None
CLOCK_FG = as_rgb(int("1e1d2f", 16))
CLOCK_BG = as_rgb(int("c9cbff", 16))

DATE_FG = CLOCK_FG
DATE_BG = as_rgb(int("f2cdcd", 16))

def calc_draw_spaces(*args) -> int:
length = 0
for i in args:
if not isinstance(i, str):
i = str(i)
length += len(i)
return length
SYMBOL = "  "
SYMBOL_FG = CLOCK_FG
SYMBOL_BG = as_rgb(int("96cdfb", 16))


def _draw_icon(screen: Screen, index: int, symbol: str = "") -> int:
if index != 1:
return 0

fg, bg = screen.cursor.fg, screen.cursor.bg
screen.cursor.fg = as_rgb(color_as_int(Color(30, 29, 47)))
screen.cursor.bg = as_rgb(color_as_int(Color(199, 201, 253)))
screen.draw(symbol)
screen.cursor.fg, screen.cursor.bg = fg, bg
screen.cursor.x = len(symbol)
return screen.cursor.x
cells = [
(SYMBOL_FG, SYMBOL_BG, symbol),
(SYMBOL_BG, SYMBOL_FG, ""),
(screen.cursor.fg, screen.cursor.bg, " "),
]

for fg, bg, cell in cells:
restore_fg, restore_bg = screen.cursor.fg, screen.cursor.bg
screen.cursor.fg = fg
screen.cursor.bg = bg
screen.draw(cell)
screen.cursor.fg, screen.cursor.bg = restore_fg, restore_bg

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:
print(extra_data)
if draw_data.leading_spaces:
screen.draw(" " * draw_data.leading_spaces)

# TODO: https://github.com/kovidgoyal/kitty/discussions/4447#discussioncomment-2463083
# tm = get_boss().active_tab_manager
# if tm is not None:
# w = tm.active_window
# if w is not None:
# cwd = w.cwd_of_child or ''
# log_error(cwd)

draw_title(draw_data, screen, tab, index)
trailing_spaces = min(max_title_length - 1, draw_data.trailing_spaces)
max_title_length -= trailing_spaces
extra = screen.cursor.x - before - max_title_length
if extra > 0:
screen.cursor.x -= extra + 1
screen.draw("…")
if trailing_spaces:
screen.draw(" " * trailing_spaces)
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.draw(draw_data.sep)
screen.cursor.bg = 0
return end
return screen.cursor.x


# more handy kitty tab_bar things:
# REF: https://github.com/kovidgoyal/kitty/discussions/4447#discussioncomment-2183440
def _draw_right_status(screen: Screen, is_last: bool) -> int:
if not is_last:
return 0
return screen.cursor.x

draw_attributed_string(Formatter.reset, screen)
date = datetime.datetime.today().strftime(" (%B %d")
time = datetime.datetime.now().strftime(", %H:%M)")
hostname = os.uname()[1]
cells = [
(CLOCK_BG, screen.cursor.bg, ""),
(CLOCK_FG, CLOCK_BG, datetime.datetime.now().strftime(" %H:%M ")),
(DATE_BG, CLOCK_BG, ""),
(DATE_FG, DATE_BG, datetime.datetime.now().strftime("  %Y/%m/%d ")),
]

right_status_length = calc_draw_spaces(date + " " + time + " ")
right_status_length = 0
for _, _, cell in cells:
right_status_length += len(cell)

draw_spaces = screen.columns - screen.cursor.x - right_status_length
if draw_spaces > 0:
screen.draw(" " * draw_spaces)

cells = [
(Color(171, 233, 179), date),
(Color(171, 233, 179), time),
]

for fg, bg, cell in cells:
screen.cursor.fg = fg
screen.cursor.bg = bg
screen.draw(cell)
screen.cursor.fg = 0
for color, status in cells:
screen.cursor.fg = as_rgb(color_as_int(color))
screen.draw(status)
screen.cursor.bg = 0

if screen.columns - screen.cursor.x > right_status_length:
screen.cursor.x = screen.columns - right_status_length

screen.cursor.x = max(screen.cursor.x, screen.columns - right_status_length)
return screen.cursor.x


# REF: https://github.com/kovidgoyal/kitty/discussions/4447#discussioncomment-1940795
# def redraw_tab_bar():
# tm = get_boss().active_tab_manager
# if tm is not None:
# tm.mark_tab_bar_dirty()


def draw_tab(
draw_data: DrawData,
screen: Screen,
Expand All @@ -131,20 +83,12 @@ def draw_tab(
is_last: bool,
extra_data: ExtraData,
) -> int:
_draw_icon(screen, index, symbol=" \uf81f ")
_draw_left_status(
draw_data,
screen,
tab,
before,
max_title_length,
index,
is_last,
extra_data,
_draw_icon(screen, index, symbol=SYMBOL)
end = draw_tab_with_powerline(
draw_data, screen, tab, before, max_title_length, index, is_last, extra_data
)
_draw_right_status(
screen,
is_last,
)

return screen.cursor.x
return end
6 changes: 5 additions & 1 deletion config/kitty/kanagawa-bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,22 @@ def _draw_left_status(
trailing_spaces = min(max_title_length - 1, draw_data.trailing_spaces)
max_title_length -= trailing_spaces
extra = screen.cursor.x - before - max_title_length

if extra > 0:
screen.cursor.x -= extra + 1
screen.draw("…")
if trailing_spaces:
screen.draw(" " * trailing_spaces)

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.draw(draw_data.sep)
screen.cursor.bg = 0

return end


Expand Down Expand Up @@ -138,7 +142,7 @@ def draw_tab(
is_last: bool,
extra_data: ExtraData,
) -> int:
_draw_icon(screen, index, symbol=" \uf81f ")
_draw_icon(screen, index, symbol=" ")
_draw_left_status(
draw_data,
screen,
Expand Down
6 changes: 5 additions & 1 deletion config/kitty/rose-pine-bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,22 @@ def _draw_left_status(
trailing_spaces = min(max_title_length - 1, draw_data.trailing_spaces)
max_title_length -= trailing_spaces
extra = screen.cursor.x - before - max_title_length

if extra > 0:
screen.cursor.x -= extra + 1
screen.draw("…")
if trailing_spaces:
screen.draw(" " * trailing_spaces)

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.draw(draw_data.sep)
screen.cursor.bg = 0

return end


Expand Down Expand Up @@ -138,7 +142,7 @@ def draw_tab(
is_last: bool,
extra_data: ExtraData,
) -> int:
_draw_icon(screen, index, symbol=" \uf81f ")
_draw_icon(screen, index, symbol=" ")
_draw_left_status(
draw_data,
screen,
Expand Down
Loading

0 comments on commit f9f1df5

Please sign in to comment.