Commit c9c91292 authored by Alexandre Bury's avatar Alexandre Bury Committed by ticki

Replace most `std::io::Write::write` with `write_all` (#82)

`std::io::Write` doesn't guarantees that it will write everything,
and could even return a non-fatal `ErrorKind::Interrupted` error.
`write_all` has exactly the code required to deal with this.
parent c04fd7f2
......@@ -154,16 +154,16 @@ fn main() {
let stdin = stdin();
let mut stdin = stdin.lock();
stdout.write(b"password: ").unwrap();
stdout.write_all(b"password: ").unwrap();
stdout.flush().unwrap();
let pass = stdin.read_passwd(&mut stdout);
if let Ok(Some(pass)) = pass {
stdout.write(pass.as_bytes()).unwrap();
stdout.write(b"\n").unwrap();
stdout.write_all(pass.as_bytes()).unwrap();
stdout.write_all(b"\n").unwrap();
} else {
stdout.write(b"Error\n").unwrap();
stdout.write_all(b"Error\n").unwrap();
}
}
```
......
......@@ -25,10 +25,10 @@ fn main() {
stdout.flush().unwrap();
thread::sleep(Duration::from_millis(50));
stdout.write(b"# ").unwrap();
stdout.write_all(b"# ").unwrap();
stdout.flush().unwrap();
thread::sleep(Duration::from_millis(50));
stdout.write(b"\r #").unwrap();
stdout.write_all(b"\r #").unwrap();
write!(stdout, "{}", termion::cursor::Goto(1, 1)).unwrap();
stdout.flush().unwrap();
}
......
......@@ -9,15 +9,15 @@ fn main() {
let stdin = stdin();
let mut stdin = stdin.lock();
stdout.write(b"password: ").unwrap();
stdout.write_all(b"password: ").unwrap();
stdout.flush().unwrap();
let pass = stdin.read_passwd(&mut stdout);
if let Ok(Some(pass)) = pass {
stdout.write(pass.as_bytes()).unwrap();
stdout.write(b"\n").unwrap();
stdout.write_all(pass.as_bytes()).unwrap();
stdout.write_all(b"\n").unwrap();
} else {
stdout.write(b"Error\n").unwrap();
stdout.write_all(b"Error\n").unwrap();
}
}
......@@ -160,7 +160,7 @@ pub struct MouseTerminal<W: Write> {
impl<W: Write> From<W> for MouseTerminal<W> {
fn from(mut from: W) -> MouseTerminal<W> {
from.write(ENTER_MOUSE_SEQUENCE.as_bytes()).unwrap();
from.write_all(ENTER_MOUSE_SEQUENCE.as_bytes()).unwrap();
MouseTerminal { term: from }
}
......@@ -168,7 +168,7 @@ impl<W: Write> From<W> for MouseTerminal<W> {
impl<W: Write> Drop for MouseTerminal<W> {
fn drop(&mut self) {
self.term.write(EXIT_MOUSE_SEQUENCE.as_bytes()).unwrap();
self.term.write_all(EXIT_MOUSE_SEQUENCE.as_bytes()).unwrap();
}
}
......
......@@ -141,6 +141,6 @@ mod test {
fn test_into_raw_mode() {
let mut out = stdout().into_raw_mode().unwrap();
out.write(b"this is a test, muahhahahah").unwrap();
out.write_all(b"this is a test, muahhahahah").unwrap();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment