diff --git a/crossterm_cursor/src/cursor/ansi_cursor.rs b/crossterm_cursor/src/cursor/ansi_cursor.rs index d44854e..c7d7c4a 100644 --- a/crossterm_cursor/src/cursor/ansi_cursor.rs +++ b/crossterm_cursor/src/cursor/ansi_cursor.rs @@ -7,29 +7,19 @@ use crate::sys::get_cursor_position; use std::io::Write; use crossterm_utils::Result; -use std::io::Stdout; -use std::io::stdout; -use std::io::StdoutLock; -use std::io::BufWriter; -use std::sync::RwLock; /// This struct is an ANSI implementation for cursor related actions. -pub struct AnsiCursor { - stdout: RwLock> -} +pub struct AnsiCursor; impl AnsiCursor { pub fn new() -> AnsiCursor { - AnsiCursor { - stdout: RwLock::new(BufWriter::new(stdout())) - } + AnsiCursor } } impl ITerminalCursor for AnsiCursor { fn goto(&self, x: u16, y: u16) -> Result<()> { - write_cout1!(format!(csi!("{};{}H"), y + 1, x + 1), &mut self.stdout.write().unwrap())?; -// write_cout!(format!(csi!("{};{}H"), y + 1, x + 1))?; + write_cout!(format!(csi!("{};{}H"), y + 1, x + 1))?; Ok(()) } diff --git a/crossterm_style/src/ansi_color.rs b/crossterm_style/src/ansi_color.rs index f4c30e1..3ff582d 100644 --- a/crossterm_style/src/ansi_color.rs +++ b/crossterm_style/src/ansi_color.rs @@ -6,36 +6,34 @@ use crossterm_utils::Result; use crate::Colored; use std::io; -use std::io::Write; -use std::io::Stdout; use std::io::BufWriter; +use std::io::Stdout; +use std::io::Write; use std::sync::RwLock; /// This struct is an ANSI escape code implementation for color related actions. -pub struct AnsiColor { - stdout: RwLock> -} +pub struct AnsiColor; impl AnsiColor { pub fn new() -> AnsiColor { - AnsiColor { stdout: RwLock::new(BufWriter::new(io::stdout())) } + AnsiColor } } impl ITerminalColor for AnsiColor { fn set_fg(&self, fg_color: Color) -> Result<()> { - write_cout1!(&format!( + write_cout!(&format!( csi!("{}m"), self.color_value(Colored::Fg(fg_color)), - ), &mut self.stdout.write().unwrap())?; + ))?; Ok(()) } fn set_bg(&self, bg_color: Color) -> Result<()> { - write_cout1!(&format!( + write_cout!(&format!( csi!("{}m"), self.color_value(Colored::Bg(bg_color)) - ), &mut self.stdout.write().unwrap())?; + ))?; Ok(()) } diff --git a/crossterm_terminal/src/terminal/terminal.rs b/crossterm_terminal/src/terminal/terminal.rs index da82d58..92550d9 100644 --- a/crossterm_terminal/src/terminal/terminal.rs +++ b/crossterm_terminal/src/terminal/terminal.rs @@ -126,7 +126,7 @@ impl Terminal { /// /// This will also flush the standard output. pub fn write(&self, value: D) -> Result { -// write_cout!(value)?; + write_cout!(format!("{}", value))?; Ok(0) } } diff --git a/crossterm_utils/src/macros.rs b/crossterm_utils/src/macros.rs index f26f011..42accb5 100644 --- a/crossterm_utils/src/macros.rs +++ b/crossterm_utils/src/macros.rs @@ -16,7 +16,7 @@ macro_rules! write_cout { let result = stdout.write($string.as_bytes()); - match result { + size += match result { Ok(size) => size, Err(e) => return Err(crossterm_utils::ErrorKind::IoError(e)), }; @@ -24,25 +24,6 @@ macro_rules! write_cout { match stdout.flush() { Ok(_) => Ok(size), Err(e) => Err(crossterm_utils::ErrorKind::IoError(e)), - }; - - result + } }}; } - -/// Write a string to standard output whereafter the screen will be flushed. -#[macro_export] -macro_rules! write_cout1 { - ($string:expr, $stdout:expr) => {{ - let mut size = 0; - - let result = write!($stdout, "{}", $string); - - match result { - Ok(size) => size, - Err(e) => return Err(crossterm_utils::ErrorKind::IoError(e)), - }; - - result - }}; -} \ No newline at end of file diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 939c97f..9abf81b 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,10 +1,11 @@ -# Changes crossterm_input 0.9.4 +# Changes crossterm 0.9.4 - Reset foreground and background color individually. [PR](https://github.com/TimonPost/crossterm/pull/138) - Backtap input support. [PR](https://github.com/TimonPost/crossterm/pull/129) - Corrected white/grey and added dark grey. - Fixed getting cursor position with raw screen enabled. [PR](https://github.com/TimonPost/crossterm/pull/134) +- Removed one redundant stdout lock -# Changes crossterm_input 0.9.3 +# Changes crossterm 0.9.3 - Removed println from `SyncReader` ## Changes crossterm 0.9.2