-
Notifications
You must be signed in to change notification settings - Fork 242
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
synchronized output #618
base: main
Are you sure you want to change the base?
synchronized output #618
Conversation
I think it would be good to support this, but I also think a lot of the supporting code (about detecting and using the sync mechanism) would probably make more sense in the lower-level console crate (which indicatif uses). Maybe start a PR there (feel free to mention me)? |
Yes, I can do a separate PR in console. @djc Should the API look like this? let term = Term::stdout();
if term.supports_sync_update() {
term.begin_sync_update();
}
// do something
if term.supports_sync_update() {
term.end_sync_update();
} With sync update doing sth like Another option would be to use a closure let term = Term::stdout();
term.[maybe_]sync_update(|| {
term.write_line("Hello world");
}); which handles both begin and end sync update. Though here the question is if we should check whether the feature is supported inside the |
I would do a guard type that ends the sync on dropping. But, probably good to ask the console maintainer(s) to weigh in on this. |
Since the console crate seems a little bit inactive, I made this PR simpler. It now uses once_cell and might work on Windows, too, though I haven't checked (should be checked before merging, though). Note: I added a new method to a public trait which is a breaking change. I'm still not sure, if this is the correct design ( |
I pinged a console maintainer on Discord to see if we can get that conversation going. :) |
If we were to add a Sync Guard in the console crate, how would we be able to use it in indicatif? I guess via the TermLike trait, but what about the in_memory term then? |
The in-mem term is just for testing purposes. I don't think we'd need sync guard there necessarily? |
Okay, but then what about custom TermLike implementations? indicatif provides the ability to create a ProgressBar via a |
Ah ok. I see what you mean. Let me think about it a bit... |
Any update, @chris-laplante? |
Sorry, I finally got time to look at this. I think I was able to put all the pieces together in a way that makes sense for both crates. Please see console-rs/console#205 for the |
Thanks for taking a look at this! These PRs look good to me!
Just a note for the future: The Windows 10 terminal can support ANSI codes, if you enable them. If you call So in the future it might look like this. #[inline]
pub fn is_synchronized_output_supported(&self) -> bool {
#[cfg(unix)]
{
supports_synchronized_output()
}
#[cfg(not(unix))]
{
self.colors_supported() && supports_synchronized_output()
}
} I think it would be more efficient to cache the result of But right now, the In my last update for this PR, I simply removed By the way, this one line that I removed in console ( |
Would you mind copying this comment to the PR in console? That way I can reply to the console specific parts there. |
Added support for synchronized output (https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036). Before, my multi progressbars flickered a lot. But not anymore.
Note: I added a new method to a public trait which is a breaking change. I'm still not sure, if this is the correct design (supports_ansi_codes in the public trait).
Otherwise, the PR seems to work fine for me.