fixed some bugs, checked documentation and incremented version number
This commit is contained in:
parent
9102108b3a
commit
ff41d4f244
@ -1,12 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "crossterm"
|
name = "crossterm"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
authors = ["T Post <timonpost@hotmail.nl>"]
|
authors = ["T Post <timonpost@hotmail.nl>"]
|
||||||
description = "An crossplatform terminal library for manipulating terminals."
|
description = "An crossplatform terminal library for manipulating terminals."
|
||||||
repository = "https://github.com/TimonPost/crossterm"
|
repository = "https://github.com/TimonPost/crossterm"
|
||||||
documentation = "https://docs.rs/crossterm/"
|
documentation = "https://docs.rs/crossterm/"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
keywords = ["console", "color", "cursor", "terminal", "cli"]
|
keywords = ["console", "color", "cursor", "input", "terminal"]
|
||||||
exclude = ["target", "Cargo.lock"]
|
exclude = ["target", "Cargo.lock"]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@ use std::io::Write;
|
|||||||
use std::{thread,time};
|
use std::{thread,time};
|
||||||
fn main()
|
fn main()
|
||||||
{
|
{
|
||||||
input::keyboard::async_input::read_async_demo();
|
::crossterm::terminal::terminal(&::crossterm::Screen::default()).terminal_size();
|
||||||
terminal::raw_mode::print_wait_screen_on_alternate_window();
|
|
||||||
thread::sleep(time::Duration::from_millis(2000));
|
thread::sleep(time::Duration::from_millis(2000));
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,8 @@ impl RawModeCommand
|
|||||||
{
|
{
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
RawModeCommand {
|
RawModeCommand {
|
||||||
mask: ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_OUTPUT ,
|
|
||||||
|
mask: ENABLE_WRAP_AT_EOL_OUTPUT | ENABLE_LINE_INPUT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,7 +147,6 @@ impl ToAlternateScreenCommand {
|
|||||||
|
|
||||||
impl IAlternateScreenCommand for ToAlternateScreenCommand {
|
impl IAlternateScreenCommand for ToAlternateScreenCommand {
|
||||||
fn enable(&self, stdout: &mut TerminalOutput) -> Result<()> {
|
fn enable(&self, stdout: &mut TerminalOutput) -> Result<()> {
|
||||||
use super::super::super::modules::output::WinApiOutput;
|
|
||||||
|
|
||||||
let handle = handle::get_output_handle()?;
|
let handle = handle::get_output_handle()?;
|
||||||
|
|
||||||
|
@ -101,10 +101,13 @@ impl<'crossterm> Crossterm {
|
|||||||
/// This could be used to style an `Displayable` type with colors and attributes.
|
/// This could be used to style an `Displayable` type with colors and attributes.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use crossterm::Screen ;
|
/// extern crate crossterm;
|
||||||
|
/// use crossterm::{Crossterm, Screen};
|
||||||
|
///
|
||||||
|
/// let crossterm = Crossterm::new(&Screen::default());
|
||||||
///
|
///
|
||||||
/// // get an styled object which could be painted to the terminal.
|
/// // get an styled object which could be painted to the terminal.
|
||||||
/// let styled_object = style("Some Blue colored text on black background")
|
/// let styled_object = crossterm.style("Some Blue colored text on black background")
|
||||||
/// .with(Color::Blue)
|
/// .with(Color::Blue)
|
||||||
/// .on(Color::Black);
|
/// .on(Color::Black);
|
||||||
///
|
///
|
||||||
|
@ -44,10 +44,10 @@ pub fn get_module<T>(winapi_impl: T, unix_impl: T) -> Option<T> {
|
|||||||
if !windows_supportable()
|
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();
|
does_support = try_enable_ansi_support();
|
||||||
|
|
||||||
// uncomment this line when you want to use the winapi implementation.
|
// uncomment this line when you want to use the winapi implementation.
|
||||||
does_support = false;
|
// does_support = false;
|
||||||
if !does_support {
|
if !does_support {
|
||||||
term = Some(winapi_impl);
|
term = Some(winapi_impl);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
//! This module contains all the logic for switching between alternate screen and main screen.
|
//! This module contains all the logic for switching between alternate screen and main screen.
|
||||||
//!
|
//!
|
||||||
//!
|
|
||||||
//! *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.
|
//! *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.
|
//! 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.
|
//! For an example of this behavior, consider when vim is launched from bash.
|
||||||
@ -13,6 +12,7 @@ use std::io;
|
|||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
|
|
||||||
/// With this type you will be able to switch to alternate screen and back to main screen.
|
/// With this type you will be able to switch to alternate screen and back to main screen.
|
||||||
|
/// Check also the Screen type for swishing to alternate mode.
|
||||||
pub struct AlternateScreen
|
pub struct AlternateScreen
|
||||||
{
|
{
|
||||||
command: Box<IAlternateScreenCommand + Sync + Send>,
|
command: Box<IAlternateScreenCommand + Sync + Send>,
|
||||||
@ -29,6 +29,8 @@ impl AlternateScreen {
|
|||||||
|
|
||||||
/// Switch to alternate screen. This function will return an `AlternateScreen` instance if everything went well this type will give you control over the `AlternateScreen`.
|
/// Switch to alternate screen. This function will return an `AlternateScreen` instance if everything went well this type will give you control over the `AlternateScreen`.
|
||||||
///
|
///
|
||||||
|
/// The bool specifies whether the screen should be in raw mode or not.
|
||||||
|
///
|
||||||
/// # What is Alternate screen?
|
/// # What is Alternate screen?
|
||||||
/// *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.
|
/// *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.
|
/// The alternate buffer is exactly the dimensions of the window, without any scrollback region.
|
||||||
|
@ -6,6 +6,6 @@ mod screen;
|
|||||||
|
|
||||||
use super::{commands, functions, TerminalOutput};
|
use super::{commands, functions, TerminalOutput};
|
||||||
|
|
||||||
|
pub use self::raw::RawScreen;
|
||||||
pub use self::alternate::AlternateScreen;
|
pub use self::alternate::AlternateScreen;
|
||||||
pub use self::screen::Screen;
|
pub use self::screen::Screen;
|
||||||
pub use self::raw::RawScreen;
|
|
||||||
|
@ -24,7 +24,7 @@ use std::sync::Arc;
|
|||||||
pub struct RawScreen;
|
pub struct RawScreen;
|
||||||
|
|
||||||
impl RawScreen {
|
impl RawScreen {
|
||||||
/// Put terminal in raw mode.
|
/// Put terminal in raw mode. How ever using the `Screen` type to enable raw mode is much better.
|
||||||
pub fn into_raw_mode() -> io::Result<()>
|
pub fn into_raw_mode() -> io::Result<()>
|
||||||
{
|
{
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
@ -13,8 +13,6 @@ use std::sync::Arc;
|
|||||||
///
|
///
|
||||||
/// 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.
|
||||||
///
|
///
|
||||||
/// #Example
|
|
||||||
///
|
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// // create default screen.
|
/// // create default screen.
|
||||||
/// let screen = Screen::default();
|
/// let screen = Screen::default();
|
||||||
@ -64,7 +62,9 @@ impl Screen
|
|||||||
return Screen::default();
|
return Screen::default();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Switch to alternate screen. This function will return an `AlternateScreen` instance if everything went well this type will give you control over the `AlternateScreen`.
|
/// Switch to alternate screen. This function will return an `AlternateScreen` instance. If everything went well this type will give you control over the `AlternateScreen`.
|
||||||
|
///
|
||||||
|
/// The bool 'raw_mode' specifies whether the alternate screen should be raw mode or not.
|
||||||
///
|
///
|
||||||
/// # What is Alternate screen?
|
/// # What is Alternate screen?
|
||||||
/// *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.
|
/// *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.
|
||||||
@ -92,7 +92,7 @@ impl Screen
|
|||||||
self.stdout.flush()
|
self.stdout.flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
// this will disable the drop which will cause raw modes not to be undone on drop of `Screen`.
|
/// This will disable the drop which will cause raw modes not to be undone on drop of `Screen`.
|
||||||
pub fn disable_drop(&mut self)
|
pub fn disable_drop(&mut self)
|
||||||
{
|
{
|
||||||
self.drop = false;
|
self.drop = false;
|
||||||
|
@ -9,7 +9,7 @@ use super::{csbi, handle, kernel, TerminalOutput};
|
|||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use kernel::windows_kernel::kernel::get_largest_console_window_size;
|
||||||
/// This stores the cursor pos, at program level. So it can be recalled later.
|
/// This stores the cursor pos, at program level. So it can be recalled later.
|
||||||
static mut SAVED_CURSOR_POS: (u16, u16) = (0, 0);
|
static mut SAVED_CURSOR_POS: (u16, u16) = (0, 0);
|
||||||
|
|
||||||
@ -75,6 +75,14 @@ pub fn set_console_cursor_position(x: i16, y: i16) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//pub fn set_relative_cursor_pos(x: i16, y: i16)
|
||||||
|
//{
|
||||||
|
// let (cur_x, cur_y) = pos()?;
|
||||||
|
// let Relative(x, y) = *self;
|
||||||
|
// let (x, y) = (x + cur_x, y + cur_y);
|
||||||
|
// platform::set_cursor_pos(x, y)?;
|
||||||
|
//}
|
||||||
|
|
||||||
/// change the cursor visibility.
|
/// change the cursor visibility.
|
||||||
pub fn cursor_visibility(visable: bool) -> io::Result<()> {
|
pub fn cursor_visibility(visable: bool) -> io::Result<()> {
|
||||||
let handle = handle::get_current_handle().unwrap();
|
let handle = handle::get_current_handle().unwrap();
|
||||||
|
@ -12,7 +12,6 @@ use winapi::um::wincon::{CONSOLE_SCREEN_BUFFER_INFO, COORD, SMALL_RECT};
|
|||||||
use winapi::um::winnt::HANDLE;
|
use winapi::um::winnt::HANDLE;
|
||||||
|
|
||||||
use TerminalOutput;
|
use TerminalOutput;
|
||||||
use super::super::modules::output::WinApiOutput;
|
|
||||||
|
|
||||||
use common::traits::Empty;
|
use common::traits::Empty;
|
||||||
|
|
||||||
|
@ -7,6 +7,10 @@ use std::sync::Arc;
|
|||||||
pub fn terminal_size() -> (u16, u16) {
|
pub fn terminal_size() -> (u16, u16) {
|
||||||
let handle = handle::get_output_handle().unwrap();
|
let handle = handle::get_output_handle().unwrap();
|
||||||
|
|
||||||
|
// if let Ok(csbi) = csbi::get_csbi_by_handle(&handle) {
|
||||||
|
// println!("right: {} left: {} bottom: {}, top: {} window top {} windows width {} csbi.dwCursorPosition.X {} csbi.dwCursorPosition.Y {}", csbi.srWindow.Right, csbi.srWindow.Left, csbi.srWindow.Bottom, csbi.srWindow.Top, csbi.dwSize.X,csbi.dwSize.Y, csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y);
|
||||||
|
// }
|
||||||
|
|
||||||
if let Ok(csbi) = csbi::get_csbi_by_handle(&handle) {
|
if let Ok(csbi) = csbi::get_csbi_by_handle(&handle) {
|
||||||
(
|
(
|
||||||
(csbi.srWindow.Right - csbi.srWindow.Left) as u16,
|
(csbi.srWindow.Right - csbi.srWindow.Left) as u16,
|
||||||
|
@ -9,14 +9,14 @@ mod common;
|
|||||||
mod kernel;
|
mod kernel;
|
||||||
mod modules;
|
mod modules;
|
||||||
|
|
||||||
pub use common::screen;
|
use common::screen;
|
||||||
pub use modules::cursor;
|
pub use modules::cursor;
|
||||||
pub use modules::input;
|
pub use modules::input;
|
||||||
pub use modules::output;
|
pub use modules::output;
|
||||||
pub use modules::style;
|
pub use modules::style;
|
||||||
pub use modules::terminal;
|
pub use modules::terminal;
|
||||||
|
|
||||||
pub use common::screen::Screen;
|
pub use common::screen::{Screen, AlternateScreen};
|
||||||
pub use common::Crossterm;
|
pub use common::Crossterm;
|
||||||
pub use output::TerminalOutput;
|
pub use output::TerminalOutput;
|
||||||
pub use self::cursor::*;
|
pub use self::cursor::*;
|
||||||
@ -24,7 +24,6 @@ pub use self::input::*;
|
|||||||
pub use self::output::*;
|
pub use self::output::*;
|
||||||
pub use self::style::*;
|
pub use self::style::*;
|
||||||
|
|
||||||
use output::IStdout;
|
|
||||||
use common::functions;
|
use common::functions;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
@ -70,6 +70,9 @@ impl<'stdout> TerminalInput<'stdout> {
|
|||||||
|
|
||||||
/// Read the input asynchronously from the user.
|
/// Read the input asynchronously from the user.
|
||||||
///
|
///
|
||||||
|
/// This call will not block the current thread.
|
||||||
|
// Under the hood a thread is fired which will read input on unix systems from TTY and on windows systems with '_getwch' and '_getwche'
|
||||||
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// // we need to enable raw mode otherwise the characters will be outputted by default before we are able to read them.
|
/// // we need to enable raw mode otherwise the characters will be outputted by default before we are able to read them.
|
||||||
/// let screen = Screen::new(true);
|
/// let screen = Screen::new(true);
|
||||||
@ -99,6 +102,8 @@ impl<'stdout> TerminalInput<'stdout> {
|
|||||||
|
|
||||||
/// Read the input asynchronously until a certain character is hit.
|
/// Read the input asynchronously until a certain character is hit.
|
||||||
///
|
///
|
||||||
|
/// This is the same as `read_async()` but stops reading when a certain character is hit.
|
||||||
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// // we need to enable raw mode otherwise the characters will be outputted by default before we are able to read them.
|
/// // we need to enable raw mode otherwise the characters will be outputted by default before we are able to read them.
|
||||||
/// let screen = Screen::new(true);
|
/// let screen = Screen::new(true);
|
||||||
|
@ -46,6 +46,11 @@ pub struct AsyncReader {
|
|||||||
recv: mpsc::Receiver<io::Result<u8>>,
|
recv: mpsc::Receiver<io::Result<u8>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AsyncReader
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
impl Read for AsyncReader {
|
impl Read for AsyncReader {
|
||||||
/// Read from the byte stream.
|
/// Read from the byte stream.
|
||||||
///
|
///
|
||||||
@ -66,7 +71,6 @@ impl Read for AsyncReader {
|
|||||||
total += 1;
|
total += 1;
|
||||||
},
|
},
|
||||||
_ => return Err(Error::new(ErrorKind::Other, "No characters pressed.")),
|
_ => return Err(Error::new(ErrorKind::Other, "No characters pressed.")),
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,10 +102,6 @@ impl ITerminalInput for WindowsInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tx.send(Ok(pressed_char as u8));
|
tx.send(Ok(pressed_char as u8));
|
||||||
|
|
||||||
if pressed_char == 13 {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -6,9 +6,9 @@ mod ansi_output;
|
|||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
mod winapi_output;
|
mod winapi_output;
|
||||||
|
|
||||||
pub use self::ansi_output::AnsiOutput;
|
use self::ansi_output::AnsiOutput;
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
pub use self::winapi_output::WinApiOutput;
|
use self::winapi_output::WinApiOutput;
|
||||||
|
|
||||||
pub use self::output::TerminalOutput;
|
pub use self::output::TerminalOutput;
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ use super::{functions};
|
|||||||
///
|
///
|
||||||
/// This trait is implemented for `WINAPI` (Windows specific) and `ANSI` (Unix specific),
|
/// This trait is implemented for `WINAPI` (Windows specific) and `ANSI` (Unix specific),
|
||||||
/// so that color related actions can be preformed on both unix and windows systems.
|
/// so that color related actions can be preformed on both unix and windows systems.
|
||||||
pub trait IStdout {
|
trait IStdout {
|
||||||
/// Write an &str to the current stdout and flush the screen.
|
/// Write an &str to the current stdout and flush the screen.
|
||||||
fn write_str(&self, string: &str ) -> io::Result<usize>;
|
fn write_str(&self, string: &str ) -> io::Result<usize>;
|
||||||
/// Write [u8] buffer to console.
|
/// Write [u8] buffer to console.
|
||||||
|
@ -44,8 +44,6 @@ trait ITerminalColor {
|
|||||||
|
|
||||||
/// This could be used to style an Displayable with colors and attributes.
|
/// This could be used to style an Displayable with colors and attributes.
|
||||||
///
|
///
|
||||||
/// #Example
|
|
||||||
///
|
|
||||||
/// ```rust
|
/// ```rust
|
||||||
///
|
///
|
||||||
/// use crossterm::Screen;
|
/// use crossterm::Screen;
|
||||||
|
Loading…
Reference in New Issue
Block a user