left-status.lua
1 local wezterm = require('wezterm') 2 3 local nf = wezterm.nerdfonts 4 local M = {} 5 6 local ICON_SEMI_CIRCLE_LEFT = nf.ple_left_half_circle_thick --[[ '' ]] 7 local ICON_SEMI_CIRCLE_RIGHT = nf.ple_right_half_circle_thick --[[ '' ]] 8 local ICON_KEY_TABLE = nf.md_table_key --[[ '' ]] 9 local ICON_KEY = nf.md_key --[[ '' ]] 10 11 local colors = { 12 glyph_semi_circle = { bg = 'rgba(0, 0, 0, 0.4)', fg = '#fab387' }, 13 text = { bg = '#fab387', fg = '#1c1b19' }, 14 } 15 16 local __cells__ = {} 17 18 ---@param text string 19 ---@param fg string 20 ---@param bg string 21 local _push = function(text, fg, bg) 22 table.insert(__cells__, { Foreground = { Color = fg } }) 23 table.insert(__cells__, { Background = { Color = bg } }) 24 table.insert(__cells__, { Attribute = { Intensity = 'Bold' } }) 25 table.insert(__cells__, { Text = text }) 26 end 27 28 M.setup = function() 29 wezterm.on('update-right-status', function(window, _) 30 __cells__ = {} 31 32 local name = window:active_key_table() 33 if name then 34 _push(ICON_SEMI_CIRCLE_LEFT, colors.glyph_semi_circle.fg, colors.glyph_semi_circle.bg) 35 _push(ICON_KEY_TABLE, colors.text.fg, colors.text.bg) 36 _push(' ' .. string.upper(name), colors.text.fg, colors.text.bg) 37 _push(ICON_SEMI_CIRCLE_RIGHT, colors.glyph_semi_circle.fg, colors.glyph_semi_circle.bg) 38 end 39 40 if window:leader_is_active() then 41 _push(ICON_SEMI_CIRCLE_LEFT, colors.glyph_semi_circle.fg, colors.glyph_semi_circle.bg) 42 _push(ICON_KEY, colors.text.fg, colors.text.bg) 43 _push(' ', colors.text.fg, colors.text.bg) 44 _push(ICON_SEMI_CIRCLE_RIGHT, colors.glyph_semi_circle.fg, colors.glyph_semi_circle.bg) 45 end 46 47 window:set_left_status(wezterm.format(__cells__)) 48 end) 49 end 50 51 return M