-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
std.Progress: instead of one line of terminal progress, make it check the terminal width and use multiple lines #14946
Comments
I'd also like to add that this should fix an annoying issue where |
I've been able to make the changes needed to print multiple lines and I am confident that I'll also manage to implement the other features. I must add, though, that I have basically removed |
Sounds promising! Tip: You can use https://asciinema.org/ to share demos of your code in action. |
I couldn't manage to properly record using asciinema, so here a video instead: demo.webmAlthough I think the code isn't the most elegant (might just be my craving for perfection tho), I think I've managed to find an acceptable solution that isn't performance optimized. If I take some more time playing around then I might as well find something more optimized. Windows support is still to be adapted and I need to test for potential issues, as well as find a way to word-wrap on smaller terminal windows. Furthermore, I also need to make sure that multiple nodes can be displayed at a time while also having children nodes. At the moment, I have only tested for a simple cascade of nodes. To help me get a better idea of the 'vision', feedback is always appreciated. |
I've also changed the spacing to make it look a bit more compact:
|
Here another demo: demo2.webmI've finally managed to implement a tree representation and all that is left to do is add Windows support (fingers crossed), do some testing (crossed even tighter), major cleanup (code got messy), and create another commit for the line-wrapping. It was harder than I initially thought, since the original approach was just having the active Node point to parent which does not exactly present any non-active Nodes. In addition, and the way it's often done, working with trees, I had to move some code into a recursive function. Still, zero dynamic allocation and hopefully Thread-safety, since I lack experience with that, apart from implementing a queue and thread blocking in a python project. I should also mention that the screen is not being cleared so no previous lines are overwritten. |
Looks pretty good! Can you show a demo of running 2 threads that simultaneously increment different tasks from 0 to 1000? |
For sure :) demo3.webmconst std = @import("std");
const Thread = std.Thread;
fn run(node: *std.Progress.Node, arg: []const u8) void {
var child = node.start(arg, 1000);
defer child.end();
for (0..1000) |i| {
child.activate();
child.setCompletedItems(i);
std.time.sleep(5000000);
}
}
pub fn main() !void {
var progress = std.Progress{};
var node = progress.start("Building", 1);
defer node.end();
const handler_1 = try Thread.spawn(.{}, run, .{ node, "Task 1" });
const handler_2 = try Thread.spawn(.{}, run, .{ node, "Task 2" });
handler_1.join();
// node.completeOne();
handler_2.join();
// node.completeOne();
} |
Looks great! |
I am currently in the testing stages, is there anything in specific I should test against?. The line-wrapping will come as a separate commit, after which I'll do the PR for revision. |
It needs to work on Windows too (although it is not required to have identical behavior) |
I can confirm it works on Windows as well. Anything else? |
I think the next step would be to review a pull request |
Alright then, I'll try to implement the line-wrapping and open a PR for revision afterwards. |
Done in #20059 |
Extracted from #14647.
When multiple things are being worked on, and the executable has decided to use terminal emulator codes to display a progress bar, display the multiple things in a tree form rather than as a single line. This will give a better idea of what is happening when multiple threads are doing multiple things at once.
The text was updated successfully, but these errors were encountered: