Open csdvrx opened 1 year ago
Coming from iTerm2, I was also missing this functionality.
I'm new to Wezterm and Lua so not sure if this is the optimal solution, but I managed to get it working with the configuration below.
Usage:
Result:
WEZTERM_CONFIG_FILE=color.lua wezterm start
local wezterm = require 'wezterm'
local config = wezterm.config_builder()
local act = wezterm.action
tab_color = {}
-- https://wezfurlong.org/wezterm/config/lua/window-events/format-tab-title.html
wezterm.on(
'format-tab-title',
function(tab, tabs, panes, config, hover, max_width)
local title = tab.tab_title
-- if the tab title is explicitly set, take that
if not (title and #title > 0) then
title = tab.active_pane.title
end
local tab_id = tab.tab_id
if tab_color[tab_id] ~= nil then
return {
{ Background = { Color = tab_color[tab_id] } },
{ Text = title },
}
end
return title
end
)
config.keys = {
{ key = '1', mods = 'ALT', action = act.EmitEvent('toggle-tab-blue') },
{ key = '2', mods = 'ALT', action = act.EmitEvent('toggle-tab-red') },
{ key = '3', mods = 'ALT', action = act.EmitEvent('toggle-tab-green') },
{ key = '4', mods = 'ALT', action = act.EmitEvent('toggle-tab-orange') },
{ key = '5', mods = 'ALT', action = act.EmitEvent('toggle-tab-yellow') },
{ key = '6', mods = 'ALT', action = act.EmitEvent('toggle-tab-purple') },
{ key = '0', mods = 'ALT', action = act.EmitEvent('toggle-tab-nil') },
}
function set_tab_color(color)
function func(window, pane)
local tab_id = pane:tab():tab_id()
tab_color[tab_id] = color
end
return func
end
wezterm.on('toggle-tab-blue', set_tab_color("blue"))
wezterm.on('toggle-tab-red', set_tab_color("red"))
wezterm.on('toggle-tab-green', set_tab_color("green"))
wezterm.on('toggle-tab-orange', set_tab_color("orange"))
wezterm.on('toggle-tab-yellow', set_tab_color("yellow"))
wezterm.on('toggle-tab-purple', set_tab_color("purple"))
wezterm.on('toggle-tab-nil', set_tab_color(nil))
return config
Is your feature request related to a problem? Please describe.
A typical problem when working with multiple remote sessions is figuring out which is which: using the hostname in the title helps, but color cues can be processed faster.
Describe the solution you'd like
Windows Terminal support colors per tab: one color can be used for ssh to one host, another color for local terminals etc.
I would suggest the exact same functionality in wezterm, topped with hotkeys toggle so that for example Alt-R could make the background of the current tab red, Alt-B could make it blue etc.
Default colors could also be assigned per domain in the configuration, to be used at startup: either each domain could have its colors defined (witth a different domain per remote host), or SpawnCommandInNewTab could accept arguments to assign a given color to the new tab.
Describe alternatives you've considered
Having hostnames in the tab title creates more cognitive load, and is not robust: it can be changed by applications using escape codes.
Having separate wezterm windows for each remote host is unpractical
Additional context
This image illustrates how this concept works in Windows Terminal:
If more ubuntu tabs were created, each tab would have a blue background.
The current active tab can still be determined by using a different foreground color, a thin line of a different color around it, or a different font (ex: bold)