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 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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

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

View file

@ -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",