Files
LLeMbas-TTY/docs/config/lua/pane/get_progress.md
T
Wez Furlong 44866cc137 new: ConEmu progress reporting OSC sequence
This commit parses and captures the progress state as set by
ConEmu style progress reporting escape sequences.

Changes to the state will propagage through the mux via the
existing MuxNotification Alert system, and should also transit
across multiplexer connections.  However, there is no separate
multiplexer state transfer for the progress state, so reconnecting
to a mux in the middle of a progress sequence will show as None
for the progress state, until the next update occurs.

Aside from propgating and exposing the state to lua via PaneInformation
and a Pane::get_progress method, wezterm doesn't do anything with
the progress information at this time.

This commit includes an example of how you might customize your
tab title to reflect the progress in the active pane.

refs: https://github.com/wezterm/wezterm/issues/6581
2025-02-09 18:26:23 -07:00

2.4 KiB

pane:get_title()

{{since('nightly')}}

Returns the progress state associated with the pane.

By default, when the terminal is reset, the progress state will be "None" to indicate that no progress has been reported.

An application can use the ConEmu style progress report OSC sequence to alter the progress state, which has the following form:

ESC ] 9 ; 4 ; st ; pr ST

When st is:

  • 0: set progress to "None"
  • 1: set progress value to pr (number, 0-100). Reported as {Percentage = pr}
  • 2: set error state in progress, pr is optional and will be assumed 0 if omitted. Reported as {Error = pr}
  • 3: set indeterminate state. Reported as "Indeterminate"
  • 4: set paused state, pr is optional. Not supported by WezTerm

When the progress OSC is processed, the state is captured, and if it has changed, WezTerm will trigger an update of the tab bar, which will in turn cause events such as format-tab-title to trigger.

The progress information is not directly used by wezterm, but you can access it from lua to style tabs differently according to progress. For example, the following will prefix the tab with the progress percentage and adjust its color based on whether it is success or error progress:

local wezterm = require 'wezterm'

function tab_title(tab_info)
  local title = tab_info.tab_title
  -- if the tab title is explicitly set, take that
  if title and #title > 0 then
    return title
  end
  -- Otherwise, use the title from the active pane
  -- in that tab
  return tab_info.active_pane.title
end

wezterm.on(
  'format-tab-title',
  function(tab, tabs, panes, config, hover, max_width)
    local progress = tab.active_pane.progress or "None"
    local title = tab_title(tab)
    if progress ~= "None" then
      local color = 'green'
      local status
      if progress.Percentage ~= nil then
        status = string.format("%d%%", progress.Percentage)
      elseif progress.Error ~= nil then
        status = string.format("%d%%", progress.Error)
        color = 'red'
      elseif progress == "Indeterminate" then
        status = "~"
      else
        status = wezterm.serde.json_encode(progress)
      end
      return {
        { Background = { Color = color } },
        { Text = '(' .. status .. ') ' },
        'ResetAttributes',
        { Text = ' ' .. title .. ' ' },
      }
    end
    return title
  end
)

return wezterm.config_builder()