Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSC 9;4 support (progress report) #6581

Open
1 of 7 tasks
sanpii opened this issue Jan 18, 2025 · 2 comments
Open
1 of 7 tasks

OSC 9;4 support (progress report) #6581

sanpii opened this issue Jan 18, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@sanpii
Copy link

sanpii commented Jan 18, 2025

[Edit: this description has been taken over by the maintainers to track the status]

https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC

ESC ] 9 ; 4 ; st ; pr ST
Set progress state on Windows 7 taskbar and ConEmu title. When st is 0: remove progress. When st is 1: set progress value to pr (number, 0-100). When st is 2: set error state in progress on Windows 7 taskbar, pr is optional. When st is 3: set indeterminate state. When st is 4: set paused state, pr is optional.

It's being integrated into cargo: rust-lang/cargo#14615

Status of implementation within wezterm:

It basically works, and you can use the config fragment shown below to customize how it appears

  • Escape sequences are processed and exposed via lua
  • Multiplexer client synchronizes progress during (re)connect
  • Show progress by default
    • Decide on how that appears in tab titles
    • Decide on how that appears in window titles
  • Decide how to deal with indeterminate progress state.
    • Should we try to do something fancy for auto-animating a spinner of some kind?
  • Windows: update the taskbar icon/state. (unsure if we'll bother with this)
    • Needs some design: what to do when multiple panes/tabs have progress to display? Show the active one only?
    • Needs API support in the Window crate.
local wezterm = require 'wezterm'

local 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

local PCT_GLYPHS = {
  wezterm.nerdfonts.md_circle_slice_1,
  wezterm.nerdfonts.md_circle_slice_2,
  wezterm.nerdfonts.md_circle_slice_3,
  wezterm.nerdfonts.md_circle_slice_4,
  wezterm.nerdfonts.md_circle_slice_5,
  wezterm.nerdfonts.md_circle_slice_6,
  wezterm.nerdfonts.md_circle_slice_7,
  wezterm.nerdfonts.md_circle_slice_8,
}
local function pct_glyph(pct)
  local slot = math.floor(pct / 12)
  return PCT_GLYPHS[slot+1]
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)
    local elements = {
      { Text = string.format("%d: ", tab.tab_index+1) },
    }

    if progress ~= "None" then
      local color = 'green'
      local status
      if progress.Percentage ~= nil then
        -- status = string.format("%d%%", progress.Percentage)
        status = pct_glyph(progress.Percentage)
      elseif progress.Error ~= nil then
        -- status = string.format("%d%%", progress.Error)
        status = pct_glyph(progress.Error)
        color = 'red'
      elseif progress == "Indeterminate" then
        status = "~"
      else
        status = wezterm.serde.json_encode(progress)
      end

      table.insert(elements, { Foreground = { Color = color } })
      table.insert(elements, { Text = status })
      table.insert(elements, { Foreground = 'Default' })
    end

    table.insert(elements, { Text = ' ' .. title .. ' ' })

    return elements
  end
)

return wezterm.config_builder()
@sanpii sanpii added the enhancement New feature or request label Jan 18, 2025
wez added a commit that referenced this issue Feb 10, 2025
wez added a commit that referenced this issue Feb 10, 2025
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: #6581
@wez
Copy link
Member

wez commented Feb 10, 2025

I just pushed a first pass at supporting these. There's no automatic rendering of the state in the UI, but you can customize exactly how it will manifest in lua. Here's a basic example:

Edit: example moved to the issue description

@wez
Copy link
Member

wez commented Feb 10, 2025

with the updated example above, the progress renders like this in the tab title, with that green circle filling in as the progress advances:

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants