-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**Stack**: - #2847 - #2846 ⬅⚠️ *Part of a stack created by [spr](https://github.com/ejoffe/spr). Do not merge manually using the UI - doing so may have unexpected results.*
- Loading branch information
Showing
6 changed files
with
49 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use indicatif::{ProgressBar, ProgressStyle}; | ||
use std::borrow::Cow; | ||
use std::time::Duration; | ||
|
||
/// Styled spinner that uses [`ProgressBar`]. | ||
/// Automatically finishes and clears itself when dropped. | ||
pub struct Spinner(ProgressBar); | ||
impl Spinner { | ||
/// Create [`Spinner`] with a message. | ||
pub fn create_with_message(message: impl Into<Cow<'static, str>>) -> Self { | ||
let spinner = ProgressBar::new_spinner(); | ||
let style = ProgressStyle::with_template("\n{spinner} {msg}\n") | ||
.expect("template is static str and should be valid"); | ||
spinner.set_style(style); | ||
spinner.enable_steady_tick(Duration::from_millis(100)); | ||
spinner.set_message(message); | ||
Self(spinner) | ||
} | ||
} | ||
|
||
impl Drop for Spinner { | ||
fn drop(&mut self) { | ||
self.0.finish_and_clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters