diff --git a/config/kitty/catppuccin-bar.py b/config/kitty/catppuccin-bar.py index d4cc582a..f1d9e39b 100644 --- a/config/kitty/catppuccin-bar.py +++ b/config/kitty/catppuccin-bar.py @@ -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, @@ -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 diff --git a/config/kitty/kanagawa-bar.py b/config/kitty/kanagawa-bar.py index d898a175..e24648e6 100644 --- a/config/kitty/kanagawa-bar.py +++ b/config/kitty/kanagawa-bar.py @@ -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 @@ -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, diff --git a/config/kitty/rose-pine-bar.py b/config/kitty/rose-pine-bar.py index 57887473..7c61eea4 100644 --- a/config/kitty/rose-pine-bar.py +++ b/config/kitty/rose-pine-bar.py @@ -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 @@ -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, diff --git a/config/kitty/tokyonight-bar.py b/config/kitty/tokyonight-bar.py new file mode 100644 index 00000000..7c61eea4 --- /dev/null +++ b/config/kitty/tokyonight-bar.py @@ -0,0 +1,161 @@ +# Author: megalithic +# https://github.com/megalithic/dotfiles/blob/main/config/kitty/tab_bar.py + +import datetime +import json +import os +import subprocess +from collections import defaultdict + +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 + + +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 + + +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(25, 23, 36))) + screen.cursor.bg = as_rgb(color_as_int(Color(224, 222, 244))) + screen.draw(symbol) + screen.cursor.fg, screen.cursor.bg = fg, bg + screen.cursor.x = len(symbol) + 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: + 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 + + +# 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 + + draw_attributed_string(Formatter.reset, screen) + date = datetime.datetime.today().strftime(" (%B %d") + time = datetime.datetime.now().strftime(", %H:%M)") + hostname = os.uname()[1] + + right_status_length = calc_draw_spaces(date + " " + time + " ") + + draw_spaces = screen.columns - screen.cursor.x - right_status_length + if draw_spaces > 0: + screen.draw(" " * draw_spaces) + + cells = [ + (Color(235, 188, 186), date), + (Color(49, 116, 143), time), + ] + + 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 + + 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, + tab: TabBarData, + before: int, + max_title_length: int, + index: int, + is_last: bool, + extra_data: ExtraData, +) -> int: + _draw_icon(screen, index, symbol="  ") + _draw_left_status( + draw_data, + screen, + tab, + before, + max_title_length, + index, + is_last, + extra_data, + ) + _draw_right_status( + screen, + is_last, + ) + + return screen.cursor.x diff --git a/modules/desktop/terminal/kitty.nix b/modules/desktop/terminal/kitty.nix index f2caa9b4..52395132 100644 --- a/modules/desktop/terminal/kitty.nix +++ b/modules/desktop/terminal/kitty.nix @@ -25,7 +25,7 @@ in { shell_integration = "no-cursor"; confirm_os_window_close = -1; - background_opacity = 0.8; + background_opacity = "0.8"; repaint_delay = 10; disable_ligatures = "cursor"; adjust_line_height = "113%"; @@ -33,7 +33,7 @@ in { enable_audio_bell = "no"; bell_on_tab = "no"; - visual_bell_duration = "0.0"; + visual_bell_duration = 0; strip_trailing_spaces = "smart"; copy_on_select = "clipboard"; @@ -42,15 +42,14 @@ in { default_pointer_shape = "beam"; cursor_shape = "block"; - cursor_blink_interval = "0.5"; - cursor_stop_blinking_after = "15.0"; + cursor_blink_interval = 0; input_delay = 3; pointer_shape_when_dragging = "beam"; pointer_shape_when_grabbed = "arrow"; click_interval = "0.5"; - mouse_hide_wait = "3.0"; + mouse_hide_wait = 3; focus_follows_mouse = "yes"; detect_urls = "yes"; @@ -58,16 +57,16 @@ in { url_prefixes = "http https file ftp gemini irc gopher mailto news git"; scrollback_lines = 5000; - wheel_scroll_multiplier = "5.0"; + wheel_scroll_multiplier = 5; initial_window_height = 28; initial_window_width = 96; remember_window_size = "yes"; resize_draw_strategy = "static"; - window_border_width = "1.0"; - window_margin_width = "0.0"; - window_padding_width = "15.00"; + window_border_width = 1; + window_margin_width = 0; + window_padding_width = 15; placement_strategy = "top-left"; draw_minimal_borders = "yes"; @@ -120,11 +119,11 @@ in { inherit (config.modules.themes.colors.main) bright normal types; inherit (config.modules.themes.font.mono) size; in '' - font_family Victor Mono Bold Nerd Font Complete - italic_font Victor Mono Bold Italic Nerd Font Complete + font_family Victor Mono SemiBold Nerd Font Complete + italic_font Victor Mono SemiBold Italic Nerd Font Complete - bold_font Victor Mono SemiBold Nerd Font Complete - bold_italic_font Victor Mono SemiBold Italic Nerd Font Complete + bold_font Victor Mono Bold Nerd Font Complete + bold_italic_font Victor Mono Bold Italic Nerd Font Complete font_size ${toString size} @@ -135,34 +134,30 @@ in { cursor_text_color ${types.bg} tab_bar_background ${types.bg} - tab_title_template "{fmt.fg._7976ab}{fmt.bg.default} ○ {index}:{f'{title[:6]}…{title[-6:]}' if title.rindex(title[-1]) + 1 > 25 else title}{' []' if layout_name == 'stack' else '''} " - active_tab_title_template "{fmt.fg._f2cdcd}{fmt.bg.default} 綠{index}:{f'{title[:6]}…{title[-6:]}' if title.rindex(title[-1]) + 1 > 25 else title}{' []' if layout_name == 'stack' else '''} " + active_tab_foreground ${types.bg} + active_tab_background ${normal.magenta} + inactive_tab_foreground ${types.fg} + inactive_tab_background ${types.bg} - selection_foreground ${types.bg} + selection_f oreground ${types.bg} selection_background ${types.highlight} color0 ${normal.black} - color8 ${bright.black} - color1 ${normal.red} - color9 ${bright.red} - color2 ${normal.green} - color10 ${bright.green} - color3 ${normal.yellow} - color11 ${bright.yellow} - color4 ${normal.blue} - color12 ${bright.blue} - color5 ${normal.magenta} - color13 ${bright.magenta} - color6 ${normal.cyan} - color14 ${bright.cyan} - color7 ${normal.white} + + color8 ${bright.black} + color9 ${bright.red} + color10 ${bright.green} + color11 ${bright.yellow} + color12 ${bright.blue} + color13 ${bright.magenta} + color14 ${bright.cyan} color15 ${bright.white} ''; };