Removed redundant stdout lock

This commit is contained in:
Timon 2019-05-15 17:04:32 +02:00 committed by GitHub
commit 539ac12447
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 15 additions and 12 deletions

View File

@ -34,7 +34,7 @@ members = [
[dependencies] [dependencies]
crossterm_screen = { optional = true, path = "./crossterm_screen" } crossterm_screen = { optional = true, path = "./crossterm_screen" }
crossterm_cursor = { optional = true, path = "./crossterm_cursor" } crossterm_cursor = { optional = true, path = "./crossterm_cursor" }
crossterm_terminal = { optional = true, version = "0.2.2" } crossterm_terminal = { optional = true, path = "./crossterm_terminal" }
crossterm_style = { optional = true, path = "./crossterm_style" } crossterm_style = { optional = true, path = "./crossterm_style" }
crossterm_input = { optional = true, path = "./crossterm_input" } crossterm_input = { optional = true, path = "./crossterm_input" }
crossterm_utils = { optional = false, path = "./crossterm_utils" } crossterm_utils = { optional = false, path = "./crossterm_utils" }

View File

@ -16,4 +16,4 @@ winapi = { version = "0.3.7", features = ["wincon"] }
crossterm_winapi = "0.1.2" crossterm_winapi = "0.1.2"
[dependencies] [dependencies]
crossterm_utils = "0.2.1" crossterm_utils = {path = "../crossterm_utils"}

View File

@ -12,7 +12,7 @@ pub struct AnsiColor;
impl AnsiColor { impl AnsiColor {
pub fn new() -> AnsiColor { pub fn new() -> AnsiColor {
AnsiColor {} AnsiColor
} }
} }
@ -20,7 +20,7 @@ impl ITerminalColor for AnsiColor {
fn set_fg(&self, fg_color: Color) -> Result<()> { fn set_fg(&self, fg_color: Color) -> Result<()> {
write_cout!(&format!( write_cout!(&format!(
csi!("{}m"), csi!("{}m"),
self.color_value(Colored::Fg(fg_color)) self.color_value(Colored::Fg(fg_color)),
))?; ))?;
Ok(()) Ok(())
} }

View File

@ -18,5 +18,5 @@ crossterm_winapi = "0.1.2"
libc = "0.2.51" libc = "0.2.51"
[dependencies] [dependencies]
crossterm_utils = "0.2.1" crossterm_utils = {path = "../crossterm_utils"}
crossterm_cursor = "0.2.1" crossterm_cursor = {path = "../crossterm_cursor"}

View File

@ -126,7 +126,7 @@ impl Terminal {
/// ///
/// This will also flush the standard output. /// This will also flush the standard output.
pub fn write<D: fmt::Display>(&self, value: D) -> Result<usize> { pub fn write<D: fmt::Display>(&self, value: D) -> Result<usize> {
write_cout!(value)?; write_cout!(format!("{}", value))?;
Ok(0) Ok(0)
} }
} }

View File

@ -8,16 +8,18 @@ macro_rules! csi {
#[macro_export] #[macro_export]
macro_rules! write_cout { macro_rules! write_cout {
($string:expr) => {{ ($string:expr) => {{
let stdout = ::std::io::stdout();
let mut stdout = stdout.lock();
let mut size = 0; let mut size = 0;
let result = write!(::std::io::stdout(), "{}", $string); let result = stdout.write($string.as_bytes());
match result { size += match result {
Ok(size) => size, Ok(size) => size,
Err(e) => return Err(crossterm_utils::ErrorKind::IoError(e)), Err(e) => return Err(crossterm_utils::ErrorKind::IoError(e)),
}; };
match ::std::io::stdout().flush() { match stdout.flush() {
Ok(_) => Ok(size), Ok(_) => Ok(size),
Err(e) => Err(crossterm_utils::ErrorKind::IoError(e)), Err(e) => Err(crossterm_utils::ErrorKind::IoError(e)),
} }

View File

@ -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) - 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) - Backtap input support. [PR](https://github.com/TimonPost/crossterm/pull/129)
- Corrected white/grey and added dark grey. - Corrected white/grey and added dark grey.
- Fixed getting cursor position with raw screen enabled. [PR](https://github.com/TimonPost/crossterm/pull/134) - 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` - Removed println from `SyncReader`
## Changes crossterm 0.9.2 ## Changes crossterm 0.9.2