rounding up
This commit is contained in:
parent
5777eaab1d
commit
c40cdb0774
@ -74,13 +74,13 @@ impl IEnableAnsiCommand for EnableAnsiCommand {
|
|||||||
pub struct RawModeCommand {
|
pub struct RawModeCommand {
|
||||||
mask: DWORD,
|
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
|
impl RawModeCommand
|
||||||
{
|
{
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
RawModeCommand {
|
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.
|
/// Enables raw mode.
|
||||||
pub fn enable(&mut self) -> Result<()> {
|
pub fn enable(&mut self) -> Result<()> {
|
||||||
let mut dw_mode: DWORD = 0;
|
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) {
|
if !kernel::get_console_mode(&stdout, &mut dw_mode) {
|
||||||
return Err(Error::new(
|
return Err(Error::new(
|
||||||
@ -100,19 +100,19 @@ impl RawModeCommand {
|
|||||||
|
|
||||||
let new_mode = dw_mode & !self.mask;
|
let new_mode = dw_mode & !self.mask;
|
||||||
|
|
||||||
if !kernel::set_console_mode(&stdout, new_mode) {
|
// if !kernel::set_console_mode(&stdout, new_mode) {
|
||||||
return Err(Error::new(
|
// return Err(Error::new(
|
||||||
ErrorKind::Other,
|
// ErrorKind::Other,
|
||||||
"Could not set console mode when enabling raw mode",
|
// "Could not set console mode when enabling raw mode",
|
||||||
));
|
// ));
|
||||||
}
|
// }
|
||||||
|
self.disable();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Disables raw mode.
|
/// Disables raw mode.
|
||||||
pub fn disable(&self) -> Result<()> {
|
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;
|
let mut dw_mode: DWORD = 0;
|
||||||
if !kernel::get_console_mode(&stdout, &mut dw_mode) {
|
if !kernel::get_console_mode(&stdout, &mut dw_mode) {
|
||||||
|
@ -24,7 +24,7 @@ use std::sync::Arc;
|
|||||||
pub struct RawScreen;
|
pub struct RawScreen;
|
||||||
|
|
||||||
impl 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<()>
|
pub fn into_raw_mode() -> io::Result<()>
|
||||||
{
|
{
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
@ -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`.
|
/// 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()`.
|
/// 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.
|
/// 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
|
/// ```rust
|
||||||
@ -48,7 +68,7 @@ pub struct Screen
|
|||||||
|
|
||||||
impl 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.
|
/// 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
|
pub fn new(raw_mode: bool) -> Screen
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user