Skip to content

std.Progress: possible simplifications and ideas #12024

@ghost

Description

After discovering std.Progress today I noticed that this is how it's resetting the terminal cursor
to the column where the cursor was before the line was written and how it's clearing that line: https://github.com/ziglang/zig/blob/master/lib/std/Progress.zig#L206-L254

  • All this could be greatly simplified by printing '\r' which in terminals always resets the cursor to column 0. This works on Windows too. So when you print "hello world\rworld", it will print as world world!
    As for the clearing of the previous content, let's say we have hello world on the terminal but now we want to show only hello on the same line. We would simply print "\rhello" + 6 more spaces to erase world too.
    All this would greatly simplify the code and avoid escape sequences altogether. It'd be much more portable and reliable. It would also no longer require any special casing for Windows. Performance and printing speed might improve too.

Now I would really like to start working on this but the blocker I have is that doing it this way will no longer allow printing multiple progresses on the same row or else it'll look messed up. This would no longer be possible:

Test [1/1] test "basic functionality"... [3/100] climbing towers [3/5]

so it'd have to be like this:

Test [1/1] test "basic functionality"...
[3/100] climbing towers [3/5]

So would it be fine to allow only one progress line per row?

I'd specifically be interested to hear an opinion from the original designer of std.Progress, @andrewrk.

Other things that could be done include

  • Adding an option to the compiler to disable the progress bar/any output during compilation (does this already exist?) because I can definitely see Zig being useful as a language for other languages to compile to (as opposed to compiling to C) so if they want to do that by invoking zig then it'd be nice to disable that output.
  • Removing the space after the ellipsis (this would make the most sense if we go with my idea above of allowing only one progress per row in order to simplify the code using '\r')
  • Adding an actual loading bar-looking thing like this?
    [=====     ] [50/100] reticulating splines [5/5]
    
    There are a lot of flashy CLI libs etc. out there that make use of Unicode characters and stuff to make the their loading bars look really cool (think box-drawing characters etc.) but I think we should limit ourselves to ASCII characters here to make sure it works in as many environments as possible because not all Unicode characters are supported everywhere. Also, I don't think doing this provides any actual value so I think these fancy loading bars are probably best left to some external library and we should keep the current progress bar design.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions