Skip to content

Commit

Permalink
Fix return value of Write::write impl for Pipe (#120)
Browse files Browse the repository at this point in the history
* Fix return value of `Write::write` impl for `Pipe`

This should return the number of bytes written, which as implemented
is the whole buffer.

Without this, the default `write_all` implementation won't work
correctly, which is a problem with
c520a21.

* Use `.write` instead of `printfl!` to write `""`

Now that `printfl!` calls `write_all`, rather than `write`, this no
longer works. The `write_all` implementation provided by the `Write`
trait writes until the buffer of bytes left to write is empty, so `write`
is never if an empty string is passed, and thus a `Pipe` doesn't send a
message with `done`.

There are probably better ways to deal with the APIs involved here, but
this at least fixes the behavior.
  • Loading branch information
ids1024 committed Aug 8, 2023
1 parent 87db6b8 commit d60b964
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl Write for Pipe {
string: s,
})
.unwrap();
Ok(1)
Ok(buf.len())
}

fn flush(&mut self) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/pb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ impl<T: Write> ProgressBar<T> {
/// the last time
pub fn finish(&mut self) {
self.finish_draw();
printfl!(self.handle, "");
self.handle.write(b"").expect("write() failed");
}

/// Call finish and write string `s` that will replace the progress bar.
Expand Down

0 comments on commit d60b964

Please sign in to comment.