8 8 package.
loaded[
'bugabinga.apps']
= nil 9 9 local apps
= require 'bugabinga.apps' 11 -local MAX_TAB_LABEL_WIDTH
= 172 11 +local FALLBACK_TAB_PROGRAM
= 'nu' 12 12 local WORKSPACE_SUMMARY_TTL_SECONDS
= 2.0 13 13 local PALETTE_REFRESH_TTL_SECONDS
= 2.0 264 264 local domain_hud = function ( domain )
265 - if not domain
or domain
== 'local' or domain
== 'Local' then return {}
end 265 + local label
= domain
or 'local' 267 266 local color
= palette.ui.important_local
268 - if domain:find(
'^scope:',
1,
false )
then color
= palette.warning
end 268 + if not domain
or domain
== 'local' or domain
== 'Local' then 270 + color
= palette.warning
271 + elseif domain:find(
'^WSL:',
1,
false )
then 272 + label
= domain:gsub(
'^WSL:',
'WSL ' )
273 + elseif domain:find(
'^scope:',
1,
false )
then 274 + color
= palette.warning
271 278 {
Foreground = {
Color = color } },
272 279 {
Attribute = {
Intensity =
'Bold' } },
273 - {
Text =
'@' .. domain
.. ' ' },
280 + {
Text =
'@' .. label
.. ' ' },
274 281 {
Attribute = {
Intensity =
'Normal' } },
278 -local tab_label = function ( program, detail, max_width )
279 - program
= apps.normalize( program )
or 'nu' 280 - local base
= apps.label( program )
or apps.label(
'nu' )
281 - local label
= detail
and (base
.. ' · ' .. detail)
or base
282 - return wez.truncate_right( label, max_width
or MAX_TAB_LABEL_WIDTH )
285 +local root_or_nil = function ( program )
286 + program
= apps.normalize( program )
287 + if apps.is_root( program )
then return program
end 285 -local collapse_duplicate_suffix = function ( title )
286 - local head, tail
= title:match(
'^(.*)%s+[-–—:]%s+(.+)$' )
287 - if not head
or not tail
then return title
end 291 +local tab_label = function ( program, detail )
292 + program
= root_or_nil( program )
or FALLBACK_TAB_PROGRAM
293 + local base
= apps.label( program )
or apps.label( FALLBACK_TAB_PROGRAM )
294 + return detail
and (base
.. ' · ' .. detail)
or base
289 - local compact_head
= head:lower():gsub(
'[^%w]',
'' )
290 - local compact_tail
= tail:lower():gsub(
'[^%w]',
'' )
291 - if compact_tail
~= '' and compact_head
== compact_tail
then return head
end 297 +local title_program = function ( title )
298 + title
= strip_activity_marker( title )
299 + if not title
then return nil end 300 + if title:sub(
1,
#'π' )
== 'π' then return 'pi' end 304 + return root_or_nil( title:match(
'^([%w%._%-]+)' ) )
295 307 local title_detail = function ( title, program, include_shell_titles )
296 308 title
= strip_activity_marker( title )
297 309 if not title
then return nil end 301 311 local detail
= apps.title_detail( title, program, include_shell_titles )
or title
302 312 detail
= strip_activity_marker( detail )
303 - detail
= collapse_duplicate_suffix( detail )
304 313 detail
= apps.clean_title( detail )
305 314 if not detail
or apps.normalize( detail )
== apps.normalize( program )
then return nil end 312 321 visit = function ( node )
313 322 if detected
or type( node )
~= 'table' then return end 316 324 for _, key
in ipairs {
'name',
'executable' }
do 317 - if node[key]
then table.
insert( tokens,
tostring( node[key] ) )
end 325 + detected
= detected
or root_or_nil( node[key] )
319 327 if type( node.argv )
== 'table' then 320 - for _, arg
in ipairs( node.argv )
do table.
insert( tokens,
tostring( arg ) )
end 323 - for _, token
in ipairs( tokens )
do 324 - local normalized
= apps.normalize( token )
325 - if apps.is_root( normalized )
then 326 - detected
= normalized
331 - local lower
= token:lower()
332 - if lower:find(
'/',
1,
true )
or lower:find(
'\\',
1,
true )
then 333 - for _, program
in ipairs {
'codex',
'claude',
'opencode',
'pi' }
do 334 - if lower:find( program,
1,
true )
then 328 + for _, arg
in ipairs( node.argv )
do 329 + detected
= detected
or root_or_nil( arg )
332 + if detected
then return end 342 334 if type( node.children )
== 'table' then 343 335 for _, child
in pairs( node.children )
do visit( child )
end 350 -local strong_title_program = function ( title )
351 - title
= apps.clean_title( title )
352 - if not title
then return nil,
false end 354 - if title:sub(
1,
#'π' )
== 'π' then return 'pi',
false end 356 - local _, had_marker
= strip_activity_marker( title )
357 - if had_marker
then return 'claude',
true end 362 342 local process_info_program = function ( tab )
363 343 local pane_id
= tab.active_pane
and tab.active_pane.pane_id
364 344 if not pane_id
then return nil end 369 349 local ok_info, info
= pcall( mux_pane.get_foreground_process_info, mux_pane )
370 350 if not ok_info
or not info
then return nil end 372 - local program
= detect_from_process_info( info )
373 - if apps.is_root( program )
then return program
end 352 + return detect_from_process_info( info )
377 355 local tab_title = function ( tab )
378 356 local id
= tab.tab_id
or tab.tab_index
379 357 local explicit_title
= apps.clean_title( tab.tab_title )
380 358 local pane_title
= apps.clean_title( tab.active_pane.title )
359 + local display_title
= explicit_title
or pane_title
381 360 local vars
= tab.active_pane.user_vars
or {}
382 - local clean_pane_title
= strip_activity_marker( pane_title )
383 - local clean_explicit_title
= strip_activity_marker( explicit_title )
384 - local from_command
= apps.detect_from_commandline( vars.WEZTERM_PROG )
385 - local from_info
= process_info_program( tab )
386 - local from_process
= apps.normalize( tab.active_pane.foreground_process_name )
387 - if not apps.is_root( from_process )
then from_process
= nil end 388 - local from_explicit_title, explicit_weak
= strong_title_program( explicit_title )
389 - local from_pane_title, pane_weak
= strong_title_program( pane_title )
390 - local from_title
= from_explicit_title
or from_pane_title
391 - local weak_title
= (from_explicit_title
and explicit_weak)
or (
not from_explicit_title
and pane_weak)
392 - local detected
= (apps.is_root( from_command )
and from_command)
395 - or (
not weak_title
and apps.is_root( from_title )
and from_title)
396 - or (apps.is_root( from_title )
and from_title)
401 - local cached
= stable_tab_programs[id]
402 - if not cached
or (detected
~= 'nu' and detected
~= cached)
then 404 - stable_tab_programs[id]
= cached
362 + local detected
= root_or_nil( apps.detect_from_commandline( vars.WEZTERM_PROG ) )
363 + or process_info_program( tab )
364 + or root_or_nil( tab.active_pane.foreground_process_name )
365 + or title_program( display_title )
366 + or stable_tab_programs[id]
367 + or FALLBACK_TAB_PROGRAM
407 - local detail
= title_detail( clean_explicit_title
or clean_pane_title, cached, explicit_title
~= nil )
369 + if detected
~= FALLBACK_TAB_PROGRAM
then stable_tab_programs[id]
= detected
end 409 - local label
= tab_label( cached, detail, MAX_TAB_LABEL_WIDTH )
410 - return label, program_icon( cached ), cached
371 + local detail
= title_detail( display_title, detected, explicit_title
~= nil )
372 + return tab_label( detected, detail ), program_icon( detected ), detected
413 375 local tab_colors = function ( tab, hover )
454 416 local left_sep
= wez.nerdfonts.ple_left_half_circle_thick
or '\u{e0b4}' 455 417 local right_sep
= wez.nerdfonts.ple_right_half_circle_thick
or '\u{e0b6}' 456 418 local dot
= tab.is_active
and '●' or '○' 457 - local budget
= math.
max(
1, max_width
- 10 )
419 + local chrome_width
= 8 420 + local budget
= math.
max(
1, max_width
- chrome_width )
458 421 local text
= wez.truncate_right(
string.
format(
' %s %d %s %s', dot, tab.tab_index
+ 1, icon, title ), budget )
460 423 local elements
= {