Fixed bug flush_buf(). (#42)

* Fixed bug flush_buf() issue 42.
This commit is contained in:
Timon 2018-11-14 15:13:58 +01:00 committed by GitHub
parent 61188e6353
commit ad8b75f448
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 34 deletions

View File

@ -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 # 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 functionality to make a styled object writable to screen [issue 33](https://github.com/TimonPost/crossterm/issues/33)
- Added unit tests. - Added unit tests.

View File

@ -15,37 +15,6 @@ mod cursor;
mod some_types; mod some_types;
mod input; 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() 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);
} }

View File

@ -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. /// 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<usize> { pub fn write_buf(&mut self, buf: &[u8]) -> Result<usize> {
self.buffer.write(buf); self.buffer.write(buf)?;
Ok(buf.len()) Ok(buf.len())
} }
/// Flush the internal buffer to the screen. /// Flush the internal buffer to the screen.
pub fn flush_buf(&mut self) -> Result<()> { pub fn flush_buf(&mut self) -> Result<()> {
self.stdout.write_buf(&self.buffer); self.stdout.write_buf(&self.buffer)?;
self.stdout.flush() 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`. /// This will disable the drop which will cause raw modes not to be undone on drop of `Screen`.