-
Notifications
You must be signed in to change notification settings - Fork 10
Add fill command to overwrite SD card #125
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
Changes from 1 commit
2ba357c
b58bf85
b853402
5f972f8
2f5e81e
fa57018
9f226ec
5c464a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,7 @@ mod arg_util; | |
| mod args; | ||
| mod commands; | ||
| mod config; | ||
| mod output; | ||
| mod pinentry; | ||
| #[cfg(test)] | ||
| mod tests; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // commands.rs | ||
|
|
||
| // Copyright (C) 2020 The Nitrocli Developers | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| use crate::Context; | ||
|
|
||
| /// A progress bar that can be printed to an interactive output. | ||
| pub struct ProgressBar { | ||
| redraw: bool, | ||
| progress: u8, | ||
| toggle: bool, | ||
| finished: bool, | ||
| } | ||
|
|
||
| impl ProgressBar { | ||
| pub fn new() -> ProgressBar { | ||
| ProgressBar { | ||
| redraw: true, | ||
| progress: 0, | ||
| toggle: false, | ||
| finished: false, | ||
| } | ||
| } | ||
|
|
||
| pub fn is_finished(&self) -> bool { | ||
| self.finished | ||
| } | ||
|
|
||
| pub fn update(&mut self, progress: u8) -> anyhow::Result<()> { | ||
| anyhow::ensure!(!self.finished, "Tried to update finished progress bar"); | ||
| anyhow::ensure!( | ||
| progress <= 100, | ||
| "Progress bar value out of range: {}", | ||
| progress | ||
| ); | ||
| if progress != self.progress { | ||
| self.redraw = true; | ||
| self.progress = progress; | ||
| } | ||
| self.toggle = !self.toggle; | ||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn finish(&mut self) { | ||
| self.finished = true; | ||
| self.redraw = true; | ||
| self.progress = 100; | ||
| } | ||
|
|
||
| pub fn draw(&self, ctx: &mut Context<'_>) -> anyhow::Result<()> { | ||
| use crossterm::{cursor, terminal}; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh...guess we need it for other stuff too :-| Have you considered using
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||
|
|
||
| if !ctx.is_tty { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| let progress_char = if self.toggle && !self.finished { | ||
| "." | ||
| } else { | ||
| " " | ||
| }; | ||
| if self.redraw { | ||
| use progressing::Baring; | ||
|
|
||
| let mut progress_bar = progressing::mapping::Bar::with_range(0, 100); | ||
| progress_bar.set(self.progress); | ||
|
|
||
| print!(ctx, "{}", terminal::Clear(terminal::ClearType::CurrentLine))?; | ||
| print!(ctx, "{}", cursor::MoveToColumn(0))?; | ||
| print!(ctx, " {} {}", progress_char, progress_bar)?; | ||
| if self.finished { | ||
| println!(ctx)?; | ||
| } | ||
| } else { | ||
| print!(ctx, "{}{}", cursor::MoveToColumn(1), progress_char)?; | ||
| } | ||
|
|
||
| ctx.stdout.flush()?; | ||
| Ok(()) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.