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,11 +1,53 @@
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)
@ -18,7 +60,17 @@ wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_wid
end end
end end
local active_bg = config.resolved_palette.ansi[6] 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 i = (tab.tab_index) % 6
local active_bg = rainbow[i + 1]
local active_fg = colours.background local active_fg = colours.background
local inactive_bg = colours.inactive_tab.bg_color local inactive_bg = colours.inactive_tab.bg_color
local inactive_fg = colours.inactive_tab.fg_color local inactive_fg = colours.inactive_tab.fg_color
@ -42,7 +94,7 @@ wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_wid
elseif tab.tab_index == active_tab_index - 1 then elseif tab.tab_index == active_tab_index - 1 then
s_bg = inactive_bg s_bg = inactive_bg
s_fg = inactive_fg s_fg = inactive_fg
e_bg = active_bg e_bg = rainbow[(i + 1) % 6 + 1]
e_fg = inactive_bg e_fg = inactive_bg
elseif tab.is_active then elseif tab.is_active then
s_bg = active_bg s_bg = active_bg
@ -56,7 +108,8 @@ wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_wid
e_fg = inactive_bg e_fg = inactive_bg
end end
local muxpanes = wezterm.mux.get_tab(tab.tab_id):panes() local tabi = wezterm.mux.get_tab(tab.tab_id)
local muxpanes = tabi:panes()
local count = #muxpanes == 1 and "" or #muxpanes local count = #muxpanes == 1 and "" or #muxpanes
local index = tab.tab_index + 1 .. ": " local index = tab.tab_index + 1 .. ": "
@ -64,7 +117,7 @@ wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_wid
{ Background = { Color = s_bg } }, { Background = { Color = s_bg } },
{ Foreground = { Color = s_fg } }, { Foreground = { Color = s_fg } },
{ {
Text = " " .. index .. tab.active_pane.title .. fonts.numberStyle(count, "superscript") .. " ", Text = " " .. index .. tab.active_pane.title .. numberStyle(count, "superscript") .. " ",
}, },
{ Background = { Color = e_bg } }, { Background = { Color = e_bg } },
{ Foreground = { Color = e_fg } }, { Foreground = { Color = e_fg } },
@ -72,19 +125,40 @@ wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_wid
} }
end) 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 -- 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)
local 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 palette = window:effective_config().resolved_palette
local first_tab_active = window:mux_window():tabs_with_info()[1].is_active
local leader_text = ""
if window:leader_is_active() then leader_text = "" end
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 } },
@ -95,7 +169,7 @@ wezterm.on("update-status", function(window, pane)
{ 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 ") },
})) }))

View file

@ -32,55 +32,9 @@ M.get_font = function(name)
} }
return { return {
font = wezterm.font_with_fallback({ font = wezterm.font(fonts[name].font),
fonts[name].font,
"Apple Color Emoji",
}),
size = fonts[name].size, size = fonts[name].size,
} }
end 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
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",