2 2 local wez
= require 'wezterm' 3 3 local bat
= require 'bugabinga.battery' 5 5 local DELIMITER
= ' · ' 6 -local ai_shell
= require 'bugabinga.ai_shell' 7 6 local palette
= require 'bugabinga.nugu.palette_dark'.palette
8 7 local icon_names
= require 'bugabinga.icons' 84 +local busy_frame = function ()
85 + local frames
= {
'⠋',
'⠙',
'⠹',
'⠸',
'⠼',
'⠴',
'⠦',
'⠧',
'⠇',
'⠏' }
86 + return frames[(
os.
time()
% #frames)
+ 1]
89 +local progress_badge = function ( progress )
90 + if not progress
or progress
== 'None' then return nil end 91 + if progress
== 'Indeterminate' then return busy_frame(), palette.info
end 92 + if type( progress )
== 'table' and progress.Error
~= nil then return '✗', palette.error
end 93 + if type( progress )
== 'table' and progress.Percentage
~= nil then return busy_frame(), palette.info
end 94 + return busy_frame(), palette.info
97 +local pi_state_badge = function ( state )
98 + if state
== 'busy' or state
== 'running' or state
== 'thinking' then return busy_frame(), palette.info
end 99 + if state
== 'done' or state
== 'success' then return '✓', palette.ui.important_local
end 100 + if state
== 'error' or state
== 'failed' then return '✗', palette.error
end 101 + if state
== 'aborted' then return '×', palette.warning
end 102 + if state
== 'waiting' or state
== 'input' or state
== 'needs_input' then return '?', palette.warning
end 106 +local pane_progress = function ( pane )
107 + local ok, progress
= pcall( pane.get_progress, pane )
108 + if ok
then return progress
end 85 112 local short_workspace = function ( name )
86 113 local home
= wez.home_dir
87 114 if home
and name:sub(
1,
#home )
== home
then 88 115 name
= '~' .. name:sub(
#home
+ 1 )
91 - return '…/' .. (basename( name )
or name)
120 + if name:find(
'/',
1,
true )
or name:find(
'\\',
1,
true )
then 121 + return basename( name )
or name
125 + return wez.truncate_right( name,
16 )
96 -local classify_workspace_program = function ( program )
97 - if program
== 'pi' then return 'pi' end 98 - if program
== 'nvim' or program
== 'vim' then return 'nvim' end 99 - if program
== 'git' or program
== 'gh' then return 'git' end 100 - if program
== 'yazi' or program
== 'ranger' or program
== 'lf' then return 'files' end 101 - if program
== 'aerc' or program
== 'neomutt' then return 'mail' end 102 - if program
== 'wthrr' then return 'weather' end 106 130 local workspace_summaries = function ()
107 131 local ok, mux_windows
= pcall( wez.mux.all_windows )
108 132 if not ok
then return {}
end 113 137 if ok_workspace
and workspace
then 114 138 local summary
= summaries[workspace]
115 139 if not summary
then 116 - summary
= {
name = workspace,
windows =
0,
tabs =
0,
panes =
0,
programs = {} }
140 + summary
= {
name = workspace,
windows =
0,
tabs =
0,
panes =
0,
badge =
nil,
badge_color =
nil }
117 141 summaries[workspace]
= summary
119 143 summary.windows
= summary.windows
+ 1 127 151 for _, info
in ipairs( panes )
do 128 152 summary.panes
= summary.panes
+ 1 129 - local program
= detect_program( info.pane )
130 - local class
= classify_workspace_program( program )
132 - summary.programs[class]
= (summary.programs[class]
or 0)
+ 1 153 + local vars
= safe_user_vars( info.pane )
154 + local badge, color
= pi_state_badge( vars.PI_STATE )
155 + if not badge
then badge, color
= progress_badge( pane_progress( info.pane ) )
end 156 + if badge
and (
not summary.badge
or badge
== '✗' or badge
== '?')
then 157 + summary.badge
= badge
158 + summary.badge_color
= color
144 -local append_count = function ( parts, icon, count )
145 - if count
and count
> 0 then 146 - table.
insert( parts, icon
.. (count
> 1 and tostring( count )
or '') )
150 170 local workspace_badge = function ( summary, active )
151 171 local parts
= { short_workspace( summary.name ) }
152 - append_count( parts,
'π', summary.programs.pi )
153 - append_count( parts,
'', summary.programs.nvim )
154 - append_count( parts,
'', summary.programs.git )
155 - append_count( parts,
'', summary.programs.files )
156 - append_count( parts,
'', summary.programs.mail )
157 - append_count( parts,
'', summary.programs.weather )
159 - if #parts
== 1 and active
and summary.tabs
> 1 then 173 + if summary.badge
then 174 + table.
insert( parts, summary.badge )
177 + if active
and summary.tabs
> 1 then 160 178 table.
insert( parts,
tostring( summary.tabs )
.. 't' )
182 200 if shown
> 5 then break end 184 202 local active
= name
== active_workspace
185 - table.
insert( elements, {
Foreground = {
Color = active
and palette.ui.important_local
or palette.ui.minor } } )
203 + table.
insert( elements, {
Foreground = {
Color = summaries[name].badge_color
or (active
and palette.ui.important_local
or palette.ui.minor) } } )
186 204 if active
then table.
insert( elements, {
Attribute = {
Intensity =
'Bold' } } )
end 187 - table.
insert( elements, {
Text = (active
and ' ● ' or ' ○ ')
.. workspace_badge( summaries[name], active ) } )
205 + table.
insert( elements, {
Text = (active
and ' ● ' or ' ○ ')
.. workspace_badge( summaries[name], active )
.. ' ' } )
188 206 table.
insert( elements, {
Attribute = {
Intensity =
'Normal' } } )
191 209 if #ordered
> 5 then 192 210 table.
insert( elements, {
Foreground = {
Color = palette.ui.minor } } )
193 - table.
insert( elements, {
Text =
' +' .. tostring(
#ordered
- 5 ) } )
211 + table.
insert( elements, {
Text =
' +' .. tostring(
#ordered
- 5 )
.. ' ' } )
214 + table.
insert( elements, {
Text =
' ' } )
199 219 local tab_title = function ( tab )
200 220 if tab.tab_title
and #tab.tab_title
> 0 then 201 221 local explicit_program
= detect_program_from_title( tab.tab_title )
202 - return tab.tab_title, program_icon( explicit_program )
222 + return tab.tab_title, program_icon( explicit_program ), explicit_program
204 224 local vars
= tab.active_pane.user_vars
or {}
205 225 local program
= normalize_program( first_command( vars.WEZTERM_PROG ) )
206 226 or detect_program_from_title( tab.active_pane.title )
207 227 or normalize_program( tab.active_pane.foreground_process_name )
209 - return program, program_icon( program )
229 + return program, program_icon( program ), program
232 +local noisy_unseen_programs
= {
242 +local mux_tab_label = function ( mux_tab )
243 + local explicit_title
= nil 244 + local ok_title, title
= pcall(
function ()
return mux_tab:get_title()
end )
245 + if ok_title
and title
and title
~= '' then explicit_title
= title
end 247 + local ok_pane, active_pane
= pcall(
function ()
return mux_tab:active_pane()
end )
248 + local program
= nil 249 + local state_badge
= nil 250 + local state_badge_color
= nil 251 + local has_unseen_output
= false 253 + if ok_pane
and active_pane
then 254 + program
= detect_program( active_pane )
255 + local vars
= safe_user_vars( active_pane )
256 + local progress
= pane_progress( active_pane )
257 + local pi_badge, pi_color
= pi_state_badge( vars.PI_STATE )
258 + local progress_state_badge, progress_color
= progress_badge( progress )
259 + state_badge
= pi_badge
or progress_state_badge
260 + state_badge_color
= pi_color
or progress_color
263 + if not noisy_unseen_programs[program]
then 264 + local ok_panes, panes
= pcall(
function ()
return mux_tab:panes_with_info()
end )
266 + for _, info
in ipairs( panes )
do 267 + local ok_unseen, unseen
= pcall(
function ()
return info.pane:has_unseen_output()
end )
268 + if ok_unseen
and unseen
then 269 + has_unseen_output
= true 276 + local label
= explicit_title
or program
or 'nu' 277 + return wez.truncate_right( label,
12 ), program_icon( program
or detect_program_from_title( label ) ), state_badge, state_badge_color, has_unseen_output
280 +local text_width = function ( text )
281 + return wez.column_width( text )
284 +local render_fake_tab = function ( elements, tab, compact )
285 + local bg
= tab.active
and palette.ui.focus
or palette.ui.backdrop
286 + local fg
= tab.active
and palette.ui.backdrop
or palette.ui.minor
288 + if tab.state_badge_color
and not tab.active
then 289 + bg
= tab.state_badge_color
290 + fg
= palette.content.backdrop
291 + elseif tab.has_unseen_output
and not tab.active
then 292 + bg
= palette.warning
293 + fg
= palette.content.backdrop
296 + local suffix
= tab.state_badge
and (
' ' .. tab.state_badge)
or (tab.has_unseen_output
and ' !' or '')
298 + if compact
and not tab.active
then 299 + text
= string.
format(
' %d %s%s ', tab.index
+ 1, tab.icon, suffix )
301 + text
= string.
format(
' %d %s %s%s ', tab.index
+ 1, tab.icon, tab.label, suffix )
304 + table.
insert( elements, {
Background = {
Color = bg } } )
305 + table.
insert( elements, {
Foreground = {
Color = fg } } )
306 + if tab.active
then table.
insert( elements, {
Attribute = {
Intensity =
'Bold' } } )
end 307 + table.
insert( elements, {
Text = text } )
308 + table.
insert( elements, {
Attribute = {
Intensity =
'Normal' } } )
309 + table.
insert( elements, {
Background = {
Color = palette.content.backdrop } } )
310 + table.
insert( elements, {
Text =
' ' } )
312 + return text_width( text )
+ 1 315 +local fake_tabs = function ( window, max_width )
316 + local ok_window, mux_window
= pcall(
function ()
return window:mux_window()
end )
317 + if not ok_window
or not mux_window
then return {}
end 319 + local ok_tabs, tabs
= pcall(
function ()
return mux_window:tabs_with_info()
end )
320 + if not ok_tabs
then return {}
end 322 + local tab_models
= {}
323 + local full_width
= 0 324 + for _, info
in ipairs( tabs )
do 325 + local label, icon, state_badge, state_badge_color, has_unseen_output
= mux_tab_label( info.tab )
327 + index = info.index,
328 + active = info.is_active,
331 + state_badge = state_badge,
332 + state_badge_color = state_badge_color,
333 + has_unseen_output = has_unseen_output,
335 + local suffix
= model.state_badge
and (
' ' .. model.state_badge)
or (model.has_unseen_output
and ' !' or '')
336 + full_width
= full_width
+ text_width(
string.
format(
' %d %s %s%s ', model.index
+ 1, model.icon, model.label, suffix ) )
+ 1 337 + table.
insert( tab_models, model )
340 + local compact
= full_width
> max_width
341 + local active_index
= 1 342 + for i, model
in ipairs( tab_models )
do 343 + if model.active
then 349 + local selected
= { [active_index] =
true }
350 + local suffix
= tab_models[active_index].state_badge
and (
' ' .. tab_models[active_index].state_badge)
351 + or (tab_models[active_index].has_unseen_output
and ' !' or '')
352 + local active_text
= string.
format(
' %d %s %s%s ', tab_models[active_index].index
+ 1, tab_models[active_index].icon, tab_models[active_index].label, suffix )
353 + local used
= text_width( active_text )
+ 1 354 + local overflow_reserve
= 4 355 + local budget
= math.
max( used, max_width
- overflow_reserve )
357 + local left
= active_index
- 1 358 + local right
= active_index
+ 1 359 + while left
>= 1 or right
<= #tab_models
do 360 + local progressed
= false 362 + for _, i
in ipairs { right, left }
do 363 + local model
= tab_models[i]
365 + local s
= model.state_badge
and (
' ' .. model.state_badge)
or (model.has_unseen_output
and ' !' or '')
366 + local text
= compact
367 + and string.
format(
' %d %s%s ', model.index
+ 1, model.icon, s )
368 + or string.
format(
' %d %s %s%s ', model.index
+ 1, model.icon, model.label, s )
369 + local width
= text_width( text )
+ 1 370 + if used
+ width
<= budget
then 372 + used
= used
+ width
380 + if not progressed
and used
>= budget
then break end 383 + local rendered
= {}
385 + for i, model
in ipairs( tab_models )
do 386 + if selected[i]
then 387 + table.
insert( rendered, model )
389 + hidden
= hidden
+ 1 393 + local elements
= {}
395 + table.
insert( elements, {
Foreground = {
Color = palette.ui.minor } } )
396 + table.
insert( elements, {
Text =
'+' .. tostring( hidden )
.. ' ' } )
399 + for _, model
in ipairs( rendered )
do 400 + render_fake_tab( elements, model, compact )
212 406 wez.on(
'format-tab-title',
function ( tab, tabs, panes, config, hover, max_width )
213 - local title, icon
= tab_title( tab )
407 + local title, icon, program
= tab_title( tab )
408 + local pi_badge, pi_badge_color
= pi_state_badge( (tab.active_pane.user_vars
or {}).PI_STATE )
409 + local active_progress_badge, active_progress_color
= progress_badge( tab.active_pane.progress )
410 + local state_badge
= pi_badge
or active_progress_badge
411 + local state_badge_color
= pi_badge_color
or active_progress_color
214 412 local has_unseen_output
= false 215 - for _, pane_info
in ipairs( tab.panes
or {} )
do 216 - if pane_info.has_unseen_output
then 217 - has_unseen_output
= true 413 + if not noisy_unseen_programs[program]
then 414 + for _, pane_info
in ipairs( tab.panes
or {} )
do 415 + if pane_info.has_unseen_output
then 416 + has_unseen_output
= true 224 424 if tab.is_active
then 225 425 bg
= palette.ui.focus
226 426 fg
= palette.ui.backdrop
427 + elseif state_badge_color
then 428 + bg
= state_badge_color
429 + fg
= palette.content.backdrop
227 430 elseif has_unseen_output
then 228 431 bg
= palette.warning
229 432 fg
= palette.content.backdrop
236 439 fg
= palette.ui.minor
239 - local suffix
= has_unseen_output
and ' !' or '' 240 - local text
= string.
format(
' %d %s %s%s ', tab.tab_index
+ 1, icon, title, suffix )
442 + local suffix
= state_badge
and (
' ' .. state_badge)
or (has_unseen_output
and ' !' or '')
443 + local text
= string.
format(
' %d %s %s%s ', tab.tab_index
+ 1, icon, title, suffix )
241 444 text
= wez.truncate_right( text,
math.
max(
1, max_width ) )
267 470 local pane_domain_ok, pane_domain
= pcall( pane.get_domain_name, pane )
268 471 if not pane_domain_ok
then return end 270 - local time
= wez.time.now():format
'%H:%M' 271 - local ai_status
= ai_shell.get_status( window )
272 - local status
= { time, ai_status, leader, }
275 475 local prog
= detect_program( pane )
276 - if prog
== 'pi' then 277 - table.
insert( status, wez.format {
278 - {
Foreground = {
Color =
'#d151d1' } },
279 - {
Attribute = {
Intensity =
'Bold' } },
282 - elseif prog
and prog
~= 'nu' then 476 + if prog
and prog
~= 'nu' and prog
~= 'pi' then 283 477 table.
insert( status, program_icon( prog )
.. ' ' .. prog )
287 - table.
insert( status, key_table )
289 480 if zoomed_state
then 290 481 table.
insert( status, zoomed_state )
294 485 table.
insert( status,
'@' .. pane_domain )
297 - local right_elements
= {
298 - {
Text =
table.
concat( status, DELIMITER ), },
301 - table.
insert( right_elements, {
Text = DELIMITER } )
302 - table.
insert( right_elements, {
Background = {
Color = palette.error, }, } )
303 - table.
insert( right_elements, {
Foreground = {
Color = palette.ui.backdrop, }, } )
304 - table.
insert( right_elements, {
Text =
' ' .. key_table
.. ' ', } )
488 + local status_parts
= {}
489 + for _, value
in ipairs( status )
do 490 + if value
and value
~= '' then table.
insert( status_parts, value )
end 493 + local right_elements
= {}
494 + local status_text
= table.
concat( status_parts, DELIMITER )
495 + if status_text
~= '' then 496 + table.
insert( right_elements, {
Foreground = {
Color = palette.ui.minor } } )
497 + table.
insert( right_elements, {
Text = status_text
.. ' ' } )
499 + local pane_dims
= pane:get_dimensions()
500 + local tab_budget
= math.
max(
24,
math.
floor( pane_dims.cols
* 0.45 ) )
501 + if status_text
~= '' then tab_budget
= tab_budget
- text_width( status_text )
- 2 end 502 + for _, element
in ipairs( fake_tabs( window, tab_budget ) )
do 503 + table.
insert( right_elements, element )
307 506 window:set_right_status( wez.format( right_elements ) )
310 509 battery_icons
= battery_icons
.. ' ' 313 - local left_elements
= {
315 - {
Text = battery_icons },
317 - for _, element
in ipairs( workspace_hud( current_workspace ) )
do 318 - table.
insert( left_elements, element )
512 + local left_elements
= {}
513 + if key_table
or leader
then 514 + local mode_text
= key_table
or 'LEADER' 516 + {
Background = {
Color = palette.error } },
517 + {
Foreground = {
Color = palette.ui.backdrop } },
518 + {
Attribute = {
Intensity =
'Bold' } },
519 + {
Text =
' ' .. mode_text
.. ' ' },
525 + {
Text = battery_icons },
527 + for _, element
in ipairs( workspace_hud( current_workspace ) )
do 528 + table.
insert( left_elements, element )
321 532 window:set_left_status( wez.format( left_elements ) )
327 538 cfg.hide_tab_bar_if_only_one_tab
= false 328 539 cfg.use_fancy_tab_bar
= false 329 540 cfg.tab_max_width
= 32 541 + cfg.show_tabs_in_tab_bar
= false 542 + cfg.show_new_tab_button_in_tab_bar
= false 330 543 cfg.tab_bar_at_bottom
= true 331 544 cfg.status_update_interval
= 1000