Skip to content

Conversation

@andrewrk
Copy link
Member

@andrewrk andrewrk commented Jul 24, 2025

Turns out there's escape codes for sending progress status to the terminal: https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC

As far as I'm aware only Windows Terminal and Ghostty support these. I didn't get access to either one yet for testing so this PR is going in blind.

const std = @import("std");
const testing = std.testing;
const assert = std.debug.assert;

pub fn main() anyerror!void {
    const main_progress_node = std.Progress.start(.{
        .estimated_total_items = stuff.len,
        .initial_delay_ns = 0,
    });
    defer main_progress_node.end();

    for (&stuff) |name| {
        const node = main_progress_node.start(name, 0);
        defer node.end();
        std.Thread.sleep(100 * std.time.ns_per_ms);
    }
}

const stuff = [_][]const u8{
    "frobnicating",
    "confabulating",
    "prognosticating",
    "retabulating",
    "procrastinating",
    "masticating",
    "disenfranchising",
    "reticulating",
};

It integrates with --watch in the build system to set error state when failures occur, and clear it when they are fixed, also to clear progress when waiting for user input.

potential follow-up work:

  • Improve the heuristic for when to use pulsing vs a number between 1-100.
  • Improve the heuristic for mapping progress data to a number between 1-100.
  • Consider not hiding progress during lockStderr
  • (this applies to progress output too) if you hit ctrl+c, crap is leftover and not cleared. is there a solution? (other than adding a signal handler for this)

@andrewrk andrewrk added the release notes This PR should be mentioned in the release notes. label Jul 24, 2025
@mitchellh
Copy link
Contributor

VTE supports it now too which should expand support considerably on Linux: https://www.phoronix.com/news/VTE-Terminals-Progress-Indicate

@alexrp
Copy link
Member

alexrp commented Jul 24, 2025

Windows Powershell

More likely Windows Terminal, just so you don't open PowerShell in the legacy console host and get confused at why it's missing a bunch of features.

Copy link

@ddogfoodd ddogfoodd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worked for me on latest Ghostty, well done!

@andrewrk andrewrk force-pushed the terminal-progress-bar branch from 3095c0d to b22b9eb Compare July 26, 2025 00:33
@andrewrk
Copy link
Member Author

Alright I think this is good enough for a first version. I added std.Progress.setStatus and the following enum:

pub const Status = enum {
    /// Indicates the application is progressing towards completion of a task.
    /// Unless the application is interactive, this is the only status the
    /// program will ever have!
    working,
    /// The application has completed an operation, and is now waiting for user
    /// input rather than calling exit(0).
    success,
    /// The application encountered an error, and is now waiting for user input
    /// rather than calling exit(1).
    failure,
    /// The application encountered at least one error, but is still working on
    /// more tasks.
    failure_working,
};

@andrewrk andrewrk enabled auto-merge July 26, 2025 03:35
@andrewrk andrewrk merged commit fc4b7c9 into master Jul 26, 2025
10 checks passed
@andrewrk andrewrk deleted the terminal-progress-bar branch July 26, 2025 04:49
@kcbanner
Copy link
Contributor

image

Working nicely in Windows Terminal Preview 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release notes This PR should be mentioned in the release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants