-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(interactive): Add better progress bars (#1152)
- Loading branch information
Showing
4 changed files
with
111 additions
and
28 deletions.
There are no files selected for viewing
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
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,33 @@ | ||
use super::*; | ||
|
||
pub struct SizedGauge { | ||
p: Gauge<'static>, | ||
width: Option<u16>, | ||
} | ||
|
||
impl SizedGauge { | ||
pub fn new(text: Span<'static>, ratio: f64) -> Self { | ||
let width = text.width().try_into().ok(); | ||
let p = Gauge::default() | ||
.gauge_style(Style::default().fg(Color::Blue)) | ||
.use_unicode(true) | ||
.label(text) | ||
.ratio(ratio); | ||
Self { p, width } | ||
} | ||
} | ||
|
||
impl SizedWidget for SizedGauge { | ||
fn width(&self) -> Option<u16> { | ||
self.width.map(|w| w + 10) | ||
} | ||
fn height(&self) -> Option<u16> { | ||
Some(1) | ||
} | ||
} | ||
|
||
impl Draw for SizedGauge { | ||
fn draw(&mut self, area: Rect, f: &mut Frame<'_>) { | ||
f.render_widget(&self.p, area); | ||
} | ||
} |