2023-02-19 12:16:22 +00:00
|
|
|
local wezterm = require "wezterm"
|
2023-02-14 12:01:37 +00:00
|
|
|
|
2023-02-19 12:16:22 +00:00
|
|
|
-- The filled in variant of the powerline ( symbol
|
|
|
|
local SOLID_LEFT_SEP = require("utf8").char(0xe0b6)
|
2023-02-14 18:00:43 +00:00
|
|
|
|
2023-02-19 12:16:22 +00:00
|
|
|
local M = {}
|
|
|
|
M.setup = function(scheme)
|
|
|
|
wezterm.on("update-right-status", function(window, _)
|
|
|
|
-- Each element holds the text for a cell in a "powerline" style << fade
|
|
|
|
local cells = {}
|
2023-02-14 12:01:37 +00:00
|
|
|
|
2023-02-19 12:16:22 +00:00
|
|
|
-- Show current active key table
|
|
|
|
local name = window:active_key_table()
|
|
|
|
if name then
|
|
|
|
name = "TABLE: " .. name
|
|
|
|
table.insert(cells, name)
|
|
|
|
end
|
2023-02-14 18:00:43 +00:00
|
|
|
|
2023-02-19 12:16:22 +00:00
|
|
|
-- I like my date/time in this style: "Wed Mar 3 08:14"
|
|
|
|
-- local date = wezterm.strftime("%a %b %-d %H:%M")
|
|
|
|
local date = wezterm.strftime "%Y-%m-%d"
|
|
|
|
table.insert(cells, date)
|
|
|
|
local time = wezterm.strftime "%H:%M"
|
|
|
|
table.insert(cells, time)
|
2023-02-14 12:01:37 +00:00
|
|
|
|
2023-02-19 12:16:22 +00:00
|
|
|
-- Get current hostname to track which device I'm on
|
|
|
|
table.insert(cells, wezterm.hostname())
|
2023-02-14 15:11:10 +00:00
|
|
|
|
2023-02-19 12:16:22 +00:00
|
|
|
-- 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
|
2023-02-14 12:01:37 +00:00
|
|
|
|
2023-02-19 12:16:22 +00:00
|
|
|
-- Foreground color for the text across the fade
|
|
|
|
local text_fg = scheme.tab_bar.active_tab.fg_color
|
|
|
|
-- Tab bar background to complete fade
|
|
|
|
local tab_bar_bg = scheme.tab_bar.background
|
|
|
|
-- Color palette for the backgrounds of each cell
|
|
|
|
local colours = wezterm.color.gradient({
|
|
|
|
colors = {
|
2023-02-19 12:18:43 +00:00
|
|
|
scheme.tab_bar.new_tab.bg_color,
|
2023-02-19 12:16:22 +00:00
|
|
|
scheme.tab_bar.active_tab.bg_color,
|
|
|
|
},
|
|
|
|
}, #cells + 1)
|
2023-02-14 12:01:37 +00:00
|
|
|
|
2023-02-19 12:16:22 +00:00
|
|
|
-- The elements to be formatted
|
|
|
|
local elements = {}
|
|
|
|
-- How many cells have been formatted
|
|
|
|
local num_cells = 0
|
2023-02-14 12:01:37 +00:00
|
|
|
|
2023-02-19 12:16:22 +00:00
|
|
|
-- 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 = colours[cell_no + 1] } })
|
|
|
|
table.insert(elements, { Text = text })
|
|
|
|
if not is_last then
|
|
|
|
table.insert(elements, { Foreground = { Color = colours[cell_no + 2] } })
|
|
|
|
table.insert(elements, { Text = " " .. SOLID_LEFT_SEP })
|
|
|
|
end
|
|
|
|
num_cells = num_cells + 1
|
|
|
|
end
|
2023-02-14 12:01:37 +00:00
|
|
|
|
2023-02-19 12:16:22 +00:00
|
|
|
table.insert(elements, { Foreground = { Color = colours[num_cells + 2] } })
|
|
|
|
table.insert(elements, { Background = { Color = tab_bar_bg } })
|
|
|
|
table.insert(elements, { Text = SOLID_LEFT_SEP })
|
|
|
|
while #cells > 0 do
|
|
|
|
local cell = table.remove(cells, 1)
|
|
|
|
push(cell, #cells == 0)
|
|
|
|
end
|
2023-02-15 10:20:56 +00:00
|
|
|
|
2023-02-28 17:35:00 +00:00
|
|
|
if os.getenv("XDG_CURRENT_DESKTOP") ~= "i3" then
|
|
|
|
window:set_right_status(wezterm.format(elements))
|
|
|
|
end
|
2023-02-19 12:16:22 +00:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
return M
|