Resolve all errors unix. Now it is time to test
This commit is contained in:
parent
a0a56ffb92
commit
03bca7fe76
File diff suppressed because it is too large
Load Diff
10
Cargo.toml
10
Cargo.toml
@ -21,10 +21,10 @@ libc = "0.2"
|
|||||||
termios = "0.3.0"
|
termios = "0.3.0"
|
||||||
|
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "crossterm"
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "a"
|
name = "crosstermexamples"
|
||||||
path = "examples//bin.rs"
|
path = "examples/bin.rs"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -13,45 +13,34 @@
|
|||||||
|
|
||||||
// Import crossterm crate.
|
// Import crossterm crate.
|
||||||
extern crate crossterm;
|
extern crate crossterm;
|
||||||
|
//
|
||||||
// Add the usings for the crossterms modules to play with crossterm
|
//// Add the usings for the crossterms modules to play with crossterm
|
||||||
use self::crossterm::crossterm_style::{paint, Color };
|
//use self::crossterm::crossterm_style::{paint, Color };
|
||||||
use self::crossterm::crossterm_cursor;
|
use self::crossterm::crossterm_cursor::cursor;
|
||||||
use self::crossterm::crossterm_terminal;
|
use self::crossterm::crossterm_terminal;
|
||||||
|
//
|
||||||
|
//// Import the example modules.
|
||||||
|
//pub mod color;
|
||||||
|
//pub mod cursor;
|
||||||
|
//pub mod terminal;
|
||||||
|
use std::io::{self, Error, ErrorKind, Write, stdout, stdin, BufRead};
|
||||||
|
|
||||||
// Import the example modules.
|
//use std::{time, thread};
|
||||||
pub mod color;
|
//
|
||||||
pub mod cursor;
|
use crossterm::crossterm_terminal::screen::{AlternateScreen, ToMainScreen, ToAlternateScreen};
|
||||||
pub mod terminal;
|
|
||||||
use std::io::{Error, ErrorKind, Write};
|
|
||||||
use std::io;
|
|
||||||
use std::{time, thread};
|
|
||||||
|
|
||||||
use self::crossterm_terminal::screen::AlternateScreen;
|
|
||||||
use crossterm::crossterm_terminal::IntoRawMode;
|
use crossterm::crossterm_terminal::IntoRawMode;
|
||||||
|
|
||||||
use crossterm::Context;
|
use crossterm::Context;
|
||||||
|
|
||||||
|
|
||||||
|
use std::{time, thread};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
//
|
let mut screen = stdout();
|
||||||
let mut screen = io::stdout().into_raw_mode(&mut context).unwrap();
|
write!(screen, "{}", ToAlternateScreen);
|
||||||
{
|
write!(screen, "Welcome to the alternate screen.\n\nPlease wait patiently until we arrive back at the main screen in a about three seconds.").unwrap();
|
||||||
// let mut screen = io::stdout();
|
//screen.flush().unwrap();
|
||||||
crossterm_cursor::cursor().goto(10, 10);
|
|
||||||
|
|
||||||
let mut curs = crossterm::crossterm_cursor::cursor();
|
thread::sleep(time::Duration::from_secs(3));
|
||||||
curs.move_up(1);
|
|
||||||
// print!("1");
|
|
||||||
write!(screen, "{}", "1");
|
|
||||||
curs.move_right(1);
|
|
||||||
// print!("2");
|
|
||||||
write!(screen, "{}", "2");
|
|
||||||
curs.move_down(1);
|
|
||||||
// print!("3");
|
|
||||||
write!(screen, "{}", "3");
|
|
||||||
curs.move_left(1);
|
|
||||||
// write!()!("4");
|
|
||||||
write!(screen, "{}", "4");
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -123,7 +123,7 @@ pub fn print_font_with_attributes()
|
|||||||
#[cfg(unix)]#[cfg(unix)]
|
#[cfg(unix)]#[cfg(unix)]
|
||||||
pub fn print_supported_colors()
|
pub fn print_supported_colors()
|
||||||
{
|
{
|
||||||
let count = crossterm::crossterm_style::get().get_available_color_count().unwrap();
|
let count = crossterm::crossterm_style::color().get_available_color_count().unwrap();
|
||||||
|
|
||||||
for i in 0..count
|
for i in 0..count
|
||||||
{
|
{
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
pub struct Crossterm;
|
|
||||||
|
|
||||||
impl Crossterm
|
|
||||||
{
|
|
||||||
fn
|
|
||||||
}
|
|
@ -1,9 +1,8 @@
|
|||||||
use std::io;
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
use Construct;
|
use Construct;
|
||||||
use super::base_cursor::ITerminalCursor;
|
|
||||||
use shared::functions;
|
use shared::functions;
|
||||||
|
use super::ITerminalCursor;
|
||||||
|
|
||||||
|
use std::io::{ self, Write };
|
||||||
|
|
||||||
/// This struct is an ansi implementation for cursor related actions.
|
/// This struct is an ansi implementation for cursor related actions.
|
||||||
pub struct AnsiCursor;
|
pub struct AnsiCursor;
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
//! This trait defines the actions that can be preformed with the termial cursor.
|
|
||||||
//! This trait can be inplemented so that an concrete inplementation of the ITerminalCursor can forfill
|
|
||||||
//! the wishes to work on an specific platform.
|
|
||||||
//!
|
|
||||||
//! ## For example:
|
|
||||||
//!
|
|
||||||
//! This trait is inplemented for winapi (Windows specific) and ansi (Unix specific),
|
|
||||||
//! so that the cursor related actions can be preformed on both unix and windows systems.
|
|
||||||
|
|
||||||
pub trait ITerminalCursor {
|
|
||||||
/// Goto some location (x,y) in the terminal.
|
|
||||||
fn goto(&self, x: u16, y: u16);
|
|
||||||
/// Get the location (x,y) of the current curor in the terminal
|
|
||||||
fn pos(&self) -> (u16, u16);
|
|
||||||
/// Move cursor n times up
|
|
||||||
fn move_up(&self, count: u16);
|
|
||||||
/// Move the cursor `n` times to the right.
|
|
||||||
fn move_right(&self, count: u16);
|
|
||||||
/// Move the cursor `n` times down.
|
|
||||||
fn move_down(&self, count: u16);
|
|
||||||
/// Move the cursor `n` times left.
|
|
||||||
fn move_left(&self, count: u16);
|
|
||||||
/// Save cursor position for recall later. Note that this position is stored program based not per instance of the cursor struct.
|
|
||||||
fn save_position(&mut self);
|
|
||||||
/// Return to saved cursor position
|
|
||||||
fn reset_position(&self);
|
|
||||||
}
|
|
@ -1,27 +1,21 @@
|
|||||||
//! With this module you can perform actions that are cursor related.
|
//! With this module you can perform actions that are cursor related.
|
||||||
//! Like changing and displaying the position of the cursor in terminal.
|
//! Like changing and displaying the position of the cursor in terminal.
|
||||||
//!
|
//!
|
||||||
use std::fmt::Display;
|
use super::*;
|
||||||
use std::ops::Drop;
|
use shared::functions;
|
||||||
|
|
||||||
use {Construct, Context};
|
use {Construct, Context};
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
use std::fmt::Display;
|
||||||
use shared::functions::get_module;
|
use std::ops::Drop;
|
||||||
|
|
||||||
use super::base_cursor::ITerminalCursor;
|
|
||||||
|
|
||||||
use super::AnsiCursor;
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
use super::WinApiCursor;
|
|
||||||
|
|
||||||
/// Struct that stores an specific platform implementation for cursor related actions.
|
/// Struct that stores an specific platform implementation for cursor related actions.
|
||||||
pub struct TerminalCursor {
|
pub struct TerminalCursor {
|
||||||
terminal_cursor: Option<Box<ITerminalCursor>>,
|
terminal_cursor: Option<Box<ITerminalCursor>>,
|
||||||
context: Context
|
context: Context
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TerminalCursor
|
impl TerminalCursor
|
||||||
{
|
{
|
||||||
/// Create new cursor instance whereon cursor related actions can be performed.
|
/// Create new cursor instance whereon cursor related actions can be performed.
|
||||||
pub fn new() -> TerminalCursor {
|
pub fn new() -> TerminalCursor {
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
@ -30,7 +24,7 @@ impl TerminalCursor
|
|||||||
let cursor = get_module::<Box<ITerminalCursor>>(WinApiCursor::new(), AnsiCursor::new(), &mut context);
|
let cursor = get_module::<Box<ITerminalCursor>>(WinApiCursor::new(), AnsiCursor::new(), &mut context);
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
let cursor = Some(AnsiCursor::new());
|
let cursor = Some(AnsiCursor::new() as Box<ITerminalCursor>);
|
||||||
|
|
||||||
TerminalCursor { terminal_cursor: cursor, context: context }
|
TerminalCursor { terminal_cursor: cursor, context: context }
|
||||||
}
|
}
|
||||||
@ -260,6 +254,14 @@ impl TerminalCursor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Drop for TerminalCursor
|
||||||
|
{
|
||||||
|
fn drop(&mut self)
|
||||||
|
{
|
||||||
|
self.context.restore_changes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Get an TerminalCursor implementation whereon cursor related actions can be performed.
|
/// Get an TerminalCursor implementation whereon cursor related actions can be performed.
|
||||||
///
|
///
|
||||||
/// Check `/examples/cursor` in the libary for more spesific examples.
|
/// Check `/examples/cursor` in the libary for more spesific examples.
|
||||||
|
@ -1,15 +1,39 @@
|
|||||||
mod base_cursor;
|
//! This trait defines the actions that can be preformed with the termial cursor.
|
||||||
mod cursor;
|
//! This trait can be inplemented so that an concrete inplementation of the ITerminalCursor can forfill
|
||||||
|
//! the wishes to work on an specific platform.
|
||||||
|
//!
|
||||||
|
//! ## For example:
|
||||||
|
//!
|
||||||
|
//! This trait is inplemented for winapi (Windows specific) and ansi (Unix specific),
|
||||||
|
//! so that the cursor related actions can be preformed on both unix and windows systems.
|
||||||
|
//!
|
||||||
|
|
||||||
|
mod cursor;
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
mod winapi_cursor;
|
||||||
mod ansi_cursor;
|
mod ansi_cursor;
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
mod winapi_cursor;
|
|
||||||
|
|
||||||
use self::ansi_cursor::AnsiCursor;
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
use self::winapi_cursor::WinApiCursor;
|
use self::winapi_cursor::WinApiCursor;
|
||||||
|
use self::ansi_cursor::AnsiCursor;
|
||||||
|
|
||||||
pub use self::cursor::{ cursor, TerminalCursor };
|
pub use self::cursor::{ cursor, TerminalCursor };
|
||||||
|
|
||||||
|
pub trait ITerminalCursor {
|
||||||
|
/// Goto some location (x,y) in the terminal.
|
||||||
|
fn goto(&self, x: u16, y: u16);
|
||||||
|
/// Get the location (x,y) of the current curor in the terminal
|
||||||
|
fn pos(&self) -> (u16, u16);
|
||||||
|
/// Move cursor n times up
|
||||||
|
fn move_up(&self, count: u16);
|
||||||
|
/// Move the cursor `n` times to the right.
|
||||||
|
fn move_right(&self, count: u16);
|
||||||
|
/// Move the cursor `n` times down.
|
||||||
|
fn move_down(&self, count: u16);
|
||||||
|
/// Move the cursor `n` times left.
|
||||||
|
fn move_left(&self, count: u16);
|
||||||
|
/// Save cursor position for recall later. Note that this position is stored program based not per instance of the cursor struct.
|
||||||
|
fn save_position(&mut self);
|
||||||
|
/// Return to saved cursor position
|
||||||
|
fn reset_position(&self);
|
||||||
|
}
|
@ -1,8 +1,7 @@
|
|||||||
use Construct;
|
use Construct;
|
||||||
use super::base_cursor::ITerminalCursor;
|
use super::ITerminalCursor;
|
||||||
use kernel::windows_kernel::{kernel, cursor};
|
use kernel::windows_kernel::{kernel, cursor};
|
||||||
|
|
||||||
|
|
||||||
/// This struct is an windows implementation for cursor related actions.
|
/// This struct is an windows implementation for cursor related actions.
|
||||||
pub struct WinApiCursor;
|
pub struct WinApiCursor;
|
||||||
|
|
||||||
|
@ -25,33 +25,42 @@ impl IContextCommand for NoncanonicalModeCommand
|
|||||||
{
|
{
|
||||||
// println!("execute NoncanonicalModeCommand uxix");
|
// println!("execute NoncanonicalModeCommand uxix");
|
||||||
// Set noncanonical mode
|
// Set noncanonical mode
|
||||||
let orig = Termios::from_fd(FD_STDIN)?;
|
if let Ok(orig) = Termios::from_fd(FD_STDIN)
|
||||||
let mut noncan = orig.clone();
|
{
|
||||||
noncan.c_lflag &= !ICANON;
|
let mut noncan = orig.clone();
|
||||||
noncan.c_lflag &= !ECHO;
|
noncan.c_lflag &= !ICANON;
|
||||||
noncan.c_lflag &= !CREAD;
|
noncan.c_lflag &= !ECHO;
|
||||||
match tcsetattr(FD_STDIN, TCSAFLUSH, &noncan)
|
noncan.c_lflag &= !CREAD;
|
||||||
|
match tcsetattr(FD_STDIN, TCSAFLUSH, &noncan)
|
||||||
{
|
{
|
||||||
Ok(_) => return true,
|
Ok(_) => return true,
|
||||||
Err(_) => return false,
|
Err(_) => return false,
|
||||||
};
|
};
|
||||||
|
}else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn undo(&mut self) -> bool
|
fn undo(&mut self) -> bool
|
||||||
{
|
{
|
||||||
|
|
||||||
// println!("undo NoncanonicalModeCommand unix");
|
// println!("undo NoncanonicalModeCommand unix");
|
||||||
// Disable noncanonical mode
|
// Disable noncanonical mode
|
||||||
let orig = Termios::from_fd(FD_STDIN)?;
|
if let Ok(orig) = Termios::from_fd(FD_STDIN)
|
||||||
let mut noncan = orig.clone();
|
|
||||||
noncan.c_lflag &= ICANON;
|
|
||||||
noncan.c_lflag &= ECHO;
|
|
||||||
noncan.c_lflag &= CREAD;
|
|
||||||
|
|
||||||
match tcsetattr(FD_STDIN, TCSAFLUSH, &noncan)
|
|
||||||
{
|
{
|
||||||
Ok(_) => return true,
|
let mut noncan = orig.clone();
|
||||||
Err(_) => return false,
|
noncan.c_lflag &= ICANON;
|
||||||
};
|
noncan.c_lflag &= ECHO;
|
||||||
|
noncan.c_lflag &= CREAD;
|
||||||
|
|
||||||
|
match tcsetattr(FD_STDIN, TCSAFLUSH, &noncan)
|
||||||
|
{
|
||||||
|
Ok(_) => return true,
|
||||||
|
Err(_) => return false,
|
||||||
|
};
|
||||||
|
}else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,29 +77,40 @@ impl IContextCommand for EnableRawModeCommand
|
|||||||
// println!("new EnableRawModeCommand unix");
|
// println!("new EnableRawModeCommand unix");
|
||||||
let key = super::generate_key();
|
let key = super::generate_key();
|
||||||
let command = EnableRawModeCommand { original_mode: None, key: key };
|
let command = EnableRawModeCommand { original_mode: None, key: key };
|
||||||
context.state.register_change(Box::from(command), key);
|
context.register_change(Box::from(command), key);
|
||||||
(Box::from(command),key)
|
(Box::from(command),key)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute(&mut self) -> bool
|
fn execute(&mut self) -> bool
|
||||||
{
|
{
|
||||||
// println!("execute EnableRawModeCommand unix");
|
// println!("execute EnableRawModeCommand unix");
|
||||||
self.original_mode = terminal::get_terminal_mode()?;
|
if let Ok(original_mode) = terminal::get_terminal_mode()
|
||||||
let mut new_mode = self.original_mode.unwrap();
|
{
|
||||||
new_mode.make_raw();
|
self.original_mode = Some(original_mode);
|
||||||
terminal::set_terminal_mode(new_mode);
|
let mut new_mode = self.original_mode.unwrap();
|
||||||
true
|
terminal::make_raw(&mut new_mode);
|
||||||
|
terminal::set_terminal_mode(&new_mode);
|
||||||
|
true
|
||||||
|
|
||||||
|
}else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn undo(&mut self) -> bool
|
fn undo(&mut self) -> bool
|
||||||
{
|
{
|
||||||
// println!("undo EnableRawModeCommand unix");
|
// println!("undo EnableRawModeCommand unix");
|
||||||
let result = terminal::set_terminal_mode(self.original_mode).unwrap();
|
if let Ok(original_mode) = terminal::get_terminal_mode()
|
||||||
|
|
||||||
match result
|
|
||||||
{
|
{
|
||||||
Ok(_) => true,
|
let result = terminal::set_terminal_mode(&self.original_mode.unwrap());
|
||||||
Err(_) => false
|
|
||||||
|
match result
|
||||||
|
{
|
||||||
|
Ok(()) => true,
|
||||||
|
Err(_) => false
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
use std::io;
|
|
||||||
use std::io::Write;
|
|
||||||
use std::string::String;
|
|
||||||
|
|
||||||
use Construct;
|
use Construct;
|
||||||
|
use super::ITerminalColor;
|
||||||
use super::super::{Color, ColorType};
|
use super::super::{Color, ColorType};
|
||||||
use super::base_color::ITerminalColor;
|
|
||||||
|
|
||||||
|
use std::io::{self, Write};
|
||||||
|
|
||||||
/// This struct is an ansi implementation for color related actions.
|
/// This struct is an ansi implementation for color related actions.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
///!
|
|
||||||
///! This trait defines the actions that can be preformed with the termial color.
|
|
||||||
///! This trait can be inplemented so that an concrete inplementation of the ITerminalColor can forfill
|
|
||||||
///! the wishes to work on an specific platform.
|
|
||||||
///!
|
|
||||||
///! ## For example:
|
|
||||||
///!
|
|
||||||
///! This trait is inplemented for winapi (Windows specific) and ansi (Unix specific),
|
|
||||||
///! so that the color related actions can be preformed on both unix and windows systems.
|
|
||||||
///!
|
|
||||||
|
|
||||||
use super::super::{Color, ColorType};
|
|
||||||
|
|
||||||
pub trait ITerminalColor {
|
|
||||||
/// Set the forground color to the given color.
|
|
||||||
fn set_fg(&self, fg_color: Color);
|
|
||||||
/// Set the background color to the given color.
|
|
||||||
fn set_bg(&self, fg_color: Color);
|
|
||||||
/// Reset the terminal color to default.
|
|
||||||
fn reset(&self);
|
|
||||||
/// Gets an value that represents an color from the given `Color` and `ColorType`.
|
|
||||||
fn color_value(&self, color: Color, color_type: ColorType) -> String;
|
|
||||||
}
|
|
@ -1,22 +1,12 @@
|
|||||||
//! With this module you can perform actions that are color related.
|
//! With this module you can perform actions that are color related.
|
||||||
//! Like styling the font, foreground color and background color.
|
//! Like styling the font, foreground color and background color.
|
||||||
|
use super::*;
|
||||||
|
use shared::functions;
|
||||||
|
use { Construct, Context };
|
||||||
|
use crossterm_style::{Color, ObjectStyle, StyledObject};
|
||||||
|
|
||||||
use std::ops::Drop;
|
use std::ops::Drop;
|
||||||
use std::fmt;
|
use std::{ fmt, io };
|
||||||
use std::io;
|
|
||||||
|
|
||||||
use {Construct, Context };
|
|
||||||
use crossterm_style::{ObjectStyle, StyledObject};
|
|
||||||
use super::base_color::ITerminalColor;
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
use shared::functions::get_module;
|
|
||||||
use super::super::Color;
|
|
||||||
|
|
||||||
use super::AnsiColor;
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
use super::WinApiColor;
|
|
||||||
|
|
||||||
/// Struct that stores an specific platform implementation for color related actions.
|
/// Struct that stores an specific platform implementation for color related actions.
|
||||||
pub struct TerminalColor {
|
pub struct TerminalColor {
|
||||||
@ -30,10 +20,10 @@ impl TerminalColor {
|
|||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let color = get_module::<Box<ITerminalColor>>(WinApiColor::new(), AnsiColor::new(), &mut context);
|
let color = functions::get_module::<Box<ITerminalColor>>(WinApiColor::new(), AnsiColor::new(), &mut context);
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
let color = Some(AnsiColor::new());
|
let color = Some(AnsiColor::new() as Box<ITerminalColor>);
|
||||||
|
|
||||||
TerminalColor { terminal_color: color, context: context}
|
TerminalColor { terminal_color: color, context: context}
|
||||||
}
|
}
|
||||||
@ -125,6 +115,14 @@ impl TerminalColor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Drop for TerminalColor
|
||||||
|
{
|
||||||
|
fn drop(&mut self)
|
||||||
|
{
|
||||||
|
self.context.restore_changes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Get an TerminalColor implementation whereon color related actions can be performed.
|
/// Get an TerminalColor implementation whereon color related actions can be performed.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
|
@ -1,12 +1,33 @@
|
|||||||
pub mod base_color;
|
|
||||||
pub mod color;
|
pub mod color;
|
||||||
|
|
||||||
mod ansi_color;
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
mod winapi_color;
|
mod winapi_color;
|
||||||
|
mod ansi_color;
|
||||||
use self::ansi_color::AnsiColor;
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
use self::winapi_color::WinApiColor;
|
use self::winapi_color::WinApiColor;
|
||||||
|
use self::ansi_color::AnsiColor;
|
||||||
|
|
||||||
|
///!
|
||||||
|
///! This trait defines the actions that can be preformed with the termial color.
|
||||||
|
///! This trait can be inplemented so that an concrete inplementation of the ITerminalColor can forfill
|
||||||
|
///! the wishes to work on an specific platform.
|
||||||
|
///!
|
||||||
|
///! ## For example:
|
||||||
|
///!
|
||||||
|
///! This trait is inplemented for winapi (Windows specific) and ansi (Unix specific),
|
||||||
|
///! so that the color related actions can be preformed on both unix and windows systems.
|
||||||
|
///!
|
||||||
|
|
||||||
|
use super::{Color, ColorType};
|
||||||
|
|
||||||
|
pub trait ITerminalColor {
|
||||||
|
/// Set the forground color to the given color.
|
||||||
|
fn set_fg(&self, fg_color: Color);
|
||||||
|
/// Set the background color to the given color.
|
||||||
|
fn set_bg(&self, fg_color: Color);
|
||||||
|
/// Reset the terminal color to default.
|
||||||
|
fn reset(&self);
|
||||||
|
/// Gets an value that represents an color from the given `Color` and `ColorType`.
|
||||||
|
fn color_value(&self, color: Color, color_type: ColorType) -> String;
|
||||||
|
}
|
@ -1,9 +1,8 @@
|
|||||||
use Construct;
|
use Construct;
|
||||||
|
use super::ITerminalColor;
|
||||||
use super::super::{ColorType, Color};
|
use super::super::{ColorType, Color};
|
||||||
use super::base_color::ITerminalColor;
|
|
||||||
|
|
||||||
use kernel::windows_kernel::kernel;
|
|
||||||
use winapi::um::wincon;
|
use winapi::um::wincon;
|
||||||
|
use kernel::windows_kernel::kernel;
|
||||||
|
|
||||||
/// This struct is an windows implementation for color related actions.
|
/// This struct is an windows implementation for color related actions.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crossterm_style::{Color, StyledObject};
|
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
use crossterm_style::{Color, StyledObject};
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use super::super::Attribute;
|
use super::super::Attribute;
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use std;
|
use std::{ fmt, self };
|
||||||
use std::fmt;
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
|
use Construct;
|
||||||
|
use shared::functions;
|
||||||
|
use super::{ClearType, ITerminal};
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use Construct;
|
|
||||||
use super::base_terminal::{ClearType, ITerminal};
|
|
||||||
|
|
||||||
use shared::functions::get_terminal_size;
|
|
||||||
|
|
||||||
/// This struct is an ansi implementation for terminal related actions.
|
/// This struct is an ansi implementation for terminal related actions.
|
||||||
pub struct AnsiTerminal ;
|
pub struct AnsiTerminal ;
|
||||||
|
|
||||||
@ -38,7 +37,7 @@ impl ITerminal for AnsiTerminal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn terminal_size(&self) -> (u16, u16) {
|
fn terminal_size(&self) -> (u16, u16) {
|
||||||
get_terminal_size()
|
functions::get_terminal_size()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scroll_up(&self, count: i16) {
|
fn scroll_up(&self, count: i16) {
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
/// Enum that can be used for the kind of clearing that can be done in the terminal.
|
|
||||||
pub enum ClearType {
|
|
||||||
All,
|
|
||||||
FromCursorDown,
|
|
||||||
FromCursorUp,
|
|
||||||
CurrentLine,
|
|
||||||
UntilNewLine,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait ITerminal{
|
|
||||||
/// Clear the current cursor by specifying the clear type
|
|
||||||
fn clear(&self, clear_type: ClearType);
|
|
||||||
/// Get the terminal size (x,y)
|
|
||||||
fn terminal_size(&self) -> (u16, u16);
|
|
||||||
/// Scroll `n` lines up in the current terminal.
|
|
||||||
fn scroll_up(&self, count: i16);
|
|
||||||
/// Scroll `n` lines down in the current terminal.
|
|
||||||
fn scroll_down(&self, count: i16);
|
|
||||||
/// Resize terminal to the given width and height.
|
|
||||||
fn set_size(&self,width: i16, height: i16);
|
|
||||||
}
|
|
@ -1,19 +1,37 @@
|
|||||||
mod raw_terminal;
|
mod raw_terminal;
|
||||||
mod base_terminal;
|
|
||||||
mod terminal;
|
mod terminal;
|
||||||
|
|
||||||
pub mod screen;
|
|
||||||
|
|
||||||
mod ansi_terminal;
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
mod winapi_terminal;
|
mod winapi_terminal;
|
||||||
|
mod ansi_terminal;
|
||||||
|
|
||||||
use self::ansi_terminal::AnsiTerminal;
|
pub mod screen;
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
use self::winapi_terminal::WinApiTerminal;
|
use self::winapi_terminal::WinApiTerminal;
|
||||||
|
use self::ansi_terminal::AnsiTerminal;
|
||||||
|
|
||||||
pub use self::base_terminal::ClearType;
|
|
||||||
pub use self::terminal::{ Terminal, terminal};
|
pub use self::terminal::{ Terminal, terminal};
|
||||||
pub use self::raw_terminal::{RawTerminal, IntoRawMode};
|
pub use self::raw_terminal::{RawTerminal, IntoRawMode};
|
||||||
|
|
||||||
|
/// Enum that can be used for the kind of clearing that can be done in the terminal.
|
||||||
|
pub enum ClearType {
|
||||||
|
All,
|
||||||
|
FromCursorDown,
|
||||||
|
FromCursorUp,
|
||||||
|
CurrentLine,
|
||||||
|
UntilNewLine,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait ITerminal{
|
||||||
|
/// Clear the current cursor by specifying the clear type
|
||||||
|
fn clear(&self, clear_type: ClearType);
|
||||||
|
/// Get the terminal size (x,y)
|
||||||
|
fn terminal_size(&self) -> (u16, u16);
|
||||||
|
/// Scroll `n` lines up in the current terminal.
|
||||||
|
fn scroll_up(&self, count: i16);
|
||||||
|
/// Scroll `n` lines down in the current terminal.
|
||||||
|
fn scroll_down(&self, count: i16);
|
||||||
|
/// Resize terminal to the given width and height.
|
||||||
|
fn set_size(&self,width: i16, height: i16);
|
||||||
|
}
|
||||||
|
@ -3,13 +3,11 @@ use crossterm_state::commands::unix_command::EnableRawModeCommand;
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use crossterm_state::commands::win_commands::EnableRawModeCommand;
|
use crossterm_state::commands::win_commands::EnableRawModeCommand;
|
||||||
|
|
||||||
use crossterm_state::commands::IContextCommand;
|
use { Construct, Context };
|
||||||
|
use crossterm_state::commands::{ICommand, IContextCommand};
|
||||||
|
|
||||||
use shared::traits::Construct;
|
use std::io::{ self, Write};
|
||||||
use crossterm_state::{ Context };
|
|
||||||
use crossterm_state::commands::ICommand;
|
|
||||||
|
|
||||||
use std::io::{self, Write};
|
|
||||||
|
|
||||||
pub struct RawTerminal<'a, W: Write>
|
pub struct RawTerminal<'a, W: Write>
|
||||||
{
|
{
|
||||||
|
@ -1,14 +1,9 @@
|
|||||||
use std::io::{self, Write};
|
use shared::functions;
|
||||||
use std::ops;
|
use { Context, Construct };
|
||||||
use std::any::Any;
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
use shared::functions::get_module;
|
|
||||||
use crossterm_state::commands::*;
|
use crossterm_state::commands::*;
|
||||||
use shared::traits::Construct;
|
|
||||||
use Context;
|
|
||||||
|
|
||||||
use std::fmt;
|
use std::{ fmt, ops };
|
||||||
|
use std::io::{self, Write};
|
||||||
|
|
||||||
/// let context = ScreenContext::new();
|
/// let context = ScreenContext::new();
|
||||||
/// ToMainScreen {}.execute(&mut context);
|
/// ToMainScreen {}.execute(&mut context);
|
||||||
@ -94,7 +89,7 @@ fn get_to_alternate_screen_command() -> Box<ICommand>
|
|||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let command = get_module::<Box<ICommand>>(win_commands::ToAlternateScreenBufferCommand::new(), shared_commands::ToAlternateScreenBufferCommand::new(), &mut context).unwrap();
|
let command = functions::get_module::<Box<ICommand>>(win_commands::ToAlternateScreenBufferCommand::new(), shared_commands::ToAlternateScreenBufferCommand::new(), &mut context).unwrap();
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
let command = shared_commands::ToAlternateScreenBufferCommand::new();
|
let command = shared_commands::ToAlternateScreenBufferCommand::new();
|
||||||
|
@ -1,18 +1,11 @@
|
|||||||
//! With this module you can perform actions that are terminal related.
|
//! With this module you can perform actions that are terminal related.
|
||||||
//! Like clearing and scrolling in the terminal or getting the size of the terminal.
|
//! Like clearing and scrolling in the terminal or getting the size of the terminal.
|
||||||
|
use super::*;
|
||||||
|
use shared::functions;
|
||||||
|
use {Construct, Context};
|
||||||
|
|
||||||
use std::ops::Drop;
|
use std::ops::Drop;
|
||||||
|
|
||||||
use {Construct, Context};
|
|
||||||
use super::base_terminal::{ClearType, ITerminal};
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
use shared::functions::get_module;
|
|
||||||
|
|
||||||
use super::AnsiTerminal;
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
use super::WinApiTerminal;
|
|
||||||
|
|
||||||
/// Struct that stores an specific platform implementation for terminal related actions.
|
/// Struct that stores an specific platform implementation for terminal related actions.
|
||||||
pub struct Terminal {
|
pub struct Terminal {
|
||||||
terminal: Option<Box<ITerminal>>,
|
terminal: Option<Box<ITerminal>>,
|
||||||
@ -25,10 +18,10 @@ impl Terminal {
|
|||||||
|
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let terminal = get_module::<Box<ITerminal>>(WinApiTerminal::new(), AnsiTerminal::new(), &mut context);
|
let terminal = functions::get_module::<Box<ITerminal>>(WinApiTerminal::new(), AnsiTerminal::new(), &mut context);
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
let terminal = Some(AnsiTerminal::new());
|
let terminal = Some(AnsiTerminal::new() as Box<ITerminal>);
|
||||||
|
|
||||||
Terminal { terminal: terminal, context: context }
|
Terminal { terminal: terminal, context: context }
|
||||||
}
|
}
|
||||||
@ -149,6 +142,14 @@ impl Terminal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Drop for Terminal
|
||||||
|
{
|
||||||
|
fn drop(&mut self)
|
||||||
|
{
|
||||||
|
self.context.restore_changes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Get an Terminal implementation whereon terminal related actions can be performed.
|
/// Get an Terminal implementation whereon terminal related actions can be performed.
|
||||||
///
|
///
|
||||||
/// Check `/examples/terminal` in the libary for more spesific examples.
|
/// Check `/examples/terminal` in the libary for more spesific examples.
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
use libc;
|
use { libc, Context };
|
||||||
use self::libc::{STDOUT_FILENO, TIOCGWINSZ, c_ushort, ioctl, c_int};
|
|
||||||
pub use self::libc::{termios, cvt};
|
|
||||||
use termios::Termios;
|
use termios::Termios;
|
||||||
use crossterm_state::commands::{NoncanonicalModeCommand, IContextCommand};
|
pub use self::libc::{termios};
|
||||||
use Context;
|
use self::libc::{STDOUT_FILENO, TIOCGWINSZ, c_ushort, ioctl, c_int};
|
||||||
use std::io;
|
use crossterm_state::commands::{ NoncanonicalModeCommand, IContextCommand} ;
|
||||||
use std::mem;
|
|
||||||
|
|
||||||
|
use std::{ io, mem };
|
||||||
|
use std::io::Error;
|
||||||
|
|
||||||
/// A representation of the size of the current terminal
|
/// A representation of the size of the current terminal
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
@ -46,7 +45,7 @@ pub fn pos() -> (u16,u16)
|
|||||||
|
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
{
|
{
|
||||||
let command = NoncanonicalModeCommand::new(&mut context);
|
let mut command = NoncanonicalModeCommand::new(&mut context);
|
||||||
command.0.execute();
|
command.0.execute();
|
||||||
|
|
||||||
// This code is original written by term_cursor credits to them.
|
// This code is original written by term_cursor credits to them.
|
||||||
@ -65,7 +64,7 @@ pub fn pos() -> (u16,u16)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read rows and cols through a ad-hoc integer parsing function
|
// Read rows and cols through a ad-hoc integer parsing function
|
||||||
let read_num = || -> Result<(i32, char), Error> {
|
let read_num = || -> (i32, char) {
|
||||||
let mut num = 0;
|
let mut num = 0;
|
||||||
let mut c;
|
let mut c;
|
||||||
|
|
||||||
@ -81,11 +80,12 @@ pub fn pos() -> (u16,u16)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((num, c))
|
(num, c)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Read rows and expect `;`
|
// Read rows and expect `;`
|
||||||
let (rows, c) = read_num();
|
let (rows, c) = read_num();
|
||||||
|
|
||||||
if c != ';' {
|
if c != ';' {
|
||||||
return (0, 0);
|
return (0, 0);
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ pub fn pos() -> (u16,u16)
|
|||||||
let (cols, c) = read_num();
|
let (cols, c) = read_num();
|
||||||
|
|
||||||
// Expect `R`
|
// Expect `R`
|
||||||
let res = if c == 'R' { Ok((cols, rows)) } else { return Ok((0, 0)); };
|
let res = if c == 'R' { (cols as u16, rows as u16) } else { return (0, 0) };
|
||||||
|
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
@ -105,7 +105,14 @@ pub fn set_terminal_mode(termios: &Termios) -> io::Result<()>
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn tcsetattr(fd: c_int, opt: c_int, termptr: *const Termios) -> c_int;
|
pub fn tcsetattr(fd: c_int, opt: c_int, termptr: *const Termios) -> c_int;
|
||||||
}
|
}
|
||||||
unsafe { tcsetattr(0, 0, termios) }
|
is_true(unsafe { tcsetattr(0, 0, termios) }).and(Ok(()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn make_raw(termios: &mut Termios) {
|
||||||
|
extern "C" {
|
||||||
|
pub fn cfmakeraw(termptr: *mut Termios);
|
||||||
|
}
|
||||||
|
unsafe { cfmakeraw(termios) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_terminal_mode() -> io::Result<Termios>
|
pub fn get_terminal_mode() -> io::Result<Termios>
|
||||||
@ -115,7 +122,17 @@ pub fn get_terminal_mode() -> io::Result<Termios>
|
|||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut termios = mem::zeroed();
|
let mut termios = mem::zeroed();
|
||||||
cvt(tcgetattr(0, &mut termios))?;
|
is_true(tcgetattr(0, &mut termios))?;
|
||||||
Ok(termios)
|
Ok(termios)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_true(value: i32) -> Result<(), Error>
|
||||||
|
{
|
||||||
|
match value
|
||||||
|
{
|
||||||
|
-1 => Err(io::Error::last_os_error()),
|
||||||
|
0 => Ok(()),
|
||||||
|
_ => Err(io::Error::last_os_error()),
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,9 @@
|
|||||||
use crossterm_state::Context;
|
use { Context, Contstruct };
|
||||||
use crossterm_state::commands::IContextCommand;
|
use crossterm_state::commands::IContextCommand;
|
||||||
use shared::traits::Construct;
|
|
||||||
|
|
||||||
static mut IS_ANSI_ON_WINDOWS_ENABLED: Option<bool> = None;
|
|
||||||
static mut DOES_WINDOWS_SUPPORT_ANSI: Option<bool> = None;
|
|
||||||
static mut HAS_BEEN_TRYED_TO_ENABLE: bool = false;
|
static mut HAS_BEEN_TRYED_TO_ENABLE: bool = false;
|
||||||
|
static mut IS_ANSI_ON_WINDOWS_ENABLED: Option<bool> = None;
|
||||||
|
static mut DOES_WINDOWS_SUPPORT_ANSI: Option<bool> = None;
|
||||||
|
|
||||||
/// Try enable ANSI escape codes and return the result.
|
/// Try enable ANSI escape codes and return the result.
|
||||||
pub fn try_enable_ansi_support(context: &mut Context) -> bool
|
pub fn try_enable_ansi_support(context: &mut Context) -> bool
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use super::kernel;
|
use super::{ kernel, cursor };
|
||||||
use crossterm_cursor::cursor;
|
|
||||||
|
|
||||||
/// 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);
|
||||||
@ -15,7 +14,7 @@ pub fn reset_to_saved_position()
|
|||||||
/// Save current cursor position to recall later.
|
/// Save current cursor position to recall later.
|
||||||
pub fn save_cursor_pos()
|
pub fn save_cursor_pos()
|
||||||
{
|
{
|
||||||
let position = cursor().pos();
|
let position = pos();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
SAVED_CURSOR_POS = (position.0, position.1);
|
SAVED_CURSOR_POS = (position.0, position.1);
|
||||||
@ -25,5 +24,5 @@ pub fn save_cursor_pos()
|
|||||||
pub fn pos() -> (u16,u16)
|
pub fn pos() -> (u16,u16)
|
||||||
{
|
{
|
||||||
let csbi = kernel::get_console_screen_buffer_info();
|
let csbi = kernel::get_console_screen_buffer_info();
|
||||||
( csbi.dwCursorPosition.X as u16, csbi.dwCursorPosition.Y as u16)
|
( csbi.dwCursorPosition.X as u16, csbi.dwCursorPosition.Y as u16 )
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,17 @@ use winapi::um::winbase::{STD_OUTPUT_HANDLE, STD_INPUT_HANDLE };
|
|||||||
use winapi::um::handleapi::INVALID_HANDLE_VALUE;
|
use winapi::um::handleapi::INVALID_HANDLE_VALUE;
|
||||||
use winapi::um::processenv::{GetStdHandle};
|
use winapi::um::processenv::{GetStdHandle};
|
||||||
use winapi::um::consoleapi::{SetConsoleMode,GetConsoleMode, };
|
use winapi::um::consoleapi::{SetConsoleMode,GetConsoleMode, };
|
||||||
|
|
||||||
use winapi::um::wincon;
|
|
||||||
use winapi::shared::minwindef::{TRUE};
|
use winapi::shared::minwindef::{TRUE};
|
||||||
use winapi::um::wincon::{ SetConsoleWindowInfo, SetConsoleCursorPosition, SetConsoleTextAttribute, SetConsoleScreenBufferSize, CreateConsoleScreenBuffer,SetConsoleActiveScreenBuffer,
|
use winapi::um::wincon;
|
||||||
GetLargestConsoleWindowSize, GetConsoleScreenBufferInfo,
|
use winapi::um::wincon::
|
||||||
FillConsoleOutputCharacterA, FillConsoleOutputAttribute,
|
{
|
||||||
CONSOLE_SCREEN_BUFFER_INFO, SMALL_RECT, COORD, CHAR_INFO, PSMALL_RECT
|
SetConsoleWindowInfo, SetConsoleCursorPosition, SetConsoleTextAttribute, SetConsoleScreenBufferSize, CreateConsoleScreenBuffer,SetConsoleActiveScreenBuffer,
|
||||||
|
GetLargestConsoleWindowSize, GetConsoleScreenBufferInfo,
|
||||||
|
FillConsoleOutputCharacterA, FillConsoleOutputAttribute,
|
||||||
|
CONSOLE_SCREEN_BUFFER_INFO, SMALL_RECT, COORD, CHAR_INFO, PSMALL_RECT
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{Empty};
|
use super::{Empty};
|
||||||
|
|
||||||
static mut CONSOLE_OUTPUT_HANDLE: Option<HANDLE> = None;
|
static mut CONSOLE_OUTPUT_HANDLE: Option<HANDLE> = None;
|
||||||
static mut CONSOLE_INPUT_HANDLE: Option<HANDLE> = None;
|
static mut CONSOLE_INPUT_HANDLE: Option<HANDLE> = None;
|
||||||
|
|
||||||
@ -261,11 +261,6 @@ pub fn read_console_output(read_buffer: &HANDLE, copy_buffer: &mut [CHAR_INFO;16
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_console()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn write_console_output(write_buffer: &HANDLE, copy_buffer: &mut [CHAR_INFO;160], buffer_size: COORD, buffer_coord: COORD, source_buffer: PSMALL_RECT)
|
pub fn write_console_output(write_buffer: &HANDLE, copy_buffer: &mut [CHAR_INFO;160], buffer_size: COORD, buffer_coord: COORD, source_buffer: PSMALL_RECT)
|
||||||
{
|
{
|
||||||
use self::wincon::WriteConsoleOutputA;
|
use self::wincon::WriteConsoleOutputA;
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
extern crate winapi;
|
|
||||||
|
|
||||||
use winapi::um::wincon::{COORD, CONSOLE_SCREEN_BUFFER_INFO, SMALL_RECT};
|
|
||||||
use shared::traits::Empty;
|
|
||||||
|
|
||||||
pub mod kernel;
|
pub mod kernel;
|
||||||
pub mod cursor;
|
pub mod cursor;
|
||||||
pub mod terminal;
|
pub mod terminal;
|
||||||
pub mod ansi_support;
|
pub mod ansi_support;
|
||||||
|
|
||||||
|
use winapi;
|
||||||
|
use shared::traits::Empty;
|
||||||
|
use self::winapi::um::wincon::{COORD, CONSOLE_SCREEN_BUFFER_INFO, SMALL_RECT};
|
||||||
|
|
||||||
impl Empty for COORD {
|
impl Empty for COORD {
|
||||||
fn empty() -> COORD {
|
fn empty() -> COORD {
|
||||||
COORD { X: 0, Y: 0 }
|
COORD { X: 0, Y: 0 }
|
||||||
|
11
src/lib.rs
11
src/lib.rs
@ -18,3 +18,14 @@ extern crate libc;
|
|||||||
extern crate termios;
|
extern crate termios;
|
||||||
|
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
|
|
||||||
|
|
||||||
|
// private mod
|
||||||
|
//
|
||||||
|
// public mod
|
||||||
|
//
|
||||||
|
// own usings
|
||||||
|
//
|
||||||
|
// std usings
|
||||||
|
//
|
||||||
|
// extern crate
|
@ -1,7 +1,7 @@
|
|||||||
//! Some actions need to preformed platform independently.
|
//! Some actions need to preformed platform independently.
|
||||||
//!
|
//!
|
||||||
use Context;
|
use {Context, Construct};
|
||||||
use shared::traits::Construct;
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use kernel::windows_kernel::terminal::terminal_size;
|
use kernel::windows_kernel::terminal::terminal_size;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
Loading…
Reference in New Issue
Block a user