feat(wezterm): rainbow tabs

This commit is contained in:
winston 2023-01-01 15:36:39 +01:00
parent 7b5f737001
commit 0a2d62a693
Signed by: winston
GPG key ID: 3786770EDBC2B481
6 changed files with 231 additions and 190 deletions

View file

@ -1,102 +1,176 @@
local wezterm = require("wezterm") local wezterm = require("wezterm")
local fonts = require("fonts")
local DIVIDERS = { local DIVIDERS = {
LEFT = utf8.char(0xe0be), LEFT = utf8.char(0xe0be),
RIGHT = utf8.char(0xe0bc), 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 -- custom tab bar
---@diagnostic disable-next-line: unused-local ---@diagnostic disable-next-line: unused-local
wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_width) 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 local active_tab_index = 0
for _, t in ipairs(tabs) do for _, t in ipairs(tabs) do
if t.is_active == true then if t.is_active == true then
active_tab_index = t.tab_index active_tab_index = t.tab_index
end end
end end
local active_bg = config.resolved_palette.ansi[6] local rainbow = {
local active_fg = colours.background config.resolved_palette.ansi[2],
local inactive_bg = colours.inactive_tab.bg_color config.resolved_palette.indexed[16],
local inactive_fg = colours.inactive_tab.fg_color config.resolved_palette.ansi[4],
local new_tab_bg = colours.new_tab.bg_color 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 local s_bg, s_fg, e_bg, e_fg
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 muxpanes = wezterm.mux.get_tab(tab.tab_id):panes() -- the last tab
local count = #muxpanes == 1 and "" or #muxpanes if tab.tab_index == #tabs - 1 then
local index = tab.tab_index + 1 .. ": " 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 { local tabi = wezterm.mux.get_tab(tab.tab_id)
{ Background = { Color = s_bg } }, local muxpanes = tabi:panes()
{ Foreground = { Color = s_fg } }, local count = #muxpanes == 1 and "" or #muxpanes
{ local index = tab.tab_index + 1 .. ": "
Text = " " .. index .. tab.active_pane.title .. fonts.numberStyle(count, "superscript") .. " ",
}, return {
{ Background = { Color = e_bg } }, { Background = { Color = s_bg } },
{ Foreground = { Color = e_fg } }, { Foreground = { Color = s_fg } },
{ Text = DIVIDERS.RIGHT }, {
} 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) end)
-- custom status -- custom status
---@diagnostic disable-next-line: unused-local ---@diagnostic disable-next-line: unused-local
wezterm.on("update-status", function(window, pane) wezterm.on("update-status", function(window, pane)
local palette = window:effective_config().resolved_palette if wezterm.GLOBAL.smart_padding ~= nil then
local firstTabActive = window:mux_window():tabs_with_info()[1].is_active 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 local leader_text = ""
leader_text = "" if window:leader_is_active() then leader_text = "" end
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({ window:set_left_status(wezterm.format({
{ Foreground = { Color = palette.background } }, { Foreground = { Color = palette.background } },
{ Background = { Color = palette.ansi[5] } }, { Background = { Color = palette.ansi[5] } },
{ Text = leader_text }, { Text = leader_text },
{ Background = { Color = divider_bg } }, { Background = { Color = divider_bg } },
{ Foreground = { Color = palette.ansi[5] } }, { Foreground = { Color = palette.ansi[5] } },
{ Text = DIVIDERS.RIGHT }, { Text = DIVIDERS.RIGHT },
})) }))
window:set_right_status(wezterm.format({ window:set_right_status(wezterm.format({
{ Background = { Color = palette.background } }, { Background = { Color = palette.tab_bar.background } },
{ Foreground = { Color = palette.ansi[6] } }, { Foreground = { Color = palette.ansi[6] } },
{ Text = os.date(" %H:%M ") }, { Text = os.date(" %H:%M ") },
})) }))
end) end)

View file

@ -3,84 +3,38 @@ local wezterm = require("wezterm")
local M = {} local M = {}
M.get_font = function(name) M.get_font = function(name)
-- fonts I like, with the settings I prefer -- fonts I like, with the settings I prefer
-- kept seperately from the rest of the config so that I can easily change them -- kept seperately from the rest of the config so that I can easily change them
local fonts = { local fonts = {
berkeley = { berkeley = {
font = { font = {
family = "Berkeley Mono", family = "Berkeley Mono",
weight = "Bold", weight = "Bold",
}, },
size = 16, size = 16,
}, },
comic = { comic = {
font = "Comic Code Ligatures", font = "Comic Code Ligatures",
size = 18, size = 18,
}, },
fantasque = { fantasque = {
font = "Fantasque Sans Mono", font = "Fantasque Sans Mono",
size = 20, size = 20,
}, },
victor = { victor = {
font = { font = {
family = "Victor Mono", family = "Victor Mono",
weight = "DemiBold", weight = "DemiBold",
harfbuzz_features = { "ss02=1" }, harfbuzz_features = { "ss02=1" },
}, },
size = 18, size = 18,
}, },
} }
return { return {
font = wezterm.font_with_fallback({ font = wezterm.font(fonts[name].font),
fonts[name].font, size = fonts[name].size,
"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
end end
return M return M

View file

@ -6,51 +6,51 @@ return {
{ {
key = "\\", key = "\\",
mods = "LEADER", mods = "LEADER",
action = act({ SplitHorizontal = { domain = "CurrentPaneDomain" } }), action = act.SplitHorizontal({ domain = "CurrentPaneDomain" }),
}, },
-- and 'Minus' to split vertically -- and 'Minus' to split vertically
{ {
key = "-", key = "-",
mods = "LEADER", mods = "LEADER",
action = act({ SplitVertical = { domain = "CurrentPaneDomain" } }), action = act.SplitVertical({ domain = "CurrentPaneDomain" }),
}, },
-- 'hjkl' to move between panes -- 'hjkl' to move between panes
{ key = "h", mods = "LEADER", action = act({ ActivatePaneDirection = "Left" }) }, { key = "h", mods = "LEADER", action = act.ActivatePaneDirection("Left")},
{ key = "j", mods = "LEADER", action = act({ ActivatePaneDirection = "Down" }) }, { key = "j", mods = "LEADER", action = act.ActivatePaneDirection("Down")},
{ key = "k", mods = "LEADER", action = act({ ActivatePaneDirection = "Up" }) }, { key = "k", mods = "LEADER", action = act.ActivatePaneDirection("Up") },
{ key = "l", mods = "LEADER", action = act({ ActivatePaneDirection = "Right" }) }, { key = "l", mods = "LEADER", action = act.ActivatePaneDirection("Right") },
-- -- Shift + 'hjkl' to resize panes -- -- Shift + 'hjkl' to resize panes
{ key = "h", mods = "LEADER|SHIFT", action = act({ AdjustPaneSize = { "Left", 5 } }) }, { key = "h", mods = "LEADER|SHIFT", action = act.AdjustPaneSize({"Left", 5}) },
{ key = "j", mods = "LEADER|SHIFT", action = act({ AdjustPaneSize = { "Down", 5 } }) }, { key = "j", mods = "LEADER|SHIFT", action = act.AdjustPaneSize({"Down", 5}) },
{ key = "k", mods = "LEADER|SHIFT", action = act({ AdjustPaneSize = { "Up", 5 } }) }, { key = "k", mods = "LEADER|SHIFT", action = act.AdjustPaneSize({"Up", 5}) },
{ key = "l", mods = "LEADER|SHIFT", action = act({ AdjustPaneSize = { "Right", 5 } }) }, { key = "l", mods = "LEADER|SHIFT", action = act.AdjustPaneSize({"Right", 5}) },
-- numbers to navigate to tabs -- numbers to navigate to tabs
{ key = "1", mods = "LEADER", action = act({ ActivateTab = 0 }) }, { key = "1", mods = "LEADER", action = act.ActivateTab(0) },
{ key = "2", mods = "LEADER", action = act({ ActivateTab = 1 }) }, { key = "2", mods = "LEADER", action = act.ActivateTab(1) },
{ key = "3", mods = "LEADER", action = act({ ActivateTab = 2 }) }, { key = "3", mods = "LEADER", action = act.ActivateTab(2) },
{ key = "4", mods = "LEADER", action = act({ ActivateTab = 3 }) }, { key = "4", mods = "LEADER", action = act.ActivateTab(3) },
{ key = "5", mods = "LEADER", action = act({ ActivateTab = 4 }) }, { key = "5", mods = "LEADER", action = act.ActivateTab(4) },
{ key = "6", mods = "LEADER", action = act({ ActivateTab = 5 }) }, { key = "6", mods = "LEADER", action = act.ActivateTab(5) },
{ key = "7", mods = "LEADER", action = act({ ActivateTab = 6 }) }, { key = "7", mods = "LEADER", action = act.ActivateTab(6) },
{ key = "8", mods = "LEADER", action = act({ ActivateTab = 7 }) }, { key = "8", mods = "LEADER", action = act.ActivateTab(7) },
{ key = "9", mods = "LEADER", action = act({ ActivateTab = 8 }) }, { key = "9", mods = "LEADER", action = act.ActivateTab(8) },
{ key = "9", mods = "LEADER", action = act({ ActivateTab = 9 }) }, { key = "9", mods = "LEADER", action = act.ActivateTab(9) },
{ key = "0", mods = "LEADER", action = act({ ActivateTab = -1 }) }, { key = "0", mods = "LEADER", action = act.ActivateTab(-1) },
{ key = "1", mods = "SUPER", action = act({ ActivateTab = 0 }) }, { key = "1", mods = "SUPER", action = act.ActivateTab(0) },
{ key = "2", mods = "SUPER", action = act({ ActivateTab = 1 }) }, { key = "2", mods = "SUPER", action = act.ActivateTab(1) },
{ key = "3", mods = "SUPER", action = act({ ActivateTab = 2 }) }, { key = "3", mods = "SUPER", action = act.ActivateTab(2) },
{ key = "4", mods = "SUPER", action = act({ ActivateTab = 3 }) }, { key = "4", mods = "SUPER", action = act.ActivateTab(3) },
{ key = "5", mods = "SUPER", action = act({ ActivateTab = 4 }) }, { key = "5", mods = "SUPER", action = act.ActivateTab(4) },
{ key = "6", mods = "SUPER", action = act({ ActivateTab = 5 }) }, { key = "6", mods = "SUPER", action = act.ActivateTab(5) },
{ key = "7", mods = "SUPER", action = act({ ActivateTab = 6 }) }, { key = "7", mods = "SUPER", action = act.ActivateTab(6) },
{ key = "8", mods = "SUPER", action = act({ ActivateTab = 7 }) }, { key = "8", mods = "SUPER", action = act.ActivateTab(7) },
{ key = "9", mods = "SUPER", action = act({ ActivateTab = 8 }) }, { key = "9", mods = "SUPER", action = act.ActivateTab(8) },
{ key = "9", mods = "SUPER", action = act({ ActivateTab = 9 }) }, { key = "9", mods = "SUPER", action = act.ActivateTab(9) },
{ key = "0", mods = "SUPER", action = act({ ActivateTab = -1 }) }, { key = "0", mods = "SUPER", action = act.ActivateTab(-1) },
-- 'c' to create a new tab -- '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 -- '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 -- 'z' to toggle the zoom for the current pane
{ key = "z", mods = "LEADER", action = "TogglePaneZoomState" }, { key = "z", mods = "LEADER", action = "TogglePaneZoomState" },
-- 'v' to visually select in the current pane -- 'v' to visually select in the current pane

View file

@ -19,9 +19,14 @@ M.get_custom_colorschemes = function()
oledppuccin.tab_bar.background = "#040404" oledppuccin.tab_bar.background = "#040404"
oledppuccin.tab_bar.inactive_tab.bg_color = "#0f0f0f" oledppuccin.tab_bar.inactive_tab.bg_color = "#0f0f0f"
oledppuccin.tab_bar.new_tab.bg_color = "#080808" 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 { return {
["OLEDppuccin"] = oledppuccin, ["OLEDppuccin"] = oledppuccin,
["Catppuccin Latte"] = latte,
} }
end end

View file

@ -0,0 +1 @@
return {}

View file

@ -5,6 +5,13 @@ require("bar")
local font = fonts.get_font("berkeley") local font = fonts.get_font("berkeley")
-- wezterm.GLOBAL.smart_padding = {
-- left = 12,
-- right = 12,
-- top = 0,
-- bottom = 0,
-- }
return { return {
-- keys -- keys
disable_default_key_bindings = true, disable_default_key_bindings = true,
@ -32,12 +39,12 @@ return {
light = "Catppuccin Latte", light = "Catppuccin Latte",
}), }),
-- tab bar -- tab bar
hide_tab_bar_if_only_one_tab = false,
tab_bar_at_bottom = true, tab_bar_at_bottom = true,
tab_max_width = 32, tab_max_width = 32,
use_fancy_tab_bar = false, use_fancy_tab_bar = false,
-- etc. -- etc.
adjust_window_size_when_changing_font_size = false, adjust_window_size_when_changing_font_size = false,
use_resize_increments = true,
audible_bell = "Disabled", audible_bell = "Disabled",
clean_exit_codes = { 130 }, clean_exit_codes = { 130 },
default_cursor_style = "BlinkingBar", default_cursor_style = "BlinkingBar",