diff --git a/dots/.config/wezterm/config/theme/colors.lua b/dots/.config/wezterm/config/theme/colors.lua index 844041f3..7a764318 100644 --- a/dots/.config/wezterm/config/theme/colors.lua +++ b/dots/.config/wezterm/config/theme/colors.lua @@ -42,108 +42,100 @@ local color_names = { }, } -local get_colors = function(color_name) +local colors = { + tokyonight_night = { + foreground = "#c0caf5", + background = "#0f111d", + cursor_bg = "#c0caf5", + cursor_border = "#c0caf5", + cursor_fg = "#1a1b26", + selection_bg = "#33467C", + selection_fg = "#c0caf5", + ansi = { "#15161E", "#f7768e", "#9ece6a", "#e0af68", "#7aa2f7", "#bb9af7", "#7dcfff", "#a9b1d6" }, + brights = { "#414868", "#f7768e", "#9ece6a", "#e0af68", "#7aa2f7", "#bb9af7", "#7dcfff", "#c0caf5" }, + }, - local colors = { - tokyonight_night = { - foreground = "#c0caf5", - background = "#0f111d", - cursor_bg = "#c0caf5", - cursor_border = "#c0caf5", - cursor_fg = "#1a1b26", - selection_bg = "#33467C", - selection_fg = "#c0caf5", - ansi = { "#15161E", "#f7768e", "#9ece6a", "#e0af68", "#7aa2f7", "#bb9af7", "#7dcfff", "#a9b1d6" }, - brights = { "#414868", "#f7768e", "#9ece6a", "#e0af68", "#7aa2f7", "#bb9af7", "#7dcfff", "#c0caf5" }, + kanagawa = { + foreground = color_names.kanagawa.fujiWhite, + background = color_names.kanagawa.sumiInk1, + + cursor_bg = color_names.kanagawa.oldWhite, + cursor_fg = color_names.kanagawa.oldWhite, + cursor_border = color_names.kanagawa.oldWhite, + + selection_fg = color_names.kanagawa.oldWhite, + selection_bg = color_names.kanagawa.waveBlue2, + + scrollbar_thumb = color_names.kanagawa.sumiInk0, + split = color_names.kanagawa.sumiInk0, + + ansi = { + color_names.kanagawa.sumiInk0, + color_names.kanagawa.autumnRed, + color_names.kanagawa.autumnGreen, + color_names.kanagawa.boatYellow2, + color_names.kanagawa.crystalBlue, + color_names.kanagawa.oniViolet, + color_names.kanagawa.waveAqua1, + color_names.kanagawa.oldWhite, }, + brights = { + color_names.kanagawa.fujiGray, + color_names.kanagawa.samuraiRed, + color_names.kanagawa.springGreen, + color_names.kanagawa.carpYellow, + color_names.kanagawa.springBlue, + color_names.kanagawa.springViolet1, + color_names.kanagawa.waveAqua2, + color_names.kanagawa.fujiWhite, + }, + indexed = { [16] = color_names.kanagawa.surimiOrange, [17] = color_names.kanagawa.peachRed }, + tab_bar = { + background = color_names.kanagawa.sumiInk0, - kanagawa = { - foreground = color_names.kanagawa.fujiWhite, - background = color_names.kanagawa.sumiInk1, + inactive_tab_edge = color_names.kanagawa.sumiInk1, - cursor_bg = color_names.kanagawa.oldWhite, - cursor_fg = color_names.kanagawa.oldWhite, - cursor_border = color_names.kanagawa.oldWhite, - - selection_fg = color_names.kanagawa.oldWhite, - selection_bg = color_names.kanagawa.waveBlue2, - - scrollbar_thumb = color_names.kanagawa.sumiInk0, - split = color_names.kanagawa.sumiInk0, - - ansi = { - color_names.kanagawa.sumiInk0, - color_names.kanagawa.autumnRed, - color_names.kanagawa.autumnGreen, - color_names.kanagawa.boatYellow2, - color_names.kanagawa.crystalBlue, - color_names.kanagawa.oniViolet, - color_names.kanagawa.waveAqua1, - color_names.kanagawa.oldWhite, + inactive_tab = { + bg_color = color_names.kanagawa.sumiInk0, + fg_color = color_names.kanagawa.sumiInk4, }, - brights = { - color_names.kanagawa.fujiGray, - color_names.kanagawa.samuraiRed, - color_names.kanagawa.springGreen, - color_names.kanagawa.carpYellow, - color_names.kanagawa.springBlue, - color_names.kanagawa.springViolet1, - color_names.kanagawa.waveAqua2, - color_names.kanagawa.fujiWhite, + + inactive_tab_hover = { + bg_color = color_names.kanagawa.sumiInk1, + fg_color = color_names.kanagawa.sakuraPink, + }, + new_tab = { + bg_color = color_names.kanagawa.sumiInk0, + fg_color = color_names.kanagawa.oniViolet, }, - indexed = { [16] = color_names.kanagawa.surimiOrange, [17] = color_names.kanagawa.peachRed }, - tab_bar = { - background = color_names.kanagawa.sumiInk0, - active_tab = { - bg_color = color_names.kanagawa.sumiInk2, - fg_color = color_names.kanagawa.oniViolet, - }, - - inactive_tab = { - bg_color = color_names.kanagawa.sumiInk1, - fg_color = color_names.kanagawa.sumiInk4 - }, - - inactive_tab_hover = { - bg_color = color_names.kanagawa.sumiInk3, - fg_color = color_names.kanagawa.sakuraPink - }, - new_tab = { - bg_color = color_names.kanagawa.sumiInk0, - fg_color = color_names.kanagawa.oniViolet - }, - - new_tab_hover = { - bg_color = color_names.kanagawa.sumiInk3, - fg_color = color_names.kanagawa.sakuraPink, - }, + new_tab_hover = { + bg_color = color_names.kanagawa.sumiInk0, + fg_color = color_names.kanagawa.peachRed, }, }, - } + }, +} +M.theme = colors.kanagawa - local chosen_colors = colors[color_name] - if not chosen_colors then - local fallback_color = "kanagawa" - chosen_colors = colors[fallback_color] - wezterm.log_warn("No color '" .. color_name .. "' exists! Falling back to '" .. fallback_color .. "'!") - color_name = fallback_color - end - return { - palette = chosen_colors, - palette_name = color_name - } -end +-- This function returns the suggested title for a tab. +-- It prefers the title that was set via `tab:set_title()` +-- or `wezterm cli set-tab-title`, but falls back to the +-- title of the active pane in that tab. -local palette = get_colors("kanagawa") -M.theme = palette.palette +local edges = { + solid = { + left = "", + right = "", + }, + empty = { + left = "", + right = "", + }, +} -if palette.palette_name == "kanagawa" then - wezterm.log_info("Setting tab format for kanagawa") - -- This function returns the suggested title for a tab. - -- It prefers the title that was set via `tab:set_title()` - -- or `wezterm cli set-tab-title`, but falls back to the - -- title of the active pane in that tab. +---@diagnostic disable-next-line: unused-local +wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_width) local function tab_title(tab_info) local title = tab_info.tab_title -- if the tab title is explicitly set, take that @@ -155,17 +147,132 @@ if palette.palette_name == "kanagawa" then return tab_info.active_pane.title end - wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_width) - local title = tab_title(tab) + local bg = color_names.kanagawa.sumiInk0 + local fg = color_names.kanagawa.sumiInk4 - -- ensure that the titles fit in the available space, - -- and that we have room for the edges. - title = " " .. wezterm.truncate_right(title,max_width) .. " " + local edge_bg = color_names.kanagawa.sumiInk0 + local edge_fg = color_names.kanagawa.oniViolet - return { - { Text = title }, - } - end) -end + local title = " " .. wezterm.truncate_right(tab_title(tab), max_width - 2) .. " " + + if tab.is_active then + bg = color_names.kanagawa.sumiInk0 + fg = color_names.kanagawa.oniViolet + elseif hover then + bg = color_names.kanagawa.sumiInk2 + fg = color_names.kanagawa.peachRed + end + + return { + { Background = { Color = edge_bg } }, + { Foreground = { Color = edge_fg } }, + { Background = { Color = bg } }, + { Foreground = { Color = fg } }, + { Text = title }, + { Background = { Color = edge_bg } }, + { Foreground = { Color = fg } }, + { Text = edges.empty.left }, + { Background = { Color = bg } }, + { Foreground = { Color = fg } }, + } +end) + +wezterm.on("update-status", function(window, pane) + -- Each element holds the text for a cell in a "powerline" style << fade + + -- Figure out the cwd and host of the current pane. + -- This will pick up the hostname for the remote host if your + -- shell is using OSC 7 on the remote host. + local cwd_uri = pane:get_current_working_dir() + local hostname = "" + local cwd = "" + if cwd_uri then + cwd_uri = cwd_uri:sub(8) + local slash = cwd_uri:find("/") + if slash then + hostname = cwd_uri:sub(1, slash - 1) + -- Remove the domain name portion of the hostname + local dot = hostname:find("[.]") + if dot then + hostname = hostname:sub(1, dot - 1) + end + hostname = "@" .. hostname + -- and extract the cwd from the uri + cwd = cwd_uri:sub(slash) + end + end + + local date = wezterm.strftime("%a, %b %-d, %I:%M %p") + + -- An entry for each battery (typically 0 or 1 battery) + local battery = "" + for _, b in ipairs(wezterm.battery_info()) do + local charge_percent = b.state_of_charge * 100 + local battery_icon = "" + + if charge_percent < 100 then + battery_icon = "" + elseif charge_percent < 70 then + battery_icon = "" + elseif charge_percent < 60 then + battery_icon = "" + elseif charge_percent < 50 then + battery_icon = "" + elseif charge_percent < 40 then + battery_icon = "" + elseif charge_percent < 30 then + battery_icon = "" + elseif charge_percent < 20 then + battery_icon = "" + elseif charge_percent < 10 then + battery_icon = "" + end + + battery = battery_icon .. " " .. string.format("%.0f%%", charge_percent) + end + + -- Color palette for the backgrounds of each cell + local fade_colors = { + { bg = color_names.kanagawa.sumiInk1, fg = color_names.kanagawa.springGreen }, + { bg = color_names.kanagawa.sumiInk2, fg = color_names.kanagawa.crystalBlue }, + { bg = color_names.kanagawa.sumiInk3, fg = color_names.kanagawa.surimiOrange }, + { bg = color_names.kanagawa.sumiInk4, fg = color_names.kanagawa.fujiWhite }, + } + + -- The elements to be formatted + local elements = {} + -- Ensure the items have a "cap" on them + table.insert(elements, { Foreground = { Color = fade_colors[1].bg } }) + table.insert(elements, { Text = edges.solid.right }) + + -- How many cells have been formatted + local num_cells = 0 + + -- Translate a cell into elements + local function push(text, is_last) + local cell_no = num_cells + 1 + table.insert(elements, { Foreground = { Color = fade_colors[cell_no].fg } }) + table.insert(elements, { Background = { Color = fade_colors[cell_no].bg } }) + table.insert(elements, { Text = " " .. text .. " " }) + if not is_last then + table.insert(elements, { Foreground = { Color = fade_colors[cell_no + 1].bg } }) + table.insert(elements, { Text = edges.solid.right }) + end + num_cells = num_cells + 1 + end + + local cells = { + cwd, + battery, + date, + hostname, + } + while #cells > 0 do + local cell = table.remove(cells, 1) + push(cell, #cells == 0) + end + + window:set_right_status(wezterm.format(elements)) +end) return M