diff --git a/.travis.yml b/.travis.yml index 645fe41..70ec4de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,11 +2,11 @@ language: rust rust: - stable -- beta - nightly before_script: - export PATH=$PATH:/home/travis/.cargo/bin +- rustup component add rustfmt-preview os: - linux @@ -19,3 +19,4 @@ branches: script: - cargo build +- cargo fmt -- --check diff --git a/Cargo.toml b/Cargo.toml index 139213f..fad6780 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "crossterm" -version = "0.5.1" +version = "0.6.0" authors = ["T. Post"] description = "An crossplatform terminal library for manipulating terminals." repository = "https://github.com/TimonPost/crossterm" @@ -12,7 +12,7 @@ readme = "README.md" [target.'cfg(windows)'.dependencies] winapi = { version = "0.3.5", features = ["winbase","winuser","consoleapi","processenv","wincon", "handleapi","errhandlingapi"] } -crossterm_winapi = { version = "0.0.0", git="https://github.com/TimonPost/crossterm_winapi" } +crossterm_winapi = "0.1.0" [target.'cfg(unix)'.dependencies] libc = "0.2.43" diff --git a/README.md b/README.md index a9aaaba..356e15f 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Add the Crossterm package to your `Cargo.toml` file. ``` [dependencies] -crossterm = "0.5.0" +crossterm = "0.6" ``` And import the Crossterm modules you want to use. @@ -95,7 +95,7 @@ These are the features from this crate: - Background color (16 base colors) - 256 color support (Windows 10 and UNIX only) - RGB support (Windows 10 and UNIX only) - - Text Attributes like: bold, italic, underscore and crossed word ect (unix only) + - Text Attributes like: bold, italic, underscore and crossed word ect (Windows 10 and UNIX only) - Terminal - Clearing (all lines, current line, from cursor down and up, until new line) - Scrolling (Up, down) @@ -139,7 +139,7 @@ use crossterm::style::{Color, style}; let style1 = style("Some Blue font on Black background").with(Color::Blue).on(Color::Black); let style2 = style("Some Red font on Yellow background").with(Color::Red).on(Color::Yellow); -// attributes are only supported for UNIX terminals. +// syling font with (Windows 10 and UNIX systems) let normal = style("Normal text"); let bold = style("Bold text").bold(); let italic = style("Italic text").italic(); @@ -151,21 +151,21 @@ let reversed = style("Reversed text").reverse(); let dimmed = style("Dim text").dim(); let crossed_out = style("Crossed out font").crossed_out(); -// paint styled text to screen (this could also be called inline) +// paint styled text to screen (this could also be called inline) println!("{}", style1); println!("{}", style2); println!("{}", bold); println!("{}", hidden); ... -// cursom rgb value +// cursom rgb value (Windows 10 and UNIX systems) style("RGB color (10,10,10) ").with(Color::Rgb { r: 10, g: 10, b: 10 })); -// custom ansi color value +// custom ansi color value (Windows 10 and UNIX systems) style("ANSI color value (50) ").with(Color::AnsiValue(50)); ``` diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index 58b0d5e..bf0e83a 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -1,3 +1,11 @@ +# Changes crossterm 0.6.0 +- WinApi rewrite and correctly error handled [PR 67](https://github.com/TimonPost/crossterm/pull/67) +- Windows attribute support [PR 62](https://github.com/TimonPost/crossterm/pull/62) +- Readline bug fix windows systems [PR 62](https://github.com/TimonPost/crossterm/pull/62) +- Error handling improvement. +- General refactoring, all warnings removed. +- Documentation improvement. + # Changes crossterm 0.5.1 - Documentation refactor. - Fixed broken API documentation [PR 53](https://github.com/TimonPost/crossterm/pull/53). diff --git a/docs/UpgradeManual.md b/docs/UpgradeManual.md index 8dbfb28..f487c33 100644 --- a/docs/UpgradeManual.md +++ b/docs/UpgradeManual.md @@ -2,7 +2,7 @@ ***WARNING*** -I workded on making the user API more conviniant therefore I had to make some chages to the user API. The problem with `0.4` is that you need to pass a `Screen` to the modules: `cursor(), color(), terminal()`. +I workded on making the user API more convenient therefore I had to make some changes to the user API. The problem with `0.4` is that you need to pass a `Screen` to the modules: `cursor(), color(), terminal()`. In the new situation you only have to do this when working with raw or alternate screen. When you just want to perform actions like styling on the main screen you don't have to to pass in the `Screen` any more. This will look like the following: diff --git a/docs/know_problems.md b/docs/know_problems.md new file mode 100644 index 0000000..baea455 --- /dev/null +++ b/docs/know_problems.md @@ -0,0 +1,8 @@ +There are some problems I discovered during development. +And I don't think it has to do anything with crossterm but it has to do whit how terminals handle ANSI or WinApi. + +# Winapi-problems +- Power shell does not interpreter 'DarkYellow' and is instead using gray instead, cmd is working perfectly fine. + +# UNIX-terminals +The Arc and Manjaro KDE Konsole's are not seeming to resize the terminal instead they are resizing the buffer. \ No newline at end of file diff --git a/docs/mdbook/src/input.md b/docs/mdbook/src/input.md index 7072332..2b77f5e 100644 --- a/docs/mdbook/src/input.md +++ b/docs/mdbook/src/input.md @@ -45,7 +45,7 @@ This thread send all input via an 'mpsc' channel to the `AsyncReader` we got bac By calling `bytes()` on the `AsyncReader` we get an iterator back over the characters (bytes). -``` +```rust let mut stdin = input.read_async().bytes(); /* next code here */ @@ -55,7 +55,7 @@ Now we got an iterator back we can call `next()` on it to get the next pressed c If an character is pressed we will get `Some(Ok(u8))` back which we compare to see if 'x' is pressed. If the 'x' is pressed we break the loop. -``` +```rust loop { let pressed_char: Option> = stdin.next(); diff --git a/docs/some_common_bugs.txt b/docs/some_common_bugs.txt deleted file mode 100644 index 5b5f519..0000000 --- a/docs/some_common_bugs.txt +++ /dev/null @@ -1,2 +0,0 @@ -Power shell does not interpreter 'DarkYellow' and is instead using gray Winapi. -Arc and manjaro konsole are not seeming to resize the terminal instead they are resizeing the buffer. \ No newline at end of file diff --git a/examples/examples.rs b/examples/examples.rs index 7ba3e2f..fc3dcf8 100644 --- a/examples/examples.rs +++ b/examples/examples.rs @@ -16,7 +16,7 @@ mod terminal; fn main() { let cursor = crossterm::cursor(); - cursor.goto(5,5); + cursor.goto(5, 5); let integer = 10; let float: f32 = integert as f32; diff --git a/src/common/error.rs b/src/common/error.rs index 88f295d..a85c3f2 100644 --- a/src/common/error.rs +++ b/src/common/error.rs @@ -48,4 +48,4 @@ impl From for ErrorKind { fn from(e: fmt::Error) -> ErrorKind { ErrorKind::FmtError(e) } -} \ No newline at end of file +} diff --git a/src/common/functions.rs b/src/common/functions.rs index b86cd65..2c6d344 100644 --- a/src/common/functions.rs +++ b/src/common/functions.rs @@ -67,11 +67,11 @@ pub fn get_module(winapi_impl: T, unix_impl: T) -> Option { let mut does_support = false; if !windows_supportable() { -// Try to enable ansi on windows if not than use WINAPI. + // Try to enable ansi on windows if not than use WINAPI. does_support = try_enable_ansi_support(); -// -// uncomment this line when you want to use the winapi implementation. -// does_support = false; + // + // uncomment this line when you want to use the winapi implementation. + // does_support = false; if !does_support { term = Some(winapi_impl); } diff --git a/src/common/mod.rs b/src/common/mod.rs index dfbe616..6387220 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -3,12 +3,12 @@ #[macro_use] pub mod macros; pub mod commands; +pub mod error; pub mod functions; pub mod screen; pub mod traits; -pub mod error; mod crossterm; pub use self::crossterm::Crossterm; -use TerminalOutput; \ No newline at end of file +use TerminalOutput; diff --git a/src/common/screen/alternate.rs b/src/common/screen/alternate.rs index 1ec2a2d..af4b0ad 100644 --- a/src/common/screen/alternate.rs +++ b/src/common/screen/alternate.rs @@ -44,7 +44,8 @@ impl AlternateScreen { functions::get_module::>( Box::from(commands::win_commands::ToAlternateScreenCommand::new()), Box::from(commands::shared_commands::ToAlternateScreenCommand::new()), - ).unwrap(); + ) + .unwrap(); #[cfg(not(target_os = "windows"))] let command = Box::from(commands::shared_commands::ToAlternateScreenCommand::new()); diff --git a/src/kernel/windows_kernel/mod.rs b/src/kernel/windows_kernel/mod.rs index d6d50ff..8deb32f 100644 --- a/src/kernel/windows_kernel/mod.rs +++ b/src/kernel/windows_kernel/mod.rs @@ -1,9 +1,9 @@ //! This module contains the `windows` (unsafe) logic. -#[allow(unused)] -mod reading; pub mod ansi_support; mod cursor; +#[allow(unused)] +mod reading; pub mod writing; pub use self::cursor::Cursor; @@ -15,4 +15,4 @@ pub use crossterm_winapi::{ /// Exit the current process. pub fn exit() { ::std::process::exit(256); -} \ No newline at end of file +} diff --git a/src/lib.rs b/src/lib.rs index 2d6aa34..922c4df 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -302,10 +302,10 @@ extern crate libc; #[cfg(unix)] extern crate termios; -#[cfg(windows)] -extern crate winapi; #[cfg(windows)] extern crate crossterm_winapi; +#[cfg(windows)] +extern crate winapi; #[macro_use] mod common; diff --git a/src/modules/cursor/ansi_cursor.rs b/src/modules/cursor/ansi_cursor.rs index 70431c9..c94ba12 100644 --- a/src/modules/cursor/ansi_cursor.rs +++ b/src/modules/cursor/ansi_cursor.rs @@ -49,22 +49,22 @@ impl ITerminalCursor for AnsiCursor { Ok(()) } - fn reset_position(&self, stdout: &Option<&Arc>)-> Result<()> { + fn reset_position(&self, stdout: &Option<&Arc>) -> Result<()> { functions::write_str(stdout, csi!("u"))?; Ok(()) } - fn hide(&self, stdout: &Option<&Arc>)-> Result<()> { + fn hide(&self, stdout: &Option<&Arc>) -> Result<()> { functions::write_str(stdout, csi!("?25l"))?; Ok(()) } - fn show(&self, stdout: &Option<&Arc>) -> Result<()>{ + fn show(&self, stdout: &Option<&Arc>) -> Result<()> { functions::write_str(stdout, csi!("?25h"))?; Ok(()) } - fn blink(&self, blink: bool, stdout: &Option<&Arc>) -> Result<()>{ + fn blink(&self, blink: bool, stdout: &Option<&Arc>) -> Result<()> { if blink { functions::write_str(stdout, csi!("?12h"))?; } else { diff --git a/src/modules/cursor/cursor.rs b/src/modules/cursor/cursor.rs index 76087ea..7c69c20 100644 --- a/src/modules/cursor/cursor.rs +++ b/src/modules/cursor/cursor.rs @@ -133,7 +133,9 @@ impl<'stdout> TerminalCursor<'stdout> { /// cursor.move_right(3); /// ``` pub fn move_right(&mut self, count: u16) -> &mut TerminalCursor<'stdout> { - self.terminal_cursor.move_right(count, &self.stdout).unwrap(); + self.terminal_cursor + .move_right(count, &self.stdout) + .unwrap(); self } diff --git a/src/modules/cursor/mod.rs b/src/modules/cursor/mod.rs index 8906966..b80b491 100644 --- a/src/modules/cursor/mod.rs +++ b/src/modules/cursor/mod.rs @@ -17,8 +17,8 @@ use self::ansi_cursor::AnsiCursor; use self::winapi_cursor::WinApiCursor; pub use self::cursor::{cursor, from_screen, TerminalCursor}; -use common::error::Result; use super::functions; +use common::error::Result; use std::sync::Arc; use TerminalOutput; diff --git a/src/modules/cursor/winapi_cursor.rs b/src/modules/cursor/winapi_cursor.rs index d754859..fdf5157 100644 --- a/src/modules/cursor/winapi_cursor.rs +++ b/src/modules/cursor/winapi_cursor.rs @@ -2,9 +2,9 @@ //! This module is used for Windows terminals that do not support ANSI escape codes. //! Note that the cursor position is 0 based. This means that we start counting at 0 when setting the cursor position. -use kernel::windows_kernel::{Cursor, Handle}; -use common::error::Result; use super::*; +use common::error::Result; +use kernel::windows_kernel::{Cursor, Handle}; /// This struct is a windows implementation for cursor related actions. pub struct WinApiCursor; @@ -71,5 +71,7 @@ impl ITerminalCursor for WinApiCursor { Ok(()) } - fn blink(&self, _blink: bool, _stdout: &Option<&Arc>) -> Result<()> { Ok(()) } + fn blink(&self, _blink: bool, _stdout: &Option<&Arc>) -> Result<()> { + Ok(()) + } } diff --git a/src/modules/style/ansi_color.rs b/src/modules/style/ansi_color.rs index cfd7513..28724e8 100644 --- a/src/modules/style/ansi_color.rs +++ b/src/modules/style/ansi_color.rs @@ -25,7 +25,7 @@ impl ITerminalColor for AnsiColor { Ok(()) } - fn set_bg(&self, bg_color: Color, stdout: &Option<&Arc>)-> Result<()> { + fn set_bg(&self, bg_color: Color, stdout: &Option<&Arc>) -> Result<()> { functions::write( stdout, format!( @@ -36,7 +36,7 @@ impl ITerminalColor for AnsiColor { Ok(()) } - fn reset(&self, stdout: &Option<&Arc>)-> Result<()>{ + fn reset(&self, stdout: &Option<&Arc>) -> Result<()> { functions::write_str(stdout, csi!("0m"))?; Ok(()) } @@ -81,4 +81,4 @@ impl ITerminalColor for AnsiColor { ansi_value.push_str(color_val); ansi_value } -} \ No newline at end of file +} diff --git a/src/modules/style/color.rs b/src/modules/style/color.rs index 0062f58..8aadaa9 100644 --- a/src/modules/style/color.rs +++ b/src/modules/style/color.rs @@ -94,7 +94,7 @@ impl<'stdout> TerminalColor<'stdout> { /// // crossterm provides to set the background from &str or String /// colored_terminal.set_fg(Color::from("Red")); /// ``` - pub fn set_fg(&self, color: Color)-> Result<()> { + pub fn set_fg(&self, color: Color) -> Result<()> { self.color.set_fg(color, &self.stdout) } @@ -108,7 +108,7 @@ impl<'stdout> TerminalColor<'stdout> { /// // crossterm provides to set the background from &str or String /// colored_terminal.set_bg(Color::from("Red")); /// ``` - pub fn set_bg(&self, color: Color) -> Result<()>{ + pub fn set_bg(&self, color: Color) -> Result<()> { self.color.set_bg(color, &self.stdout) } @@ -118,7 +118,7 @@ impl<'stdout> TerminalColor<'stdout> { /// let colored_terminal = color(); /// colored_terminal.reset(); /// ``` - pub fn reset(&self)-> Result<()> { + pub fn reset(&self) -> Result<()> { self.color.reset(&self.stdout) } diff --git a/src/modules/style/mod.rs b/src/modules/style/mod.rs index 0239c52..6b4fdd3 100644 --- a/src/modules/style/mod.rs +++ b/src/modules/style/mod.rs @@ -22,7 +22,7 @@ pub use self::color::{color, from_screen, TerminalColor}; pub use self::objectstyle::ObjectStyle; pub use self::styledobject::DisplayableObject; pub use self::styledobject::StyledObject; -use common::{functions, error::Result}; +use common::{error::Result, functions}; use TerminalOutput; diff --git a/src/modules/style/styledobject.rs b/src/modules/style/styledobject.rs index efec113..5d0ae92 100644 --- a/src/modules/style/styledobject.rs +++ b/src/modules/style/styledobject.rs @@ -3,9 +3,9 @@ use super::{color, from_screen, Color, ObjectStyle}; use Screen; +use common::error::Result; use std::fmt::{self, Display, Formatter}; use std::io::Write; -use common::error::Result; use std::result; use super::Attribute; @@ -255,4 +255,4 @@ impl<'a, D: Display + 'a> Display for DisplayableObject<'a, D> { self.styled_object.paint(&self.screen).unwrap(); Ok(()) } -} \ No newline at end of file +} diff --git a/src/modules/style/winapi_color.rs b/src/modules/style/winapi_color.rs index 6658594..3eb458a 100644 --- a/src/modules/style/winapi_color.rs +++ b/src/modules/style/winapi_color.rs @@ -2,11 +2,11 @@ //! This module is used for non supporting `ANSI` Windows terminals. use super::*; +use common::error::Result; use kernel::windows_kernel::{Console, Handle, HandleType, ScreenBuffer}; use std::io; use std::sync::{Once, ONCE_INIT}; use winapi::um::wincon; -use common::error::Result; /// This struct is a WinApi implementation for color related actions. pub struct WinApiColor; @@ -18,7 +18,7 @@ impl WinApiColor { } impl ITerminalColor for WinApiColor { - fn set_fg(&self, fg_color: Color, _stdout: &Option<&Arc>) -> Result<()>{ + fn set_fg(&self, fg_color: Color, _stdout: &Option<&Arc>) -> Result<()> { // init the original color in case it is not set. let _ = init_console_color()?; @@ -40,8 +40,7 @@ impl ITerminalColor for WinApiColor { color = color | wincon::BACKGROUND_INTENSITY as u16; } - Console::from(**screen_buffer.get_handle()) - .set_text_attribute(color)?; + Console::from(**screen_buffer.get_handle()).set_text_attribute(color)?; Ok(()) } @@ -68,8 +67,7 @@ impl ITerminalColor for WinApiColor { color = color | wincon::FOREGROUND_INTENSITY as u16; } - Console::from(**screen_buffer.get_handle()) - .set_text_attribute(color)?; + Console::from(**screen_buffer.get_handle()).set_text_attribute(color)?; Ok(()) } diff --git a/src/modules/terminal/ansi_terminal.rs b/src/modules/terminal/ansi_terminal.rs index 9429114..5151dc3 100644 --- a/src/modules/terminal/ansi_terminal.rs +++ b/src/modules/terminal/ansi_terminal.rs @@ -41,7 +41,7 @@ impl ITerminal for AnsiTerminal { functions::get_terminal_size() } - fn scroll_up(&self, count: i16, stdout: &Option<&Arc>) -> Result<()>{ + fn scroll_up(&self, count: i16, stdout: &Option<&Arc>) -> Result<()> { functions::write(&stdout, format!(csi!("{}S"), count))?; Ok(()) } @@ -51,7 +51,12 @@ impl ITerminal for AnsiTerminal { Ok(()) } - fn set_size(&self, width: i16, height: i16, stdout: &Option<&Arc>) -> Result<()> { + fn set_size( + &self, + width: i16, + height: i16, + stdout: &Option<&Arc>, + ) -> Result<()> { functions::write(&stdout, format!(csi!("8;{};{}t"), height, width))?; Ok(()) } diff --git a/src/modules/terminal/mod.rs b/src/modules/terminal/mod.rs index 4a59c26..388cc2d 100644 --- a/src/modules/terminal/mod.rs +++ b/src/modules/terminal/mod.rs @@ -15,7 +15,7 @@ use self::winapi_terminal::WinApiTerminal; pub use self::terminal::{from_screen, terminal, Terminal}; -use common::{functions, error}; +use common::{error, functions}; use std::sync::Arc; use {Screen, TerminalOutput}; @@ -38,7 +38,11 @@ pub enum ClearType { /// so that terminal related actions can be preformed on both Unix and Windows systems. trait ITerminal { /// Clear the current cursor by specifying the clear type - fn clear(&self, clear_type: ClearType, stdout: &Option<&Arc>) -> error::Result<()>; + fn clear( + &self, + clear_type: ClearType, + stdout: &Option<&Arc>, + ) -> error::Result<()>; /// Get the terminal size (x,y) fn terminal_size(&self, stdout: &Option<&Arc>) -> (u16, u16); /// Scroll `n` lines up in the current terminal. @@ -46,7 +50,12 @@ trait ITerminal { /// Scroll `n` lines down in the current terminal. fn scroll_down(&self, count: i16, stdout: &Option<&Arc>) -> error::Result<()>; /// Resize terminal to the given width and height. - fn set_size(&self, width: i16, height: i16, stdout: &Option<&Arc>) -> error::Result<()>; + fn set_size( + &self, + width: i16, + height: i16, + stdout: &Option<&Arc>, + ) -> error::Result<()>; /// Close the current terminal fn exit(&self, stdout: &Option<&Arc>); } diff --git a/src/modules/terminal/winapi_terminal.rs b/src/modules/terminal/winapi_terminal.rs index 62a6951..81af720 100644 --- a/src/modules/terminal/winapi_terminal.rs +++ b/src/modules/terminal/winapi_terminal.rs @@ -4,7 +4,7 @@ //! Windows versions lower then windows 10 are not supporting ANSI codes. Those versions will use this implementation instead. use super::*; -use common::error::{Result, ErrorKind}; +use common::error::{ErrorKind, Result}; use kernel::windows_kernel::{Console, Coord, Cursor, Handle, ScreenBuffer, Size}; /// This struct is an winapi implementation for terminal related actions. @@ -56,31 +56,39 @@ impl ITerminal for WinApiTerminal { Ok(()) } - fn scroll_down(&self, count: i16, _stdout: &Option<&Arc>) -> Result<()>{ + fn scroll_down(&self, count: i16, _stdout: &Option<&Arc>) -> Result<()> { let screen_buffer = ScreenBuffer::current()?; let csbi = screen_buffer.info()?; let mut window = csbi.terminal_window(); - let buffer_size =csbi.buffer_size(); + let buffer_size = csbi.buffer_size(); // Check whether the window is too close to the screen buffer top if window.bottom < buffer_size.height - count { window.top += count; // move top down window.bottom += count; // move bottom down - Console::new()? - .set_console_info(false, window)?; + Console::new()?.set_console_info(false, window)?; } Ok(()) } /// Set the current terminal size - fn set_size(&self, width: i16, height: i16, _stdout: &Option<&Arc>) -> Result<()> { + fn set_size( + &self, + width: i16, + height: i16, + _stdout: &Option<&Arc>, + ) -> Result<()> { if width <= 0 { - return Err(ErrorKind::ResizingTerminalFailure(String::from("Cannot set the terminal width lower than 1"))); + return Err(ErrorKind::ResizingTerminalFailure(String::from( + "Cannot set the terminal width lower than 1", + ))); } if height <= 0 { - return Err(ErrorKind::ResizingTerminalFailure(String::from("Cannot set the terminal height lower then 1"))); + return Err(ErrorKind::ResizingTerminalFailure(String::from( + "Cannot set the terminal height lower then 1", + ))); } // Get the position of the current console window @@ -99,7 +107,9 @@ impl ITerminal for WinApiTerminal { if current_size.width < window.left + width { if window.left >= i16::max_value() - width { - return Err(ErrorKind::ResizingTerminalFailure(String::from("Argument out of range when setting terminal width."))); + return Err(ErrorKind::ResizingTerminalFailure(String::from( + "Argument out of range when setting terminal width.", + ))); } new_size.width = window.left + width; @@ -107,7 +117,9 @@ impl ITerminal for WinApiTerminal { } if current_size.height < window.top + height { if window.top >= i16::max_value() - height { - return Err(ErrorKind::ResizingTerminalFailure(String::from("Argument out of range when setting terminal height."))); + return Err(ErrorKind::ResizingTerminalFailure(String::from( + "Argument out of range when setting terminal height.", + ))); } new_size.height = window.top + height; @@ -116,7 +128,9 @@ impl ITerminal for WinApiTerminal { if resize_buffer { if let Err(_) = screen_buffer.set_size(new_size.width, new_size.height) { - return Err(ErrorKind::ResizingTerminalFailure(String::from("Something went wrong when setting screen buffer size."))); + return Err(ErrorKind::ResizingTerminalFailure(String::from( + "Something went wrong when setting screen buffer size.", + ))); } } @@ -129,17 +143,25 @@ impl ITerminal for WinApiTerminal { // If we resized the buffer, un-resize it. if resize_buffer { if let Err(_) = screen_buffer.set_size(current_size.width, current_size.height) { - return Err(ErrorKind::ResizingTerminalFailure(String::from("Something went wrong when setting screen buffer size."))); + return Err(ErrorKind::ResizingTerminalFailure(String::from( + "Something went wrong when setting screen buffer size.", + ))); } } let bounds = console.largest_window_size(); if width > bounds.x { - return Err(ErrorKind::ResizingTerminalFailure(format!("Argument width: {} out of range when setting terminal width.", width))); + return Err(ErrorKind::ResizingTerminalFailure(format!( + "Argument width: {} out of range when setting terminal width.", + width + ))); } if height > bounds.y { - return Err(ErrorKind::ResizingTerminalFailure(format!("Argument height: {} out of range when setting terminal height", width))); + return Err(ErrorKind::ResizingTerminalFailure(format!( + "Argument height: {} out of range when setting terminal height", + width + ))); } Ok(()) @@ -155,7 +177,11 @@ impl ITerminal for WinApiTerminal { } } -pub fn clear_after_cursor(location: Coord, buffer_size: Size, current_attribute: u16) -> Result<()> { +pub fn clear_after_cursor( + location: Coord, + buffer_size: Size, + current_attribute: u16, +) -> Result<()> { let (mut x, mut y) = (location.x, location.y); // if cursor position is at the outer right position @@ -173,7 +199,11 @@ pub fn clear_after_cursor(location: Coord, buffer_size: Size, current_attribute: clear(start_location, cells_to_write, current_attribute) } -pub fn clear_before_cursor(location: Coord, buffer_size: Size, current_attribute: u16) -> Result<()> { +pub fn clear_before_cursor( + location: Coord, + buffer_size: Size, + current_attribute: u16, +) -> Result<()> { let (xpos, ypos) = (location.x, location.y); // one cell after cursor position @@ -207,7 +237,11 @@ pub fn clear_entire_screen(buffer_size: Size, current_attribute: u16) -> Result< Ok(()) } -pub fn clear_current_line(location: Coord, buffer_size: Size, current_attribute: u16) -> Result<()> { +pub fn clear_current_line( + location: Coord, + buffer_size: Size, + current_attribute: u16, +) -> Result<()> { // location where to start clearing let start_location = Coord::new(0, location.y); @@ -243,10 +277,8 @@ pub fn clear_until_line(location: Coord, buffer_size: Size, current_attribute: u fn clear(start_location: Coord, cells_to_write: u32, current_attribute: u16) -> Result<()> { let console = Console::from(Handle::current_out_handle()?); - let _ = console - .fill_whit_character(start_location, cells_to_write, ' ')?; - console - .fill_whit_attribute(start_location, cells_to_write, current_attribute)?; + let _ = console.fill_whit_character(start_location, cells_to_write, ' ')?; + console.fill_whit_attribute(start_location, cells_to_write, current_attribute)?; Ok(()) }