Skip to content

Commit

Permalink
main: Stop the write(ln)!(stdout()..) craziness
Browse files Browse the repository at this point in the history
stop the crossterm docs propaganda and flush stdout where ncessary

Signed-off-by: Konrad Dybcio <konradybcio@kernel.org>
  • Loading branch information
konradybcio committed May 7, 2024
1 parent d722874 commit f1ab395
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub async fn send_image(write_sink: &mut Arc<Mutex<impl Write>>, buf: &[u8]) ->

if percent_done != last_percent_done {
let s = format!(" Sending image: {}%\r", percent_done);
write!(stdout(), "{}", s.green()).unwrap();
print!("{}", s.green());
stdout().flush()?;
}

Expand All @@ -121,8 +121,9 @@ pub async fn send_image(write_sink: &mut Arc<Mutex<impl Write>>, buf: &[u8]) ->
last_percent_done = percent_done;

if bytes_sent == buf.len() {
write!(stdout(), "\r{}\r", " ".repeat(80))?;
write!(stdout(), "{}\r\n", String::from("Image sent!").green())?;
print!("\r{}\r", " ".repeat(80));
print!("{}\r\n", String::from("Image sent!").green());
stdout().flush()?;
}
}

Expand Down Expand Up @@ -154,7 +155,7 @@ pub fn print_string_msg(buf: &[u8]) {
return;
}

writeln!(stdout(), "{}\r", String::from_utf8_lossy(buf)).unwrap();
println!("{}\r", String::from_utf8_lossy(buf));
stdout().flush().unwrap();
}

Expand Down
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ async fn handle_keypress(
macro_rules! todo {
($s: expr) => {{
let val = format!($s);
writeln!(stdout(), "{val}\r").unwrap();
println!("{val}\r");
stdout().flush()?;
}};
}

Expand Down Expand Up @@ -134,7 +135,7 @@ async fn main() -> anyhow::Result<()> {
// Stream of "blue text" - status updates from the server
if let Ok(bytes_read) = (*get_arc!(chan)).stderr().read(&mut buf) {
let s = String::from_utf8_lossy(&buf[..bytes_read]);
print!("{}\r", s.replace("\n", "\r\n").blue());
print!("{}\r", s.replace('\n', "\r\n").blue());
stdout().flush()?;
}

Expand Down

0 comments on commit f1ab395

Please sign in to comment.