nixos/config/wezterm/status.lua

71 lines
2.1 KiB
Lua
Raw Normal View History

local wezterm = require("wezterm")
wezterm.on("update-right-status", function(window, pane)
-- Each element holds the text for a cell in a "powerline" style << fade
local cells = {}
-- I like my date/time in this style: "Wed Mar 3 08:14"
local date = wezterm.strftime("%a %b %-d %H:%M")
table.insert(cells, date)
-- Get current hostname to track which device I'm on
table.insert(cells, wezterm.hostname())
-- An entry for each battery (typically 0 or 1 battery)
for _, b in ipairs(wezterm.battery_info()) do
table.insert(cells, string.format("%.0f%%", b.state_of_charge * 100))
end
-- WIP key table code - not yet used
local name = window:active_key_table()
if name then
name = "TABLE: " .. name
table.insert(cells, name)
end
-- The powerline < symbol
local LEFT_ARROW = utf8.char(0xe0b3)
-- The filled in variant of the < symbol
local SOLID_LEFT_ARROW = utf8.char(0xe0b2)
-- Color palette for the backgrounds of each cell
local colors = wezterm.color.gradient({
colors = {
"#333333",
"#926ee4",
-- "#9ccfd8",
},
}, #cells + 1)
-- Foreground color for the text across the fade
local text_fg = wezterm.color.get_builtin_schemes()["duskfox"].foreground
-- The elements to be formatted
local elements = {}
-- How many cells have been formatted
local num_cells = 0
-- Translate a cell into elements
local function push(text, is_last)
local cell_no = num_cells + 1
table.insert(elements, { Foreground = { Color = text_fg } })
table.insert(elements, { Background = { Color = colors[cell_no + 1] } })
table.insert(elements, { Text = " " .. text .. " " })
if not is_last then
table.insert(elements, { Foreground = { Color = colors[cell_no + 2] } })
table.insert(elements, { Text = SOLID_LEFT_ARROW })
end
num_cells = num_cells + 1
end
table.insert(elements, { Foreground = { Color = colors[num_cells + 2] } })
table.insert(elements, { Background = { Color = colors[1] } })
table.insert(elements, { Text = SOLID_LEFT_ARROW })
while #cells > 0 do
local cell = table.remove(cells, 1)
push(cell, #cells == 0)
end
window:set_right_status(wezterm.format(elements))
end)