-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add fill command to overwrite SD card #125
Conversation
This patch adds the fill command that overwrites the SD card with random data. Similar to the reset command, we always require the user to enter the admin PIN even if is cached.
This patch adds the is_tty field to the Context struct that indicates whether stdout is a TTY. This allows us to use TTY features like moving the cursor in our output.
This patch uses the progressing crate to display a progress bar for the fill command if the output is printed to a TTY.
I'll have a look at that tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this functionality. I have a few comments.
src/output.rs
Outdated
} | ||
|
||
pub fn draw(&self, ctx: &mut Context<'_>) -> anyhow::Result<()> { | ||
use crossterm::{cursor, terminal}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 termion
? Would it fulfill our requirements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. termion
works for ANSI terminals only. crossterm
is cross-platform and also supports e. g. Windows terminals.
mention operation time in man page
use crossterm 0.17.7
document ProgressBar
I’ve pushed fixes for the issues you mentioned. Let me know if you want me to replace |
Yeah, I'd prefer we keep an eye on dependencies and add them responsibly and only as necessary. I am sure |
replace crossterm with termion
Unfortunately, termion’s
Could you please check if it is working for you? Here is the code with termion instead of crossterm. |
Hm. Seeing the same issue. |
Ugh, here is a good one too. This is the error that I get when running
which makes absolutely no sense to the average user. That's just utterly brain dead. Here is the verbose log:
If only we were capable of handing errors through properly... |
It works with: --- src/output.rs
+++ src/output.rs
@@ -67,6 +67,7 @@ impl ProgressBar {
pub fn draw(&self, ctx: &mut Context<'_>) -> anyhow::Result<()> {
use anyhow::Context as _;
use termion::cursor::DetectCursorPos as _;
+ use termion::raw::IntoRawMode;
if !ctx.is_tty {
return Ok(());
@@ -74,6 +75,8 @@ impl ProgressBar {
let pos = ctx
.stdout
+ .into_raw_mode()
+ .unwrap()
.cursor_pos()
.context("Failed to query cursor position")?;
let progress_char = if self.toggle && !self.finished { |
Hmm, it seems to work if I activate raw mode, at least in a minimal example. (Unfortunately, termion’s API reference is rather poor.) But should we always activate raw mode in |
I think we can just do that only in |
I don’t think so – |
Yes, but we have a reference to a |
This issue is caused by overlapping error codes in |
Sorry, I missed your comment with the patch. I’ll add it to my implementation and open an issue with termion regarding the documentation. |
replace crossterm with termion
Updated. Regarding killing nitrocli while the operation is still running (I wanted to discuss this separately, but as you’ve brought up the issue, we can discuss this here): I think we should provide some means to re-attach to the progress bar if we killed nitrocli. There are four ways to deal with this:
The I like options 3 and 4 best. 4 would be future proof, but the problem is that I can’t think of a good name for this subcommand. |
By the way, this is the reason why impl<'_, W: Write + ?Sized> Write for &'_ mut W |
Thank you! Merged it now.
Intuitively I'd prefer keeping it in |
No description provided.