diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index 096b0ec..a6faad0 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -1,3 +1,6 @@ +# Changes crossterm to 0.4.3 +- Fixed bug [issue 41](https://github.com/TimonPost/crossterm/issues/41) + # Changes crossterm to 0.4.2 - Added functionality to make a styled object writable to screen [issue 33](https://github.com/TimonPost/crossterm/issues/33) - Added unit tests. diff --git a/examples/examples.rs b/examples/examples.rs index 1b0399f..697b06e 100644 --- a/examples/examples.rs +++ b/examples/examples.rs @@ -15,37 +15,6 @@ mod cursor; mod some_types; mod input; -use std::io::Write; - -use crossterm::style::{style, Color, DisplayableObject}; -use crossterm::terminal::terminal; -use crossterm::Screen; - -use crossterm::output::TerminalOutput; -use crossterm::cursor::TerminalCursor; - -use crossterm::terminal::Terminal; -use std::{thread,time}; - fn main() { - let screen = Screen::new(false); - let terminal = Terminal::new(&screen.stdout); - - // get terminal size - let (x, y) = terminal.terminal_size(); - - // set size to 30, 50 - terminal.set_size(30,50); - - // if we uncomment the line below the code will work perfectly fine and we will get the new dimensions. - // if we comment this line the terminal dimensions gotten from terminal_size() are equal to the old dimensions. - - // thread::sleep(time::Duration::from_millis(20)); - - // get new dimensions - let (x_new, y_new) = terminal.terminal_size(); - - println!("old width: {} old height: {}", x, y); - println!("new width: {} new height: {}", x_new, y_new); } diff --git a/src/common/screen/screen.rs b/src/common/screen/screen.rs index 7eed3f0..87f9c01 100644 --- a/src/common/screen/screen.rs +++ b/src/common/screen/screen.rs @@ -102,14 +102,16 @@ impl Screen /// /// This function is useful if you want to build up some output and when you are ready you could flush the output to the screen. pub fn write_buf(&mut self, buf: &[u8]) -> Result { - self.buffer.write(buf); + self.buffer.write(buf)?; Ok(buf.len()) } /// Flush the internal buffer to the screen. pub fn flush_buf(&mut self) -> Result<()> { - self.stdout.write_buf(&self.buffer); - self.stdout.flush() + self.stdout.write_buf(&self.buffer)?; + self.stdout.flush()?; + self.buffer.clear(); + Ok(()) } /// This will disable the drop which will cause raw modes not to be undone on drop of `Screen`.