From 0a2d62a693dded1d2066446d2b82e12e3f7c7558 Mon Sep 17 00:00:00 2001 From: winston Date: Sun, 1 Jan 2023 15:36:39 +0100 Subject: [PATCH] feat(wezterm): rainbow tabs --- dot_config/wezterm/bar.lua | 230 ++++++++++++++++++++----------- dot_config/wezterm/fonts.lua | 108 +++++---------- dot_config/wezterm/shortcuts.lua | 68 ++++----- dot_config/wezterm/theme.lua | 5 + dot_config/wezterm/tlconfig.lua | 1 + dot_config/wezterm/wezterm.lua | 9 +- 6 files changed, 231 insertions(+), 190 deletions(-) create mode 100644 dot_config/wezterm/tlconfig.lua diff --git a/dot_config/wezterm/bar.lua b/dot_config/wezterm/bar.lua index 76ba1f7..1cae07b 100644 --- a/dot_config/wezterm/bar.lua +++ b/dot_config/wezterm/bar.lua @@ -1,102 +1,176 @@ local wezterm = require("wezterm") -local fonts = require("fonts") local DIVIDERS = { - LEFT = utf8.char(0xe0be), - RIGHT = utf8.char(0xe0bc), + LEFT = utf8.char(0xe0be), + RIGHT = utf8.char(0xe0bc), } +-- superscript/subscript +local function numberStyle(number, script) + local scripts = { + superscript = { + "⁰", + "¹", + "²", + "³", + "⁴", + "⁵", + "⁶", + "⁷", + "⁸", + "⁹", + }, + subscript = { + "₀", + "₁", + "₂", + "₃", + "₄", + "₅", + "₆", + "₇", + "₈", + "₉", + }, + } + local numbers = scripts[script] + local number_string = tostring(number) + local result = "" + for i = 1, #number_string do + local char = number_string:sub(i, i) + local num = tonumber(char) + if num then + result = result .. numbers[num + 1] + else + result = result .. char + end + end + return result +end + -- custom tab bar ---@diagnostic disable-next-line: unused-local wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_width) - local colours = config.resolved_palette.tab_bar + local colours = config.resolved_palette.tab_bar - local active_tab_index = 0 - for _, t in ipairs(tabs) do - if t.is_active == true then - active_tab_index = t.tab_index - end - end + local active_tab_index = 0 + for _, t in ipairs(tabs) do + if t.is_active == true then + active_tab_index = t.tab_index + end + end - local active_bg = config.resolved_palette.ansi[6] - local active_fg = colours.background - local inactive_bg = colours.inactive_tab.bg_color - local inactive_fg = colours.inactive_tab.fg_color - local new_tab_bg = colours.new_tab.bg_color + local rainbow = { + config.resolved_palette.ansi[2], + config.resolved_palette.indexed[16], + config.resolved_palette.ansi[4], + config.resolved_palette.ansi[3], + config.resolved_palette.ansi[5], + config.resolved_palette.ansi[6] + } - local s_bg, s_fg, e_bg, e_fg + local i = (tab.tab_index) % 6 + local active_bg = rainbow[i + 1] + local active_fg = colours.background + local inactive_bg = colours.inactive_tab.bg_color + local inactive_fg = colours.inactive_tab.fg_color + local new_tab_bg = colours.new_tab.bg_color - -- the last tab - if tab.tab_index == #tabs - 1 then - if tab.is_active then - s_bg = active_bg - s_fg = active_fg - e_bg = new_tab_bg - e_fg = active_bg - else - s_bg = inactive_bg - s_fg = inactive_fg - e_bg = new_tab_bg - e_fg = inactive_bg - end - elseif tab.tab_index == active_tab_index - 1 then - s_bg = inactive_bg - s_fg = inactive_fg - e_bg = active_bg - e_fg = inactive_bg - elseif tab.is_active then - s_bg = active_bg - s_fg = active_fg - e_bg = inactive_bg - e_fg = active_bg - else - s_bg = inactive_bg - s_fg = inactive_fg - e_bg = inactive_bg - e_fg = inactive_bg - end + local s_bg, s_fg, e_bg, e_fg - local muxpanes = wezterm.mux.get_tab(tab.tab_id):panes() - local count = #muxpanes == 1 and "" or #muxpanes - local index = tab.tab_index + 1 .. ": " + -- the last tab + if tab.tab_index == #tabs - 1 then + if tab.is_active then + s_bg = active_bg + s_fg = active_fg + e_bg = new_tab_bg + e_fg = active_bg + else + s_bg = inactive_bg + s_fg = inactive_fg + e_bg = new_tab_bg + e_fg = inactive_bg + end + elseif tab.tab_index == active_tab_index - 1 then + s_bg = inactive_bg + s_fg = inactive_fg + e_bg = rainbow[(i + 1) % 6 + 1] + e_fg = inactive_bg + elseif tab.is_active then + s_bg = active_bg + s_fg = active_fg + e_bg = inactive_bg + e_fg = active_bg + else + s_bg = inactive_bg + s_fg = inactive_fg + e_bg = inactive_bg + e_fg = inactive_bg + end - return { - { Background = { Color = s_bg } }, - { Foreground = { Color = s_fg } }, - { - Text = " " .. index .. tab.active_pane.title .. fonts.numberStyle(count, "superscript") .. " ", - }, - { Background = { Color = e_bg } }, - { Foreground = { Color = e_fg } }, - { Text = DIVIDERS.RIGHT }, - } + local tabi = wezterm.mux.get_tab(tab.tab_id) + local muxpanes = tabi:panes() + local count = #muxpanes == 1 and "" or #muxpanes + local index = tab.tab_index + 1 .. ": " + + return { + { Background = { Color = s_bg } }, + { Foreground = { Color = s_fg } }, + { + Text = " " .. index .. tab.active_pane.title .. numberStyle(count, "superscript") .. " ", + }, + { Background = { Color = e_bg } }, + { Foreground = { Color = e_fg } }, + { Text = DIVIDERS.RIGHT }, + } +end) + +local function arrContains(arr, val) + for _, v in ipairs(arr) do + if v == val then + return true + end + end + + return false +end + +local nonpadded_apps = { "nvim", "btop", "btm" } + +wezterm.on("smartpadding", function(window, pane) + local fgp = pane:get_foreground_process_info() + if fgp == nil then return + elseif arrContains(nonpadded_apps, fgp.name) then + window:set_config_overrides({ window_padding = { left = 0, right = 0, top = 0, bottom = 0 } }) + else window:set_config_overrides({ window_padding = wezterm.GLOBAL.smart_padding }) end end) -- custom status ---@diagnostic disable-next-line: unused-local wezterm.on("update-status", function(window, pane) - local palette = window:effective_config().resolved_palette - local firstTabActive = window:mux_window():tabs_with_info()[1].is_active + if wezterm.GLOBAL.smart_padding ~= nil then + wezterm.emit("smartpadding", window, pane) + end - local leader_text = "  " + local palette = window:effective_config().resolved_palette + local first_tab_active = window:mux_window():tabs_with_info()[1].is_active - if window:leader_is_active() then - leader_text = "  " - end + local leader_text = "  " + if window:leader_is_active() then leader_text = "  " end - local divider_bg = firstTabActive and palette.ansi[6] or palette.tab_bar.inactive_tab.bg_color + local divider_bg = first_tab_active and palette.ansi[2] or palette.tab_bar.inactive_tab.bg_color - window:set_left_status(wezterm.format({ - { Foreground = { Color = palette.background } }, - { Background = { Color = palette.ansi[5] } }, - { Text = leader_text }, - { Background = { Color = divider_bg } }, - { Foreground = { Color = palette.ansi[5] } }, - { Text = DIVIDERS.RIGHT }, - })) - window:set_right_status(wezterm.format({ - { Background = { Color = palette.background } }, - { Foreground = { Color = palette.ansi[6] } }, - { Text = os.date(" %H:%M ") }, - })) + window:set_left_status(wezterm.format({ + { Foreground = { Color = palette.background } }, + { Background = { Color = palette.ansi[5] } }, + { Text = leader_text }, + { Background = { Color = divider_bg } }, + { Foreground = { Color = palette.ansi[5] } }, + { Text = DIVIDERS.RIGHT }, + })) + window:set_right_status(wezterm.format({ + { Background = { Color = palette.tab_bar.background } }, + { Foreground = { Color = palette.ansi[6] } }, + { Text = os.date(" %H:%M ") }, + })) end) diff --git a/dot_config/wezterm/fonts.lua b/dot_config/wezterm/fonts.lua index b96ab4f..5373e04 100644 --- a/dot_config/wezterm/fonts.lua +++ b/dot_config/wezterm/fonts.lua @@ -3,84 +3,38 @@ local wezterm = require("wezterm") local M = {} M.get_font = function(name) - -- fonts I like, with the settings I prefer - -- kept seperately from the rest of the config so that I can easily change them - local fonts = { - berkeley = { - font = { - family = "Berkeley Mono", - weight = "Bold", - }, - size = 16, - }, - comic = { - font = "Comic Code Ligatures", - size = 18, - }, - fantasque = { - font = "Fantasque Sans Mono", - size = 20, - }, - victor = { - font = { - family = "Victor Mono", - weight = "DemiBold", - harfbuzz_features = { "ss02=1" }, - }, - size = 18, - }, - } + -- fonts I like, with the settings I prefer + -- kept seperately from the rest of the config so that I can easily change them + local fonts = { + berkeley = { + font = { + family = "Berkeley Mono", + weight = "Bold", + }, + size = 16, + }, + comic = { + font = "Comic Code Ligatures", + size = 18, + }, + fantasque = { + font = "Fantasque Sans Mono", + size = 20, + }, + victor = { + font = { + family = "Victor Mono", + weight = "DemiBold", + harfbuzz_features = { "ss02=1" }, + }, + size = 18, + }, + } - return { - font = wezterm.font_with_fallback({ - fonts[name].font, - "Apple Color Emoji", - }), - size = fonts[name].size, - } -end - --- superscript/subscript -M.numberStyle = function(number, script) - local scripts = { - superscript = { - "⁰", - "¹", - "²", - "³", - "⁴", - "⁵", - "⁶", - "⁷", - "⁸", - "⁹", - }, - subscript = { - "₀", - "₁", - "₂", - "₃", - "₄", - "₅", - "₆", - "₇", - "₈", - "₉", - }, - } - local numbers = scripts[script] - local number_string = tostring(number) - local result = "" - for i = 1, #number_string do - local char = number_string:sub(i, i) - local num = tonumber(char) - if num then - result = result .. numbers[num + 1] - else - result = result .. char - end - end - return result + return { + font = wezterm.font(fonts[name].font), + size = fonts[name].size, + } end return M diff --git a/dot_config/wezterm/shortcuts.lua b/dot_config/wezterm/shortcuts.lua index 4939c0c..767b549 100644 --- a/dot_config/wezterm/shortcuts.lua +++ b/dot_config/wezterm/shortcuts.lua @@ -6,51 +6,51 @@ return { { key = "\\", mods = "LEADER", - action = act({ SplitHorizontal = { domain = "CurrentPaneDomain" } }), + action = act.SplitHorizontal({ domain = "CurrentPaneDomain" }), }, -- and 'Minus' to split vertically { key = "-", mods = "LEADER", - action = act({ SplitVertical = { domain = "CurrentPaneDomain" } }), + action = act.SplitVertical({ domain = "CurrentPaneDomain" }), }, -- 'hjkl' to move between panes - { key = "h", mods = "LEADER", action = act({ ActivatePaneDirection = "Left" }) }, - { key = "j", mods = "LEADER", action = act({ ActivatePaneDirection = "Down" }) }, - { key = "k", mods = "LEADER", action = act({ ActivatePaneDirection = "Up" }) }, - { key = "l", mods = "LEADER", action = act({ ActivatePaneDirection = "Right" }) }, + { key = "h", mods = "LEADER", action = act.ActivatePaneDirection("Left")}, + { key = "j", mods = "LEADER", action = act.ActivatePaneDirection("Down")}, + { key = "k", mods = "LEADER", action = act.ActivatePaneDirection("Up") }, + { key = "l", mods = "LEADER", action = act.ActivatePaneDirection("Right") }, -- -- Shift + 'hjkl' to resize panes - { key = "h", mods = "LEADER|SHIFT", action = act({ AdjustPaneSize = { "Left", 5 } }) }, - { key = "j", mods = "LEADER|SHIFT", action = act({ AdjustPaneSize = { "Down", 5 } }) }, - { key = "k", mods = "LEADER|SHIFT", action = act({ AdjustPaneSize = { "Up", 5 } }) }, - { key = "l", mods = "LEADER|SHIFT", action = act({ AdjustPaneSize = { "Right", 5 } }) }, + { key = "h", mods = "LEADER|SHIFT", action = act.AdjustPaneSize({"Left", 5}) }, + { key = "j", mods = "LEADER|SHIFT", action = act.AdjustPaneSize({"Down", 5}) }, + { key = "k", mods = "LEADER|SHIFT", action = act.AdjustPaneSize({"Up", 5}) }, + { key = "l", mods = "LEADER|SHIFT", action = act.AdjustPaneSize({"Right", 5}) }, -- numbers to navigate to tabs - { key = "1", mods = "LEADER", action = act({ ActivateTab = 0 }) }, - { key = "2", mods = "LEADER", action = act({ ActivateTab = 1 }) }, - { key = "3", mods = "LEADER", action = act({ ActivateTab = 2 }) }, - { key = "4", mods = "LEADER", action = act({ ActivateTab = 3 }) }, - { key = "5", mods = "LEADER", action = act({ ActivateTab = 4 }) }, - { key = "6", mods = "LEADER", action = act({ ActivateTab = 5 }) }, - { key = "7", mods = "LEADER", action = act({ ActivateTab = 6 }) }, - { key = "8", mods = "LEADER", action = act({ ActivateTab = 7 }) }, - { key = "9", mods = "LEADER", action = act({ ActivateTab = 8 }) }, - { key = "9", mods = "LEADER", action = act({ ActivateTab = 9 }) }, - { key = "0", mods = "LEADER", action = act({ ActivateTab = -1 }) }, - { key = "1", mods = "SUPER", action = act({ ActivateTab = 0 }) }, - { key = "2", mods = "SUPER", action = act({ ActivateTab = 1 }) }, - { key = "3", mods = "SUPER", action = act({ ActivateTab = 2 }) }, - { key = "4", mods = "SUPER", action = act({ ActivateTab = 3 }) }, - { key = "5", mods = "SUPER", action = act({ ActivateTab = 4 }) }, - { key = "6", mods = "SUPER", action = act({ ActivateTab = 5 }) }, - { key = "7", mods = "SUPER", action = act({ ActivateTab = 6 }) }, - { key = "8", mods = "SUPER", action = act({ ActivateTab = 7 }) }, - { key = "9", mods = "SUPER", action = act({ ActivateTab = 8 }) }, - { key = "9", mods = "SUPER", action = act({ ActivateTab = 9 }) }, - { key = "0", mods = "SUPER", action = act({ ActivateTab = -1 }) }, + { key = "1", mods = "LEADER", action = act.ActivateTab(0) }, + { key = "2", mods = "LEADER", action = act.ActivateTab(1) }, + { key = "3", mods = "LEADER", action = act.ActivateTab(2) }, + { key = "4", mods = "LEADER", action = act.ActivateTab(3) }, + { key = "5", mods = "LEADER", action = act.ActivateTab(4) }, + { key = "6", mods = "LEADER", action = act.ActivateTab(5) }, + { key = "7", mods = "LEADER", action = act.ActivateTab(6) }, + { key = "8", mods = "LEADER", action = act.ActivateTab(7) }, + { key = "9", mods = "LEADER", action = act.ActivateTab(8) }, + { key = "9", mods = "LEADER", action = act.ActivateTab(9) }, + { key = "0", mods = "LEADER", action = act.ActivateTab(-1) }, + { key = "1", mods = "SUPER", action = act.ActivateTab(0) }, + { key = "2", mods = "SUPER", action = act.ActivateTab(1) }, + { key = "3", mods = "SUPER", action = act.ActivateTab(2) }, + { key = "4", mods = "SUPER", action = act.ActivateTab(3) }, + { key = "5", mods = "SUPER", action = act.ActivateTab(4) }, + { key = "6", mods = "SUPER", action = act.ActivateTab(5) }, + { key = "7", mods = "SUPER", action = act.ActivateTab(6) }, + { key = "8", mods = "SUPER", action = act.ActivateTab(7) }, + { key = "9", mods = "SUPER", action = act.ActivateTab(8) }, + { key = "9", mods = "SUPER", action = act.ActivateTab(9) }, + { key = "0", mods = "SUPER", action = act.ActivateTab(-1) }, -- 'c' to create a new tab - { key = "c", mods = "LEADER", action = act({ SpawnTab = "CurrentPaneDomain" }) }, + { key = "c", mods = "LEADER", action = act.SpawnTab("CurrentPaneDomain") }, -- 'x' to kill the current pane - { key = "x", mods = "LEADER", action = act({ CloseCurrentPane = { confirm = true } }) }, + { key = "x", mods = "LEADER", action = act.CloseCurrentPane({ confirm = true }) }, -- 'z' to toggle the zoom for the current pane { key = "z", mods = "LEADER", action = "TogglePaneZoomState" }, -- 'v' to visually select in the current pane diff --git a/dot_config/wezterm/theme.lua b/dot_config/wezterm/theme.lua index 058441c..c089dba 100644 --- a/dot_config/wezterm/theme.lua +++ b/dot_config/wezterm/theme.lua @@ -19,9 +19,14 @@ M.get_custom_colorschemes = function() oledppuccin.tab_bar.background = "#040404" oledppuccin.tab_bar.inactive_tab.bg_color = "#0f0f0f" oledppuccin.tab_bar.new_tab.bg_color = "#080808" + oledppuccin.ansi[6] = "#c6a0f6" + + local latte = wezterm.color.get_builtin_schemes()["Catppuccin Latte"] + latte.ansi[6] = "#8839ef" return { ["OLEDppuccin"] = oledppuccin, + ["Catppuccin Latte"] = latte, } end diff --git a/dot_config/wezterm/tlconfig.lua b/dot_config/wezterm/tlconfig.lua new file mode 100644 index 0000000..a564707 --- /dev/null +++ b/dot_config/wezterm/tlconfig.lua @@ -0,0 +1 @@ +return {} diff --git a/dot_config/wezterm/wezterm.lua b/dot_config/wezterm/wezterm.lua index 26e1b2e..388253b 100644 --- a/dot_config/wezterm/wezterm.lua +++ b/dot_config/wezterm/wezterm.lua @@ -5,6 +5,13 @@ require("bar") local font = fonts.get_font("berkeley") +-- wezterm.GLOBAL.smart_padding = { +-- left = 12, +-- right = 12, +-- top = 0, +-- bottom = 0, +-- } + return { -- keys disable_default_key_bindings = true, @@ -32,12 +39,12 @@ return { light = "Catppuccin Latte", }), -- tab bar - hide_tab_bar_if_only_one_tab = false, tab_bar_at_bottom = true, tab_max_width = 32, use_fancy_tab_bar = false, -- etc. adjust_window_size_when_changing_font_size = false, + use_resize_increments = true, audible_bell = "Disabled", clean_exit_codes = { 130 }, default_cursor_style = "BlinkingBar",