Skip to content

Commit

Permalink
feat: left status pill to show when leader-key/keytable is active
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinSilvester committed May 17, 2024
1 parent 3c2e296 commit 6cead70
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
51 changes: 51 additions & 0 deletions events/left-status.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
local wezterm = require('wezterm')

local nf = wezterm.nerdfonts
local M = {}

local GLYPH_SEMI_CIRCLE_LEFT = nf.ple_left_half_circle_thick --[[ '' ]]
local GLYPH_SEMI_CIRCLE_RIGHT = nf.ple_right_half_circle_thick --[[ '' ]]
local GLYPH_KEY_TABLE = nf.md_table_key --[[ '󱏅' ]]
local GLYPH_KEY = nf.md_key --[[ '󰌆' ]]

local colors = {
glyph_semi_circle = { bg = 'rgba(0, 0, 0, 0.4)', fg = '#fab387' },
text = { bg = '#fab387', fg = '#1c1b19' },
}

local __cells__ = {}

---@param text string
---@param fg string
---@param bg string
local _push = function(text, fg, bg)
table.insert(__cells__, { Foreground = { Color = fg } })
table.insert(__cells__, { Background = { Color = bg } })
table.insert(__cells__, { Attribute = { Intensity = 'Bold' } })
table.insert(__cells__, { Text = text })
end

M.setup = function()
wezterm.on('update-right-status', function(window, _pane)
__cells__ = {}

local name = window:active_key_table()
if name then
_push(GLYPH_SEMI_CIRCLE_LEFT, colors.glyph_semi_circle.fg, colors.glyph_semi_circle.bg)
_push(GLYPH_KEY_TABLE, colors.text.fg, colors.text.bg)
_push(' ' .. string.upper(name), colors.text.fg, colors.text.bg)
_push(GLYPH_SEMI_CIRCLE_RIGHT, colors.glyph_semi_circle.fg, colors.glyph_semi_circle.bg)
end

if window:leader_is_active() then
_push(GLYPH_SEMI_CIRCLE_LEFT, colors.glyph_semi_circle.fg, colors.glyph_semi_circle.bg)
_push(GLYPH_KEY, colors.text.fg, colors.text.bg)
_push(' ', colors.text.fg, colors.text.bg)
_push(GLYPH_SEMI_CIRCLE_RIGHT, colors.glyph_semi_circle.fg, colors.glyph_semi_circle.bg)
end

window:set_left_status(wezterm.format(__cells__))
end)
end

return M
1 change: 1 addition & 0 deletions wezterm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local Config = require('config')
require('utils.backdrops'):set_files():random()

require('events.right-status').setup()
require('events.left-status').setup()
require('events.tab-title').setup()
require('events.new-tab-button').setup()

Expand Down

0 comments on commit 6cead70

Please sign in to comment.