refactor(wezterm): deduplicate format-tab-title event calls

This commit is contained in:
Price Hiller 2023-08-31 22:42:54 -05:00
parent c31a1e9799
commit cd6716aaf9
Signed by: Price
SSH Key Fingerprint: SHA256:Y4S9ZzYphRn1W1kbJerJFO6GGsfu9O70VaBSxJO7dF8
2 changed files with 8 additions and 46 deletions

View File

@ -13,6 +13,10 @@ local edges = {
},
}
-- This function returns the suggested title for a tab.
-- It prefers the title that was set via `tab:set_title()`
-- or `wezterm cli set-tab-title`, but falls back to the
-- title of the active pane in that tab.
---@diagnostic disable-next-line: unused-local
wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_width)
log.debug("received event", { prefix = "format-tab-title", ignore_result = true })
@ -36,6 +40,10 @@ wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_wid
local title = " " .. wezterm.truncate_right(tab_title(tab), max_width - 2) .. " "
if title:match("^%s+$") then
title = " N/A "
end
if tab.is_active then
bg = color_names.kanagawa.sumiInk0
fg = color_names.kanagawa.oniViolet

View File

@ -138,50 +138,4 @@ local edges = {
},
}
---@diagnostic disable-next-line: unused-local
wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_width)
local function tab_title(tab_info)
local title = tab_info.tab_title
-- if the tab title is explicitly set, take that
if title and #title > 0 then
return title
end
-- Otherwise, use the title from the active pane
-- in that tab
return tab_info.active_pane.title
end
local bg = color_names.kanagawa.sumiInk0
local fg = color_names.kanagawa.sumiInk4
local edge_bg = color_names.kanagawa.sumiInk0
local edge_fg = color_names.kanagawa.oniViolet
local title = " " .. wezterm.truncate_right(tab_title(tab), max_width - 2) .. " "
if title:match("^%s+$") then
title = " N/A "
end
if tab.is_active then
bg = color_names.kanagawa.sumiInk0
fg = color_names.kanagawa.oniViolet
elseif hover then
fg = color_names.kanagawa.peachRed
end
return {
{ Background = { Color = edge_bg } },
{ Foreground = { Color = edge_fg } },
{ Background = { Color = bg } },
{ Foreground = { Color = fg } },
{ Text = title },
{ Background = { Color = edge_bg } },
{ Foreground = { Color = fg } },
{ Text = edges.empty.left },
{ Background = { Color = bg } },
{ Foreground = { Color = fg } },
}
end)
return M