From c40cdb07742be1a19ea45fcb23798c6e24663341 Mon Sep 17 00:00:00 2001 From: TimonPost Date: Sat, 25 Aug 2018 11:24:51 +0200 Subject: [PATCH] rounding up --- src/common/commands/win_commands.rs | 22 +++++++++++----------- src/common/screen/raw.rs | 2 +- src/common/screen/screen.rs | 22 +++++++++++++++++++++- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/common/commands/win_commands.rs b/src/common/commands/win_commands.rs index 957496f..4ac373b 100644 --- a/src/common/commands/win_commands.rs +++ b/src/common/commands/win_commands.rs @@ -74,13 +74,13 @@ impl IEnableAnsiCommand for EnableAnsiCommand { pub struct RawModeCommand { mask: DWORD, } -use self::wincon::{ENABLE_ECHO_INPUT, ENABLE_LINE_INPUT, ENABLE_PROCESSED_INPUT, ENABLE_WRAP_AT_EOL_OUTPUT, ENABLE_PROCESSED_OUTPUT}; +use self::wincon::{ ENABLE_LINE_INPUT, ENABLE_WRAP_AT_EOL_OUTPUT}; impl RawModeCommand { pub fn new() -> Self { RawModeCommand { - mask: ENABLE_WRAP_AT_EOL_OUTPUT | ENABLE_LINE_INPUT + mask: ENABLE_WRAP_AT_EOL_OUTPUT | ENABLE_LINE_INPUT } } } @@ -89,7 +89,7 @@ impl RawModeCommand { /// Enables raw mode. pub fn enable(&mut self) -> Result<()> { let mut dw_mode: DWORD = 0; - let stdout = handle::get_current_handle().unwrap(); + let stdout = handle::get_output_handle().unwrap(); if !kernel::get_console_mode(&stdout, &mut dw_mode) { return Err(Error::new( @@ -100,19 +100,19 @@ impl RawModeCommand { let new_mode = dw_mode & !self.mask; - if !kernel::set_console_mode(&stdout, new_mode) { - return Err(Error::new( - ErrorKind::Other, - "Could not set console mode when enabling raw mode", - )); - } - +// if !kernel::set_console_mode(&stdout, new_mode) { +// return Err(Error::new( +// ErrorKind::Other, +// "Could not set console mode when enabling raw mode", +// )); +// } +self.disable(); Ok(()) } /// Disables raw mode. pub fn disable(&self) -> Result<()> { - let stdout = handle::get_current_handle().unwrap(); + let stdout = handle::get_output_handle().unwrap(); let mut dw_mode: DWORD = 0; if !kernel::get_console_mode(&stdout, &mut dw_mode) { diff --git a/src/common/screen/raw.rs b/src/common/screen/raw.rs index dbb16bb..9796001 100644 --- a/src/common/screen/raw.rs +++ b/src/common/screen/raw.rs @@ -24,7 +24,7 @@ use std::sync::Arc; pub struct RawScreen; impl RawScreen { - /// Put terminal in raw mode. How ever using the `Screen` type to enable raw mode is much better. + /// Put terminal in raw mode. pub fn into_raw_mode() -> io::Result<()> { #[cfg(not(target_os = "windows"))] diff --git a/src/common/screen/screen.rs b/src/common/screen/screen.rs index 4e82346..7eed3f0 100644 --- a/src/common/screen/screen.rs +++ b/src/common/screen/screen.rs @@ -11,6 +11,26 @@ use std::sync::Arc; /// You have to make sure that you pass the correct `Screen` to the modules `cursor, terminal, color, input, style`. /// Most of the time you just have one screen so you could get an instance of that screen with: `Screen::default()`. /// +/// The screen can be in two modes at first: +/// - Alternate modes: +/// +/// *Nix style applications often utilize an alternate screen buffer, so that they can modify the entire contents of the buffer, without affecting the application that started them. +/// The alternate buffer is exactly the dimensions of the window, without any scrollback region. +/// For an example of this behavior, consider when vim is launched from bash. +/// Vim uses the entirety of the screen to edit the file, then returning to bash leaves the original buffer unchanged. +/// +/// - RawModes +/// - No line buffering. +/// Normally the terminals uses line buffering. This means that the input will be send to the terminal line by line. +/// With raw mode the input will be send one byte at a time. +/// - Input +/// All input has to be written manually by the programmer. +/// - Characters +/// The characters are not processed by the terminal driver, but are sent straight through. +/// Special character have no meaning, like backspace will not be interpret as backspace but instead will be directly send to the terminal. +/// - Escape characters +/// Note that in raw modes `\n` `\r` will move to the new line but the cursor will be at the same position as before on the new line therefor use `\n\r` to start at the new line at the first cell. +/// /// Also this screen has an buffer where you can write to. When you want to write the buffer to the screen you could flush the screen. /// /// ```rust @@ -48,7 +68,7 @@ pub struct Screen impl Screen { - /// Create new instance of the Screen also specify if the current screen should be in raw mode or normal mode. Check out `RawScreen` type for more info. + /// Create new instance of the Screen also specify if the current screen should be in raw mode or normal mode. /// If you are not sure what raw mode is then pass false or use the `Screen::default()` to create an instance. pub fn new(raw_mode: bool) -> Screen {