refactor(wezterm): deduplicate format-tab-title event calls
This commit is contained in:
parent
c31a1e9799
commit
cd6716aaf9
@ -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
|
---@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)
|
||||||
log.debug("received event", { prefix = "format-tab-title", ignore_result = true })
|
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) .. " "
|
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
|
if tab.is_active then
|
||||||
bg = color_names.kanagawa.sumiInk0
|
bg = color_names.kanagawa.sumiInk0
|
||||||
fg = color_names.kanagawa.oniViolet
|
fg = color_names.kanagawa.oniViolet
|
||||||
|
@ -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
|
return M
|
||||||
|
Loading…
Reference in New Issue
Block a user