Refactor
This commit is contained in:
parent
685bc5e961
commit
f64a405236
@ -1,6 +1,6 @@
|
|||||||
//! This module contains some commands that could be executed for specific task.
|
//! This module contains some commands that could be executed for specific task.
|
||||||
|
|
||||||
use super::super::write::Stdout;
|
use super::super::output::TerminalOutput;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
@ -26,8 +26,8 @@ pub trait IEnableAnsiCommand {
|
|||||||
|
|
||||||
// This trait provides an interface for switching to alternate screen and back.
|
// This trait provides an interface for switching to alternate screen and back.
|
||||||
pub trait IAlternateScreenCommand: Send {
|
pub trait IAlternateScreenCommand: Send {
|
||||||
fn enable(&self, screen_manager: &mut Stdout) -> io::Result<()>;
|
fn enable(&self, screen_manager: &mut TerminalOutput) -> io::Result<()>;
|
||||||
fn disable(&self, screen_manager: &Stdout) -> io::Result<()>;
|
fn disable(&self, screen_manager: &TerminalOutput) -> io::Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This trait provides an interface for switching to raw mode and back.
|
// This trait provides an interface for switching to raw mode and back.
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! This module contains the commands that can be used for both unix and windows 10 systems because they support ANSI escape codes
|
//! This module contains the commands that can be used for both unix and windows 10 systems because they support ANSI escape codes
|
||||||
|
|
||||||
use super::{IAlternateScreenCommand, Stdout};
|
use super::{IAlternateScreenCommand, TerminalOutput};
|
||||||
|
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::io::{ Result, stdout, Write};
|
use std::io::{ Result, stdout, Write};
|
||||||
@ -17,13 +17,13 @@ impl ToAlternateScreenCommand {
|
|||||||
impl IAlternateScreenCommand for ToAlternateScreenCommand {
|
impl IAlternateScreenCommand for ToAlternateScreenCommand {
|
||||||
|
|
||||||
/// enable alternate screen.
|
/// enable alternate screen.
|
||||||
fn enable(&self, screen_manager: &mut Stdout) -> Result<()> {
|
fn enable(&self, screen_manager: &mut TerminalOutput) -> Result<()> {
|
||||||
screen_manager.write_str(csi!("?1049h"));
|
screen_manager.write_str(csi!("?1049h"));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// disable alternate screen.
|
/// disable alternate screen.
|
||||||
fn disable(&self, screen_manager: &Stdout) -> Result<()> {
|
fn disable(&self, screen_manager: &TerminalOutput) -> Result<()> {
|
||||||
screen_manager.write_str(csi!("?1049l"));
|
screen_manager.write_str(csi!("?1049l"));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
//! This module contains the commands that can be used for windows systems.
|
//! This module contains the commands that can be used for windows systems.
|
||||||
|
|
||||||
use super::{IAlternateScreenCommand, IEnableAnsiCommand, IRawScreenCommand, Stdout};
|
use super::{IAlternateScreenCommand, IEnableAnsiCommand, IRawScreenCommand, TerminalOutput};
|
||||||
|
|
||||||
use kernel::windows_kernel::{ansi_support, csbi, handle, kernel};
|
use kernel::windows_kernel::{ansi_support, csbi, handle, kernel};
|
||||||
use modules::write::IStdout;
|
use modules::output::IStdout;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use winapi::shared::minwindef::DWORD;
|
use winapi::shared::minwindef::DWORD;
|
||||||
use winapi::um::wincon;
|
use winapi::um::wincon;
|
||||||
@ -148,8 +148,8 @@ impl ToAlternateScreenCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl IAlternateScreenCommand for ToAlternateScreenCommand {
|
impl IAlternateScreenCommand for ToAlternateScreenCommand {
|
||||||
fn enable(&self, screen_manager: &mut Stdout) -> Result<()> {
|
fn enable(&self, screen_manager: &mut TerminalOutput) -> Result<()> {
|
||||||
use super::super::super::modules::write::WinApiStdout;
|
use super::super::super::modules::output::WinApiOutput;
|
||||||
|
|
||||||
let handle = handle::get_output_handle()?;
|
let handle = handle::get_output_handle()?;
|
||||||
|
|
||||||
@ -159,9 +159,9 @@ impl IAlternateScreenCommand for ToAlternateScreenCommand {
|
|||||||
// Make the new screen buffer the active screen buffer.
|
// Make the new screen buffer the active screen buffer.
|
||||||
csbi::set_active_screen_buffer(new_handle)?;
|
csbi::set_active_screen_buffer(new_handle)?;
|
||||||
|
|
||||||
let b: &mut WinApiStdout = match screen_manager
|
let b: &mut WinApiOutput = match screen_manager
|
||||||
.as_any_mut()
|
.as_any_mut()
|
||||||
.downcast_mut::<WinApiStdout>()
|
.downcast_mut::<WinApiOutput>()
|
||||||
{
|
{
|
||||||
Some(b) => b,
|
Some(b) => b,
|
||||||
None => return Err(Error::new(ErrorKind::Other, "Invalid cast exception")),
|
None => return Err(Error::new(ErrorKind::Other, "Invalid cast exception")),
|
||||||
@ -172,7 +172,7 @@ impl IAlternateScreenCommand for ToAlternateScreenCommand {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disable(&self, screen_manager: &Stdout) -> Result<()> {
|
fn disable(&self, screen_manager: &TerminalOutput) -> Result<()> {
|
||||||
let handle = handle::get_output_handle()?;
|
let handle = handle::get_output_handle()?;
|
||||||
csbi::set_active_screen_buffer(handle);
|
csbi::set_active_screen_buffer(handle);
|
||||||
|
|
||||||
|
@ -4,9 +4,9 @@ use super::screen::{AlternateScreen, Screen};
|
|||||||
|
|
||||||
use super::super::cursor;
|
use super::super::cursor;
|
||||||
use super::super::input;
|
use super::super::input;
|
||||||
use super::super::write;
|
use super::super::output;
|
||||||
use super::super::style;
|
use super::super::style;
|
||||||
use super::super::terminal;
|
use super::super::terminal;
|
||||||
|
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
@ -20,7 +20,7 @@ use common::commands::unix_command;
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use common::commands::win_commands;
|
use common::commands::win_commands;
|
||||||
|
|
||||||
use write::Stdout;
|
use output::TerminalOutput;
|
||||||
|
|
||||||
/// This type could be used to access the `cursor, terminal, color, input, styling` module more easily.
|
/// This type could be used to access the `cursor, terminal, color, input, styling` module more easily.
|
||||||
/// You need to pass a reference to the screen where on you want to perform the actions to the `Crossterm` type.
|
/// You need to pass a reference to the screen where on you want to perform the actions to the `Crossterm` type.
|
||||||
@ -50,7 +50,7 @@ use write::Stdout;
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub struct Crossterm {
|
pub struct Crossterm {
|
||||||
stdout: Arc<Stdout>
|
stdout: Arc<TerminalOutput>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'crossterm> Crossterm {
|
impl<'crossterm> Crossterm {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Some actions need to preformed platform independently since they can not be solved `ANSI escape codes`.
|
//! Some actions need to preformed platform independently since they can not be solved `ANSI escape codes`.
|
||||||
|
|
||||||
use super::Stdout;
|
use super::TerminalOutput;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
@ -17,28 +17,16 @@ use kernel::unix_kernel::terminal::{exit, pos, terminal_size};
|
|||||||
|
|
||||||
/// Get the terminal size based on the current platform.
|
/// Get the terminal size based on the current platform.
|
||||||
pub fn get_terminal_size() -> (u16, u16) {
|
pub fn get_terminal_size() -> (u16, u16) {
|
||||||
#[cfg(unix)]
|
|
||||||
return terminal_size();
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
return terminal_size();
|
return terminal_size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the cursor position based on the current platform.
|
/// Get the cursor position based on the current platform.
|
||||||
pub fn get_cursor_position(stdout: &Arc<Stdout>) -> (u16, u16) {
|
pub fn get_cursor_position(stdout: &Arc<TerminalOutput>) -> (u16, u16) {
|
||||||
#[cfg(unix)]
|
|
||||||
return pos(stdout);
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
return pos(stdout);
|
return pos(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// exit the current terminal.
|
/// exit the current terminal.
|
||||||
pub fn exit_terminal() {
|
pub fn exit_terminal() {
|
||||||
#[cfg(unix)]
|
|
||||||
exit();
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,5 +10,4 @@ pub mod traits;
|
|||||||
mod crossterm;
|
mod crossterm;
|
||||||
|
|
||||||
pub use self::crossterm::Crossterm;
|
pub use self::crossterm::Crossterm;
|
||||||
use super::modules::Stdout;
|
use {Screen, TerminalOutput};
|
||||||
pub use screen::Screen;
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
//! Vim uses the entirety of the screen to edit the file, then returning to bash leaves the original buffer unchanged.
|
//! Vim uses the entirety of the screen to edit the file, then returning to bash leaves the original buffer unchanged.
|
||||||
|
|
||||||
use super::commands::{self, IAlternateScreenCommand};
|
use super::commands::{self, IAlternateScreenCommand};
|
||||||
use super::{functions, Screen, Stdout, RawScreen};
|
use super::{functions, Screen, TerminalOutput, RawScreen};
|
||||||
|
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
@ -35,7 +35,7 @@ impl AlternateScreen {
|
|||||||
/// 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.
|
||||||
/// Vim uses the entirety of the screen to edit the file, then returning to bash leaves the original buffer unchanged.
|
/// Vim uses the entirety of the screen to edit the file, then returning to bash leaves the original buffer unchanged.
|
||||||
pub fn to_alternate_screen(screen_manager: Stdout) -> io::Result<AlternateScreen> {
|
pub fn to_alternate_screen(stdout: TerminalOutput) -> io::Result<AlternateScreen> {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let command = functions::get_module::<Box<commands::IAlternateScreenCommand + Send>>(
|
let command = functions::get_module::<Box<commands::IAlternateScreenCommand + Send>>(
|
||||||
Box::from(commands::win_commands::ToAlternateScreenCommand::new()),
|
Box::from(commands::win_commands::ToAlternateScreenCommand::new()),
|
||||||
@ -45,7 +45,7 @@ impl AlternateScreen {
|
|||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
let command = Box::from(commands::shared_commands::ToAlternateScreenCommand::new());
|
let command = Box::from(commands::shared_commands::ToAlternateScreenCommand::new());
|
||||||
|
|
||||||
let mut stdout = screen_manager;
|
let mut stdout = stdout;
|
||||||
command.enable(&mut stdout)?;
|
command.enable(&mut stdout)?;
|
||||||
return Ok(AlternateScreen::new(command, Screen::from(stdout)));
|
return Ok(AlternateScreen::new(command, Screen::from(stdout)));
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ mod alternate;
|
|||||||
mod raw;
|
mod raw;
|
||||||
mod screen;
|
mod screen;
|
||||||
|
|
||||||
use super::{commands, functions, Stdout};
|
use super::{commands, functions, TerminalOutput};
|
||||||
|
|
||||||
pub use self::alternate::AlternateScreen;
|
pub use self::alternate::AlternateScreen;
|
||||||
pub use self::screen::Screen;
|
pub use self::screen::Screen;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
//! With these modes you can easier design the terminal screen.
|
//! With these modes you can easier design the terminal screen.
|
||||||
|
|
||||||
use super::commands::*;
|
use super::commands::*;
|
||||||
use super::{functions, Screen, Stdout};
|
use super::{functions, Screen, TerminalOutput};
|
||||||
|
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ use common::commands::win_commands;
|
|||||||
use common::commands::IAlternateScreenCommand;
|
use common::commands::IAlternateScreenCommand;
|
||||||
|
|
||||||
use super::{AlternateScreen,RawScreen};
|
use super::{AlternateScreen,RawScreen};
|
||||||
use super::super::super::modules::write::Stdout;
|
use TerminalOutput;
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::io::Result;
|
use std::io::Result;
|
||||||
@ -52,7 +52,7 @@ use std::sync::Arc;
|
|||||||
pub struct Screen
|
pub struct Screen
|
||||||
{
|
{
|
||||||
buffer: Vec<u8>,
|
buffer: Vec<u8>,
|
||||||
pub stdout: Arc<Stdout>,
|
pub stdout: Arc<TerminalOutput>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Screen
|
impl Screen
|
||||||
@ -64,7 +64,7 @@ impl Screen
|
|||||||
if raw_mode
|
if raw_mode
|
||||||
{
|
{
|
||||||
RawScreen::into_raw_mode();;
|
RawScreen::into_raw_mode();;
|
||||||
return Screen { stdout: Arc::new(Stdout::new(true)), buffer: Vec::new() };
|
return Screen { stdout: Arc::new(TerminalOutput::new(true)), buffer: Vec::new() };
|
||||||
}
|
}
|
||||||
|
|
||||||
return Screen::default();
|
return Screen::default();
|
||||||
@ -98,7 +98,7 @@ impl Screen
|
|||||||
/// 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.
|
||||||
/// Vim uses the entirety of the screen to edit the file, then returning to bash leaves the original buffer unchanged.
|
/// Vim uses the entirety of the screen to edit the file, then returning to bash leaves the original buffer unchanged.
|
||||||
pub fn enable_alternate_modes(&self, raw_mode: bool) -> Result<AlternateScreen> {
|
pub fn enable_alternate_modes(&self, raw_mode: bool) -> Result<AlternateScreen> {
|
||||||
let mut stdout = Stdout::new(raw_mode);
|
let mut stdout = TerminalOutput::new(raw_mode);
|
||||||
|
|
||||||
if raw_mode
|
if raw_mode
|
||||||
{
|
{
|
||||||
@ -110,18 +110,18 @@ impl Screen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Stdout> for Screen
|
impl From<TerminalOutput> for Screen
|
||||||
{
|
{
|
||||||
/// Create an screen with the given `Stdout`
|
/// Create an screen with the given `Stdout`
|
||||||
fn from(stdout: Stdout) -> Self {
|
fn from(stdout: TerminalOutput) -> Self {
|
||||||
return Screen { stdout: Arc::new(stdout), buffer: Vec::new() };
|
return Screen { stdout: Arc::new(stdout), buffer: Vec::new() };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Arc<Stdout>> for Screen
|
impl From<Arc<TerminalOutput>> for Screen
|
||||||
{
|
{
|
||||||
/// Create an screen with the given 'Arc<Stdout>'
|
/// Create an screen with the given 'Arc<Stdout>'
|
||||||
fn from(stdout: Arc<Stdout>) -> Self {
|
fn from(stdout: Arc<TerminalOutput>) -> Self {
|
||||||
return Screen { stdout: stdout, buffer: Vec::new() };
|
return Screen { stdout: stdout, buffer: Vec::new() };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ impl Default for Screen
|
|||||||
{
|
{
|
||||||
/// Create an new screen which will not be in raw mode or alternate mode.
|
/// Create an new screen which will not be in raw mode or alternate mode.
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
return Screen { stdout: Arc::new(Stdout::new(false)), buffer: Vec::new() };
|
return Screen { stdout: Arc::new(TerminalOutput::new(false)), buffer: Vec::new() };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use self::libc::{c_int, c_ushort, ioctl, STDOUT_FILENO, TIOCGWINSZ};
|
use self::libc::{c_int, c_ushort, ioctl, STDOUT_FILENO, TIOCGWINSZ};
|
||||||
use common::commands::unix_command::{RawModeCommand, NoncanonicalModeCommand};
|
use common::commands::unix_command::{RawModeCommand, NoncanonicalModeCommand};
|
||||||
use {libc, Stdout, Screen};
|
use {libc, TerminalOutput, Screen};
|
||||||
pub use libc::termios;
|
pub use libc::termios;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -45,7 +45,7 @@ pub fn terminal_size() -> (u16, u16) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the current cursor position.
|
/// Get the current cursor position.
|
||||||
pub fn pos(stdout: &Arc<Stdout>) -> (u16, u16) {
|
pub fn pos(stdout: &Arc<TerminalOutput>) -> (u16, u16) {
|
||||||
let mut crossterm = Crossterm::new(&Screen::default());
|
let mut crossterm = Crossterm::new(&Screen::default());
|
||||||
let input = crossterm.input();
|
let input = crossterm.input();
|
||||||
|
|
||||||
|
@ -7,18 +7,18 @@ use winapi::um::wincon::{
|
|||||||
CreateConsoleScreenBuffer, GetConsoleScreenBufferInfo, SetConsoleActiveScreenBuffer,
|
CreateConsoleScreenBuffer, GetConsoleScreenBufferInfo, SetConsoleActiveScreenBuffer,
|
||||||
SetConsoleScreenBufferSize, CONSOLE_SCREEN_BUFFER_INFO, CONSOLE_TEXTMODE_BUFFER, COORD,
|
SetConsoleScreenBufferSize, CONSOLE_SCREEN_BUFFER_INFO, CONSOLE_TEXTMODE_BUFFER, COORD,
|
||||||
};
|
};
|
||||||
use winapi::um::winnt::HANDLE;
|
|
||||||
use winapi::um::winnt::{FILE_SHARE_READ, FILE_SHARE_WRITE, GENERIC_READ, GENERIC_WRITE};
|
use winapi::um::winnt::{FILE_SHARE_READ, FILE_SHARE_WRITE, GENERIC_READ, GENERIC_WRITE};
|
||||||
|
|
||||||
use super::{handle, kernel, Empty, Stdout};
|
use super::{handle, kernel, Empty, TerminalOutput, HANDLE};
|
||||||
|
|
||||||
use std::sync::{Once, ONCE_INIT};
|
|
||||||
use std::io::{self, ErrorKind, Result};
|
use std::io::{self, ErrorKind, Result};
|
||||||
|
use std::sync::{Once, ONCE_INIT};
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
/// Create a new console screen buffer info struct.
|
/// Create a new console screen buffer info struct.
|
||||||
pub fn get_csbi(screen_manager: &Arc<Stdout>) -> Result<CONSOLE_SCREEN_BUFFER_INFO> {
|
pub fn get_csbi(screen_manager: &Arc<TerminalOutput>) -> Result<CONSOLE_SCREEN_BUFFER_INFO> {
|
||||||
let mut csbi = CONSOLE_SCREEN_BUFFER_INFO::empty();
|
let mut csbi = CONSOLE_SCREEN_BUFFER_INFO::empty();
|
||||||
let success;
|
let success;
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ pub fn get_csbi(screen_manager: &Arc<Stdout>) -> Result<CONSOLE_SCREEN_BUFFER_IN
|
|||||||
|
|
||||||
/// Get buffer info and handle of the current screen.
|
/// Get buffer info and handle of the current screen.
|
||||||
pub fn get_csbi_and_handle(
|
pub fn get_csbi_and_handle(
|
||||||
screen_manager: &Arc<Stdout>,
|
screen_manager: &Arc<TerminalOutput>,
|
||||||
) -> Result<(CONSOLE_SCREEN_BUFFER_INFO, HANDLE)> {
|
) -> Result<(CONSOLE_SCREEN_BUFFER_INFO, HANDLE)> {
|
||||||
let handle = handle::get_current_handle(screen_manager)?;
|
let handle = handle::get_current_handle(screen_manager)?;
|
||||||
let csbi = get_csbi_by_handle(&handle)?;
|
let csbi = get_csbi_by_handle(&handle)?;
|
||||||
@ -63,7 +63,7 @@ pub fn get_csbi_by_handle(handle: &HANDLE) -> Result<CONSOLE_SCREEN_BUFFER_INFO>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set the console screen buffer size
|
/// Set the console screen buffer size
|
||||||
pub fn set_console_screen_buffer_size(size: COORD, screen_manager: &Arc<Stdout>) -> bool {
|
pub fn set_console_screen_buffer_size(size: COORD, screen_manager: &Arc<TerminalOutput>) -> bool {
|
||||||
let handle = handle::get_current_handle(screen_manager).unwrap();
|
let handle = handle::get_current_handle(screen_manager).unwrap();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -5,29 +5,28 @@ use winapi::um::wincon::{
|
|||||||
SetConsoleCursorInfo, SetConsoleCursorPosition, CONSOLE_CURSOR_INFO, COORD,
|
SetConsoleCursorInfo, SetConsoleCursorPosition, CONSOLE_CURSOR_INFO, COORD,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::super::super::modules::write::{Stdout, WinApiStdout};
|
use super::{csbi, handle, kernel, TerminalOutput, WinApiOutput};
|
||||||
use super::{csbi, handle, kernel};
|
|
||||||
|
|
||||||
use std::io::{self, ErrorKind, Result};
|
use std::io;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
/// 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);
|
||||||
|
|
||||||
/// Reset to saved cursor position
|
/// Reset to saved cursor position
|
||||||
pub fn reset_to_saved_position(screen_manager: &Arc<Stdout>) {
|
pub fn reset_to_saved_position(stdout: &Arc<TerminalOutput>) {
|
||||||
unsafe {
|
unsafe {
|
||||||
set_console_cursor_position(
|
set_console_cursor_position(
|
||||||
SAVED_CURSOR_POS.0 as i16,
|
SAVED_CURSOR_POS.0 as i16,
|
||||||
SAVED_CURSOR_POS.1 as i16,
|
SAVED_CURSOR_POS.1 as i16,
|
||||||
screen_manager,
|
stdout,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Save current cursor position to recall later.
|
/// Save current cursor position to recall later.
|
||||||
pub fn save_cursor_pos(screen_manager: &Arc<Stdout>) {
|
pub fn save_cursor_pos(stdout: &Arc<TerminalOutput>) {
|
||||||
let position = pos(screen_manager);
|
let position = pos(stdout);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
SAVED_CURSOR_POS = (position.0, position.1);
|
SAVED_CURSOR_POS = (position.0, position.1);
|
||||||
@ -35,8 +34,8 @@ pub fn save_cursor_pos(screen_manager: &Arc<Stdout>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// get the current cursor position.
|
/// get the current cursor position.
|
||||||
pub fn pos(screen_manager: &Arc<Stdout>) -> (u16, u16) {
|
pub fn pos(stdout: &Arc<TerminalOutput>) -> (u16, u16) {
|
||||||
let handle = handle::get_current_handle(screen_manager).unwrap();
|
let handle = handle::get_current_handle(stdout).unwrap();
|
||||||
|
|
||||||
if let Ok(csbi) = csbi::get_csbi_by_handle(&handle) {
|
if let Ok(csbi) = csbi::get_csbi_by_handle(&handle) {
|
||||||
(
|
(
|
||||||
@ -49,7 +48,7 @@ pub fn pos(screen_manager: &Arc<Stdout>) -> (u16, u16) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set the cursor position to the given x and y. Note that this is 0 based.
|
/// Set the cursor position to the given x and y. Note that this is 0 based.
|
||||||
pub fn set_console_cursor_position(x: i16, y: i16, screen_manager: &Arc<Stdout>) {
|
pub fn set_console_cursor_position(x: i16, y: i16, stdout: &Arc<TerminalOutput>) {
|
||||||
if x < 0 || x >= <i16>::max_value() {
|
if x < 0 || x >= <i16>::max_value() {
|
||||||
panic!(
|
panic!(
|
||||||
"Argument Out of Range Exception when setting cursor position to X: {}",
|
"Argument Out of Range Exception when setting cursor position to X: {}",
|
||||||
@ -64,7 +63,7 @@ pub fn set_console_cursor_position(x: i16, y: i16, screen_manager: &Arc<Stdout>)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let handle = handle::get_current_handle(screen_manager).unwrap();
|
let handle = handle::get_current_handle(stdout).unwrap();
|
||||||
|
|
||||||
let position = COORD { X: x, Y: y };
|
let position = COORD { X: x, Y: y };
|
||||||
|
|
||||||
@ -78,8 +77,8 @@ pub fn set_console_cursor_position(x: i16, y: i16, screen_manager: &Arc<Stdout>)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// change the cursor visibility.
|
/// change the cursor visibility.
|
||||||
pub fn cursor_visibility(visable: bool, screen_manager: &Arc<Stdout>) -> Result<()> {
|
pub fn cursor_visibility(visable: bool, stdout: &Arc<TerminalOutput>) -> io::Result<()> {
|
||||||
let handle = handle::get_current_handle(screen_manager).unwrap();
|
let handle = handle::get_current_handle(stdout).unwrap();
|
||||||
|
|
||||||
let cursor_info = CONSOLE_CURSOR_INFO {
|
let cursor_info = CONSOLE_CURSOR_INFO {
|
||||||
dwSize: 100,
|
dwSize: 100,
|
||||||
|
@ -3,19 +3,19 @@
|
|||||||
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::winbase::{STD_INPUT_HANDLE, STD_OUTPUT_HANDLE};
|
use winapi::um::winbase::{STD_INPUT_HANDLE, STD_OUTPUT_HANDLE};
|
||||||
use winapi::um::winnt::HANDLE;
|
use super::*;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use super::super::super::modules::write::{Stdout, WinApiStdout};
|
|
||||||
|
|
||||||
/// Get the global stored handle whits provides access to the current screen.
|
/// Get the global stored handle whits provides access to the current screen.
|
||||||
pub fn get_current_handle(screen_manager: &Arc<Stdout>) -> Result<HANDLE> {
|
pub fn get_current_handle(screen_manager: &Arc<TerminalOutput>) -> Result<HANDLE> {
|
||||||
let mut mutex = screen_manager;
|
let mut mutex = screen_manager;
|
||||||
|
|
||||||
let handle: Result<HANDLE>;
|
let handle: Result<HANDLE>;
|
||||||
|
|
||||||
let winapi_screen_manager: &WinApiStdout = match screen_manager
|
let winapi_screen_manager: &WinApiOutput = match screen_manager
|
||||||
.as_any()
|
.as_any()
|
||||||
.downcast_ref::<WinApiStdout>()
|
.downcast_ref::<WinApiOutput>()
|
||||||
{
|
{
|
||||||
Some(win_api) => win_api,
|
Some(win_api) => win_api,
|
||||||
None => return Err(io::Error::new(io::ErrorKind::Other,"Could not convert to winapi screen write, this could happen when the user has an ANSI screen write and is calling the platform specific operations 'get_cursor_pos' or 'get_terminal_size'"))
|
None => return Err(io::Error::new(io::ErrorKind::Other,"Could not convert to winapi screen write, this could happen when the user has an ANSI screen write and is calling the platform specific operations 'get_cursor_pos' or 'get_terminal_size'"))
|
||||||
|
@ -4,10 +4,8 @@ use winapi::um::consoleapi::{GetConsoleMode, SetConsoleMode};
|
|||||||
use winapi::um::wincon::{
|
use winapi::um::wincon::{
|
||||||
GetLargestConsoleWindowSize, SetConsoleTextAttribute, SetConsoleWindowInfo, COORD, SMALL_RECT,
|
GetLargestConsoleWindowSize, SetConsoleTextAttribute, SetConsoleWindowInfo, COORD, SMALL_RECT,
|
||||||
};
|
};
|
||||||
use winapi::um::winnt::HANDLE;
|
|
||||||
|
|
||||||
use super::super::super::modules::Stdout;
|
use super::*;
|
||||||
use super::{handle, Empty};
|
|
||||||
|
|
||||||
use std::io::{ErrorKind, Result};
|
use std::io::{ErrorKind, Result};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -34,8 +32,8 @@ pub fn get_console_mode(handle: &HANDLE, current_mode: &mut u32) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Change the console text attribute.
|
/// Change the console text attribute.
|
||||||
pub fn set_console_text_attribute(value: u16, screen_manager: &Arc<Stdout>) -> bool {
|
pub fn set_console_text_attribute(value: u16, stdout: &Arc<TerminalOutput>) -> bool {
|
||||||
let handle = handle::get_current_handle(screen_manager).unwrap();
|
let handle = handle::get_current_handle(stdout).unwrap();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
return is_true(SetConsoleTextAttribute(handle, value));
|
return is_true(SetConsoleTextAttribute(handle, value));
|
||||||
@ -43,8 +41,8 @@ pub fn set_console_text_attribute(value: u16, screen_manager: &Arc<Stdout>) -> b
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Change console info.
|
/// Change console info.
|
||||||
pub fn set_console_info(absolute: bool, rect: &SMALL_RECT, screen_manager: &Arc<Stdout>) -> bool {
|
pub fn set_console_info(absolute: bool, rect: &SMALL_RECT, stdout: &Arc<TerminalOutput>) -> bool {
|
||||||
let handle = handle::get_current_handle(screen_manager).unwrap();
|
let handle = handle::get_current_handle(stdout).unwrap();
|
||||||
|
|
||||||
let absolute = match absolute {
|
let absolute = match absolute {
|
||||||
true => 1,
|
true => 1,
|
||||||
|
@ -8,9 +8,14 @@ pub mod kernel;
|
|||||||
pub mod terminal;
|
pub mod terminal;
|
||||||
pub mod writing;
|
pub mod writing;
|
||||||
|
|
||||||
use super::super::modules::Stdout;
|
|
||||||
use common::traits::Empty;
|
|
||||||
use winapi::um::wincon::{CONSOLE_SCREEN_BUFFER_INFO, COORD, SMALL_RECT};
|
use winapi::um::wincon::{CONSOLE_SCREEN_BUFFER_INFO, COORD, SMALL_RECT};
|
||||||
|
use winapi::um::winnt::HANDLE;
|
||||||
|
|
||||||
|
use TerminalOutput;
|
||||||
|
use super::super::modules::output::WinApiOutput;
|
||||||
|
|
||||||
|
use common::traits::Empty;
|
||||||
|
|
||||||
|
|
||||||
impl Empty for COORD {
|
impl Empty for COORD {
|
||||||
fn empty() -> COORD {
|
fn empty() -> COORD {
|
||||||
|
@ -11,12 +11,12 @@
|
|||||||
//use super::kernel;
|
//use super::kernel;
|
||||||
//use winapi::ctypes::c_void;
|
//use winapi::ctypes::c_void;
|
||||||
//
|
//
|
||||||
//pub fn read(buf: &mut [u8], screen_manager: &Rc<Mutex<ScreenManager>>) {
|
//pub fn read(buf: &mut [u8], stdout: &Rc<Mutex<ScreenManager>>) {
|
||||||
//// // Read more if the buffer is empty
|
//// // Read more if the buffer is empty
|
||||||
//// let mut utf16: Vec<u16> = Vec::new();
|
//// let mut utf16: Vec<u16> = Vec::new();
|
||||||
//// let mut num: DWORD = 0;
|
//// let mut num: DWORD = 0;
|
||||||
////
|
////
|
||||||
//// let handle = kernel::get_current_handle(&screen_manager);
|
//// let handle = kernel::get_current_handle(&stdout);
|
||||||
////
|
////
|
||||||
//// unsafe {
|
//// unsafe {
|
||||||
//// ReadConsoleW(handle,
|
//// ReadConsoleW(handle,
|
||||||
@ -36,12 +36,12 @@
|
|||||||
//
|
//
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//pub fn read_line(screen_manager: &Rc<Mutex<ScreenManager>>) -> ::std::io::Result<String>
|
//pub fn read_line(stdout: &Rc<Mutex<ScreenManager>>) -> ::std::io::Result<String>
|
||||||
//{
|
//{
|
||||||
// const BUFFER_LENGHT: u32 = 1024;
|
// const BUFFER_LENGHT: u32 = 1024;
|
||||||
// let mut buffer: &mut [CHAR_INFO; BUFFER_LENGHT as usize] = unsafe {::std::mem::zeroed() };
|
// let mut buffer: &mut [CHAR_INFO; BUFFER_LENGHT as usize] = unsafe {::std::mem::zeroed() };
|
||||||
//
|
//
|
||||||
// let handle = kernel::get_current_handle(&screen_manager);
|
// let handle = kernel::get_current_handle(&stdout);
|
||||||
//
|
//
|
||||||
// let mut dw_mode: DWORD = 0;
|
// let mut dw_mode: DWORD = 0;
|
||||||
// let console_mode = kernel::get_console_mode(&handle, &mut dw_mode);
|
// let console_mode = kernel::get_console_mode(&handle, &mut dw_mode);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
//! This module contains terminal specific logic.
|
//! This module contains terminal specific logic.
|
||||||
|
|
||||||
use super::{csbi, handle, Stdout};
|
use super::{csbi, handle, TerminalOutput};
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
/// Get the terminal size
|
/// Get the terminal size
|
||||||
@ -18,7 +17,7 @@ pub fn terminal_size() -> (u16, u16) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn buffer_size(screen_manager: &Arc<Stdout>) -> (u16, u16) {
|
pub fn buffer_size(screen_manager: &Arc<TerminalOutput>) -> (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) {
|
if let Ok(csbi) = csbi::get_csbi_by_handle(&handle) {
|
||||||
|
@ -7,9 +7,8 @@ use winapi::um::wincon::{
|
|||||||
self, FillConsoleOutputAttribute, FillConsoleOutputCharacterA, WriteConsoleOutputA, CHAR_INFO,
|
self, FillConsoleOutputAttribute, FillConsoleOutputCharacterA, WriteConsoleOutputA, CHAR_INFO,
|
||||||
COORD, PSMALL_RECT,
|
COORD, PSMALL_RECT,
|
||||||
};
|
};
|
||||||
use winapi::um::winnt::HANDLE;
|
|
||||||
|
|
||||||
use super::{csbi, handle, kernel, Stdout};
|
use super::{csbi, handle, kernel, TerminalOutput, HANDLE};
|
||||||
|
|
||||||
use std::io::{self, ErrorKind, Result};
|
use std::io::{self, ErrorKind, Result};
|
||||||
use std::str;
|
use std::str;
|
||||||
@ -20,7 +19,7 @@ pub fn fill_console_output_character(
|
|||||||
cells_written: &mut u32,
|
cells_written: &mut u32,
|
||||||
start_location: COORD,
|
start_location: COORD,
|
||||||
cells_to_write: u32,
|
cells_to_write: u32,
|
||||||
screen_manager: &Arc<Stdout>,
|
screen_manager: &Arc<TerminalOutput>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let handle = handle::get_current_handle(screen_manager).unwrap();
|
let handle = handle::get_current_handle(screen_manager).unwrap();
|
||||||
|
|
||||||
@ -42,7 +41,7 @@ pub fn fill_console_output_attribute(
|
|||||||
cells_written: &mut u32,
|
cells_written: &mut u32,
|
||||||
start_location: COORD,
|
start_location: COORD,
|
||||||
cells_to_write: u32,
|
cells_to_write: u32,
|
||||||
screen_manager: &Arc<Stdout>,
|
screen_manager: &Arc<TerminalOutput>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
// Get the position of the current console window
|
// Get the position of the current console window
|
||||||
|
|
||||||
|
12
src/lib.rs
12
src/lib.rs
@ -12,14 +12,20 @@ mod modules;
|
|||||||
pub use common::screen;
|
pub use common::screen;
|
||||||
pub use modules::cursor;
|
pub use modules::cursor;
|
||||||
pub use modules::input;
|
pub use modules::input;
|
||||||
pub use modules::write;
|
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;
|
||||||
pub use common::Crossterm;
|
pub use common::Crossterm;
|
||||||
pub use write::{Stdout};
|
pub use output::TerminalOutput;
|
||||||
use write::IStdout;
|
pub use self::cursor::*;
|
||||||
|
pub use self::input::*;
|
||||||
|
pub use self::output::*;
|
||||||
|
pub use self::style::*;
|
||||||
|
|
||||||
|
use output::IStdout;
|
||||||
|
use common::functions;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
@ -2,9 +2,7 @@
|
|||||||
//! This module is used for windows 10 terminals and unix terminals by default.
|
//! This module is used for windows 10 terminals and unix terminals by default.
|
||||||
//! Note that the cursor position is 0 based. This means that we start counting at 0 when setting the cursor position ect.
|
//! Note that the cursor position is 0 based. This means that we start counting at 0 when setting the cursor position ect.
|
||||||
|
|
||||||
use super::{functions, ITerminalCursor, Stdout};
|
use super::*;
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
|
|
||||||
/// This struct is an ansi implementation for cursor related actions.
|
/// This struct is an ansi implementation for cursor related actions.
|
||||||
@ -17,47 +15,47 @@ impl AnsiCursor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ITerminalCursor for AnsiCursor {
|
impl ITerminalCursor for AnsiCursor {
|
||||||
fn goto(&self, x: u16, y: u16, screen_manager: &Arc<Stdout>) {
|
fn goto(&self, x: u16, y: u16, stdout: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_string(format!(csi!("{};{}H"), y + 1, x + 1));
|
stdout.write_string(format!(csi!("{};{}H"), y + 1, x + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pos(&self, screen_manager: &Arc<Stdout>) -> (u16, u16) {
|
fn pos(&self, stdout: &Arc<TerminalOutput>) -> (u16, u16) {
|
||||||
functions::get_cursor_position(screen_manager)
|
functions::get_cursor_position(stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_up(&self, count: u16, screen_manager: &Arc<Stdout>) {
|
fn move_up(&self, count: u16, stdout: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_string(format!(csi!("{}A"), count));
|
stdout.write_string(format!(csi!("{}A"), count));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_right(&self, count: u16, screen_manager: &Arc<Stdout>) {
|
fn move_right(&self, count: u16, screen_manager: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_string(format!(csi!("{}C"), count));
|
screen_manager.write_string(format!(csi!("{}C"), count));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_down(&self, count: u16, screen_manager: &Arc<Stdout>) {
|
fn move_down(&self, count: u16, screen_manager: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_string(format!(csi!("{}B"), count));
|
screen_manager.write_string(format!(csi!("{}B"), count));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_left(&self, count: u16, screen_manager: &Arc<Stdout>) {
|
fn move_left(&self, count: u16, screen_manager: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_string(format!(csi!("{}D"), count));
|
screen_manager.write_string(format!(csi!("{}D"), count));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_position(&self, screen_manager: &Arc<Stdout>) {
|
fn save_position(&self, screen_manager: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_str(csi!("s"));
|
screen_manager.write_str(csi!("s"));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reset_position(&self, screen_manager: &Arc<Stdout>) {
|
fn reset_position(&self, screen_manager: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_str(csi!("u"));
|
screen_manager.write_str(csi!("u"));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hide(&self, screen_manager: &Arc<Stdout>) {
|
fn hide(&self, screen_manager: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_str(csi!("?25l"));
|
screen_manager.write_str(csi!("?25l"));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show(&self, screen_manager: &Arc<Stdout>) {
|
fn show(&self, screen_manager: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_str(csi!("?25h"));
|
screen_manager.write_str(csi!("?25h"));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn blink(&self, blink: bool, screen_manager: &Arc<Stdout>) {
|
fn blink(&self, blink: bool, screen_manager: &Arc<TerminalOutput>) {
|
||||||
if blink {
|
if blink {
|
||||||
screen_manager.write_str(csi!("?12h"));
|
screen_manager.write_str(csi!("?12h"));
|
||||||
} else {
|
} else {
|
||||||
|
@ -4,12 +4,11 @@
|
|||||||
//! Note that positions of the cursor are 0 -based witch means that the coordinates (cells) starts counting from 0
|
//! Note that positions of the cursor are 0 -based witch means that the coordinates (cells) starts counting from 0
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use Screen;
|
||||||
|
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
/// Struct that stores an specific platform implementation for cursor related actions.
|
/// Struct that stores an specific platform implementation for cursor related actions.
|
||||||
///
|
///
|
||||||
/// Check `/examples/cursor` in the library for more specific examples.
|
/// Check `/examples/cursor` in the library for more specific examples.
|
||||||
@ -31,13 +30,13 @@ use std::sync::Arc;
|
|||||||
/// cursor.move_left(2);
|
/// cursor.move_left(2);
|
||||||
/// ```
|
/// ```
|
||||||
pub struct TerminalCursor<'stdout> {
|
pub struct TerminalCursor<'stdout> {
|
||||||
screen: &'stdout Arc<Stdout>,
|
screen: &'stdout Arc<TerminalOutput>,
|
||||||
terminal_cursor: Box<ITerminalCursor>,
|
terminal_cursor: Box<ITerminalCursor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'stdout> TerminalCursor<'stdout> {
|
impl<'stdout> TerminalCursor<'stdout> {
|
||||||
/// 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(screen: &'stdout Arc<Stdout>) -> TerminalCursor<'stdout> {
|
pub fn new(screen: &'stdout Arc<TerminalOutput>) -> TerminalCursor<'stdout> {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let cursor =
|
let cursor =
|
||||||
functions::get_module::<Box<ITerminalCursor>>(WinApiCursor::new(), AnsiCursor::new())
|
functions::get_module::<Box<ITerminalCursor>>(WinApiCursor::new(), AnsiCursor::new())
|
||||||
@ -203,6 +202,6 @@ impl<'stdout> TerminalCursor<'stdout> {
|
|||||||
|
|
||||||
/// Get an TerminalCursor implementation whereon cursor related actions can be performed.
|
/// Get an TerminalCursor implementation whereon cursor related actions can be performed.
|
||||||
/// Pass the reference to any screen you want this type to perform actions on.
|
/// Pass the reference to any screen you want this type to perform actions on.
|
||||||
pub fn cursor<'stdout>(screen_manager: &'stdout Screen) -> TerminalCursor<'stdout> {
|
pub fn cursor<'stdout>(stdout: &'stdout Screen) -> TerminalCursor<'stdout> {
|
||||||
TerminalCursor::new(&screen_manager.stdout)
|
TerminalCursor::new(&stdout.stdout)
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,9 @@ use self::ansi_cursor::AnsiCursor;
|
|||||||
use self::winapi_cursor::WinApiCursor;
|
use self::winapi_cursor::WinApiCursor;
|
||||||
|
|
||||||
pub use self::cursor::{cursor, TerminalCursor};
|
pub use self::cursor::{cursor, TerminalCursor};
|
||||||
use super::{functions, Stdout, Screen};
|
|
||||||
|
|
||||||
|
use super::functions;
|
||||||
|
use TerminalOutput;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
///! This trait defines the actions that can be preformed with the terminal cursor.
|
///! This trait defines the actions that can be preformed with the terminal cursor.
|
||||||
@ -26,25 +27,25 @@ use std::sync::Arc;
|
|||||||
///! so that cursor related actions can be preformed on both unix and windows systems.
|
///! so that cursor related actions can be preformed on both unix and windows systems.
|
||||||
trait ITerminalCursor {
|
trait ITerminalCursor {
|
||||||
/// Goto some location (x,y) in the context.
|
/// Goto some location (x,y) in the context.
|
||||||
fn goto(&self, x: u16, y: u16, screen_manager: &Arc<Stdout>);
|
fn goto(&self, x: u16, y: u16, screen_manager: &Arc<TerminalOutput>);
|
||||||
/// Get the location (x,y) of the current cusror in the context
|
/// Get the location (x,y) of the current cusror in the context
|
||||||
fn pos(&self, screen_manager: &Arc<Stdout>) -> (u16, u16);
|
fn pos(&self, screen_manager: &Arc<TerminalOutput>) -> (u16, u16);
|
||||||
/// Move cursor n times up
|
/// Move cursor n times up
|
||||||
fn move_up(&self, count: u16, screen_manager: &Arc<Stdout>);
|
fn move_up(&self, count: u16, screen_manager: &Arc<TerminalOutput>);
|
||||||
/// Move the cursor `n` times to the right.
|
/// Move the cursor `n` times to the right.
|
||||||
fn move_right(&self, count: u16, screen_manager: &Arc<Stdout>);
|
fn move_right(&self, count: u16, screen_manager: &Arc<TerminalOutput>);
|
||||||
/// Move the cursor `n` times down.
|
/// Move the cursor `n` times down.
|
||||||
fn move_down(&self, count: u16, screen_manager: &Arc<Stdout>);
|
fn move_down(&self, count: u16, screen_manager: &Arc<TerminalOutput>);
|
||||||
/// Move the cursor `n` times left.
|
/// Move the cursor `n` times left.
|
||||||
fn move_left(&self, count: u16, screen_manager: &Arc<Stdout>);
|
fn move_left(&self, count: u16, screen_manager: &Arc<TerminalOutput>);
|
||||||
/// Save cursor position so that its saved position can be recalled later. Note that this position is stored program based not per instance of the cursor struct.
|
/// Save cursor position so that its saved position can be recalled later. Note that this position is stored program based not per instance of the cursor struct.
|
||||||
fn save_position(&self, screen_manager: &Arc<Stdout>);
|
fn save_position(&self, screen_manager: &Arc<TerminalOutput>);
|
||||||
/// Return to saved cursor position
|
/// Return to saved cursor position
|
||||||
fn reset_position(&self, screen_manager: &Arc<Stdout>);
|
fn reset_position(&self, screen_manager: &Arc<TerminalOutput>);
|
||||||
/// Hide the terminal cursor.
|
/// Hide the terminal cursor.
|
||||||
fn hide(&self, screen_manager: &Arc<Stdout>);
|
fn hide(&self, screen_manager: &Arc<TerminalOutput>);
|
||||||
/// Show the terminal cursor
|
/// Show the terminal cursor
|
||||||
fn show(&self, screen_manager: &Arc<Stdout>);
|
fn show(&self, screen_manager: &Arc<TerminalOutput>);
|
||||||
/// Enable or disable the blinking of the cursor.
|
/// Enable or disable the blinking of the cursor.
|
||||||
fn blink(&self, blink: bool, screen_manager: &Arc<Stdout>);
|
fn blink(&self, blink: bool, screen_manager: &Arc<TerminalOutput>);
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,10 @@
|
|||||||
//! This module is used for windows terminals that do not support ANSI escape codes.
|
//! 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 ect.
|
//! Note that the cursor position is 0 based. This means that we start counting at 0 when setting the cursor position ect.
|
||||||
|
|
||||||
use super::super::super::write::{Stdout, WinApiStdout};
|
use super::super::super::output::WinApiOutput;
|
||||||
use super::ITerminalCursor;
|
|
||||||
|
|
||||||
use kernel::windows_kernel::{cursor, kernel};
|
use kernel::windows_kernel::{cursor, kernel};
|
||||||
|
|
||||||
use std::sync::Arc;
|
use super::*;
|
||||||
|
|
||||||
|
|
||||||
/// 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;
|
||||||
@ -20,48 +17,48 @@ impl WinApiCursor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ITerminalCursor for WinApiCursor {
|
impl ITerminalCursor for WinApiCursor {
|
||||||
fn goto(&self, x: u16, y: u16, screen_manager: &Arc<Stdout>) {
|
fn goto(&self, x: u16, y: u16, screen_manager: &Arc<TerminalOutput>) {
|
||||||
cursor::set_console_cursor_position(x as i16, y as i16, screen_manager);
|
cursor::set_console_cursor_position(x as i16, y as i16, screen_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pos(&self, screen_manager: &Arc<Stdout>) -> (u16, u16) {
|
fn pos(&self, screen_manager: &Arc<TerminalOutput>) -> (u16, u16) {
|
||||||
cursor::pos(screen_manager)
|
cursor::pos(screen_manager)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_up(&self, count: u16, screen_manager: &Arc<Stdout>) {
|
fn move_up(&self, count: u16, screen_manager: &Arc<TerminalOutput>) {
|
||||||
let (xpos, ypos) = self.pos(screen_manager);
|
let (xpos, ypos) = self.pos(screen_manager);
|
||||||
self.goto(xpos, ypos - count, screen_manager);
|
self.goto(xpos, ypos - count, screen_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_right(&self, count: u16, screen_manager: &Arc<Stdout>) {
|
fn move_right(&self, count: u16, screen_manager: &Arc<TerminalOutput>) {
|
||||||
let (xpos, ypos) = self.pos(screen_manager);
|
let (xpos, ypos) = self.pos(screen_manager);
|
||||||
self.goto(xpos + count, ypos, screen_manager);
|
self.goto(xpos + count, ypos, screen_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_down(&self, count: u16, screen_manager: &Arc<Stdout>) {
|
fn move_down(&self, count: u16, screen_manager: &Arc<TerminalOutput>) {
|
||||||
let (xpos, ypos) = self.pos(screen_manager);
|
let (xpos, ypos) = self.pos(screen_manager);
|
||||||
self.goto(xpos, ypos + count, screen_manager);
|
self.goto(xpos, ypos + count, screen_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_left(&self, count: u16, screen_manager: &Arc<Stdout>) {
|
fn move_left(&self, count: u16, screen_manager: &Arc<TerminalOutput>) {
|
||||||
let (xpos, ypos) = self.pos(screen_manager);
|
let (xpos, ypos) = self.pos(screen_manager);
|
||||||
self.goto(xpos - count, ypos, screen_manager);
|
self.goto(xpos - count, ypos, screen_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_position(&self, screen_manager: &Arc<Stdout>) {
|
fn save_position(&self, screen_manager: &Arc<TerminalOutput>) {
|
||||||
cursor::save_cursor_pos(screen_manager);
|
cursor::save_cursor_pos(screen_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reset_position(&self, screen_manager: &Arc<Stdout>) {
|
fn reset_position(&self, screen_manager: &Arc<TerminalOutput>) {
|
||||||
cursor::reset_to_saved_position(screen_manager);
|
cursor::reset_to_saved_position(screen_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hide(&self, screen_manager: &Arc<Stdout>) {
|
fn hide(&self, screen_manager: &Arc<TerminalOutput>) {
|
||||||
cursor::cursor_visibility(false, screen_manager);
|
cursor::cursor_visibility(false, screen_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show(&self, screen_manager: &Arc<Stdout>) {
|
fn show(&self, screen_manager: &Arc<TerminalOutput>) {
|
||||||
cursor::cursor_visibility(true, screen_manager);
|
cursor::cursor_visibility(true, screen_manager);
|
||||||
}
|
}
|
||||||
fn blink(&self, blink: bool, screen_manager: &Arc<Stdout>) {}
|
fn blink(&self, blink: bool, screen_manager: &Arc<TerminalOutput>) {}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
//! With this module you can perform actions that are input related.
|
//! With this module you can perform actions that are input related.
|
||||||
//! Like reading a line, reading a character and reading asynchronously.
|
//! Like reading a line, reading a character and reading asynchronously.
|
||||||
|
|
||||||
use std::io;
|
|
||||||
use std::sync::Arc;
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use Screen;
|
||||||
|
|
||||||
/// Struct that stores an specific platform implementation for input related actions.
|
/// Struct that stores an specific platform implementation for input related actions.
|
||||||
///
|
///
|
||||||
@ -22,12 +21,12 @@ use super::*;
|
|||||||
/// ```
|
/// ```
|
||||||
pub struct TerminalInput<'stdout> {
|
pub struct TerminalInput<'stdout> {
|
||||||
terminal_input: Box<ITerminalInput>,
|
terminal_input: Box<ITerminalInput>,
|
||||||
stdout: &'stdout Arc<Stdout>,
|
stdout: &'stdout Arc<TerminalOutput>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'stdout> TerminalInput<'stdout> {
|
impl<'stdout> TerminalInput<'stdout> {
|
||||||
/// Create new instance of TerminalInput whereon input related actions could be preformed.
|
/// Create new instance of TerminalInput whereon input related actions could be preformed.
|
||||||
pub fn new(stdout: &'stdout Arc<Stdout>) -> TerminalInput<'stdout> {
|
pub fn new(stdout: &'stdout Arc<TerminalOutput>) -> TerminalInput<'stdout> {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let input = Box::from(WindowsInput::new());
|
let input = Box::from(WindowsInput::new());
|
||||||
|
|
||||||
|
@ -14,11 +14,11 @@ use self::unix_input::UnixInput;
|
|||||||
use self::windows_input::WindowsInput;
|
use self::windows_input::WindowsInput;
|
||||||
|
|
||||||
pub use self::input::{input, TerminalInput};
|
pub use self::input::{input, TerminalInput};
|
||||||
use super::Stdout;
|
|
||||||
|
|
||||||
use std::io::{self, Read, Error, ErrorKind};
|
use std::io::{self, Read, Error, ErrorKind};
|
||||||
use std::sync::{mpsc, Arc};
|
use std::sync::{mpsc, Arc};
|
||||||
use Screen;
|
|
||||||
|
use TerminalOutput;
|
||||||
|
|
||||||
/// This trait defines the actions that can be preformed with the terminal color.
|
/// This trait defines the actions that can be preformed with the terminal color.
|
||||||
/// This trait can be implemented so that an concrete implementation of the ITerminalColor can forfill
|
/// This trait can be implemented so that an concrete implementation of the ITerminalColor can forfill
|
||||||
@ -30,13 +30,13 @@ use Screen;
|
|||||||
/// Unix is using the tty and windows is using libc C functions to read the input.
|
/// Unix is using the tty and windows is using libc C functions to read the input.
|
||||||
trait ITerminalInput {
|
trait ITerminalInput {
|
||||||
/// Read one line from the user input
|
/// Read one line from the user input
|
||||||
fn read_line(&self, screen_manger: &Arc<Stdout>) -> io::Result<String>;
|
fn read_line(&self, screen_manger: &Arc<TerminalOutput>) -> io::Result<String>;
|
||||||
/// Read one character from the user input
|
/// Read one character from the user input
|
||||||
fn read_char(&self, screen_manger: &Arc<Stdout>) -> io::Result<char>;
|
fn read_char(&self, screen_manger: &Arc<TerminalOutput>) -> io::Result<char>;
|
||||||
/// Read the input asynchronously from the user.
|
/// Read the input asynchronously from the user.
|
||||||
fn read_async(&self, screen_manger: &Arc<Stdout>) -> AsyncReader;
|
fn read_async(&self, screen_manger: &Arc<TerminalOutput>) -> AsyncReader;
|
||||||
/// Read the input asynchronously until a certain character is hit.
|
/// Read the input asynchronously until a certain character is hit.
|
||||||
fn read_until_async(&self, delimiter: u8, screen_manger: &Arc<Stdout>) -> AsyncReader;
|
fn read_until_async(&self, delimiter: u8, screen_manger: &Arc<TerminalOutput>) -> AsyncReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is a wrapper for reading from the input asynchronously.
|
/// This is a wrapper for reading from the input asynchronously.
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
//! This is an UNIX specific implementation for input related action.
|
//! This is an UNIX specific implementation for input related action.
|
||||||
|
|
||||||
use std::char;
|
use super::*;
|
||||||
use std::io::{self, Read, Write};
|
|
||||||
use std::sync::{mpsc, Arc};
|
|
||||||
use std::thread;
|
|
||||||
|
|
||||||
use super::{AsyncReader, ITerminalInput, Stdout};
|
|
||||||
use kernel::unix_kernel::terminal::{get_tty, read_char};
|
use kernel::unix_kernel::terminal::{get_tty, read_char};
|
||||||
|
|
||||||
|
use std::char;
|
||||||
|
use std::thread;
|
||||||
|
|
||||||
pub struct UnixInput;
|
pub struct UnixInput;
|
||||||
|
|
||||||
impl UnixInput {
|
impl UnixInput {
|
||||||
@ -17,7 +15,7 @@ impl UnixInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ITerminalInput for UnixInput {
|
impl ITerminalInput for UnixInput {
|
||||||
fn read_line(&self, screen_manger: &Arc<Stdout>) -> io::Result<String> {
|
fn read_line(&self, screen_manger: &Arc<TerminalOutput>) -> io::Result<String> {
|
||||||
let mut rv = String::new();
|
let mut rv = String::new();
|
||||||
io::stdin().read_line(&mut rv)?;
|
io::stdin().read_line(&mut rv)?;
|
||||||
let len = rv.trim_right_matches(&['\r', '\n'][..]).len();
|
let len = rv.trim_right_matches(&['\r', '\n'][..]).len();
|
||||||
@ -25,11 +23,11 @@ impl ITerminalInput for UnixInput {
|
|||||||
Ok(rv)
|
Ok(rv)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_char(&self, screen_manger: &Arc<Stdout>) -> io::Result<char> {
|
fn read_char(&self, screen_manger: &Arc<TerminalOutput>) -> io::Result<char> {
|
||||||
read_char()
|
read_char()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_async(&self, screen_manger: &Arc<Stdout>) -> AsyncReader {
|
fn read_async(&self, screen_manger: &Arc<TerminalOutput>) -> AsyncReader {
|
||||||
let (send, recv) = mpsc::channel();
|
let (send, recv) = mpsc::channel();
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
@ -43,7 +41,7 @@ impl ITerminalInput for UnixInput {
|
|||||||
AsyncReader { recv: recv }
|
AsyncReader { recv: recv }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_until_async(&self, delimiter: u8, screen_manger: &Arc<Stdout>) -> AsyncReader {
|
fn read_until_async(&self, delimiter: u8, screen_manger: &Arc<TerminalOutput>) -> AsyncReader {
|
||||||
let (send, recv) = mpsc::channel();
|
let (send, recv) = mpsc::channel();
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
//! This is an WINDOWS specific implementation for input related action.
|
//! This is an WINDOWS specific implementation for input related action.
|
||||||
|
|
||||||
use std::char;
|
use super::*;
|
||||||
use std::io::{self, Write};
|
|
||||||
use std::sync::{mpsc, Arc};
|
|
||||||
use std::thread;
|
|
||||||
|
|
||||||
use super::{AsyncReader, ITerminalInput, Stdout};
|
|
||||||
|
|
||||||
use winapi::um::winnt::INT;
|
use winapi::um::winnt::INT;
|
||||||
use winapi::um::winuser;
|
use winapi::um::winuser;
|
||||||
|
|
||||||
|
use std::char;
|
||||||
|
use std::thread;
|
||||||
|
|
||||||
pub struct WindowsInput;
|
pub struct WindowsInput;
|
||||||
|
|
||||||
impl WindowsInput {
|
impl WindowsInput {
|
||||||
@ -19,7 +17,7 @@ impl WindowsInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ITerminalInput for WindowsInput {
|
impl ITerminalInput for WindowsInput {
|
||||||
fn read_line(&self, screen_manger: &Arc<Stdout>) -> io::Result<String> {
|
fn read_line(&self, screen_manger: &Arc<TerminalOutput>) -> io::Result<String> {
|
||||||
let mut chars: Vec<char> = Vec::new();
|
let mut chars: Vec<char> = Vec::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
@ -52,7 +50,7 @@ impl ITerminalInput for WindowsInput {
|
|||||||
return Ok(chars.into_iter().collect());
|
return Ok(chars.into_iter().collect());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_char(&self, screen_manger: &Arc<Stdout>) -> io::Result<char> {
|
fn read_char(&self, screen_manger: &Arc<TerminalOutput>) -> io::Result<char> {
|
||||||
let is_raw_screen = screen_manger.is_in_raw_mode;
|
let is_raw_screen = screen_manger.is_in_raw_mode;
|
||||||
|
|
||||||
// _getwch is without echo and _getwche is with echo
|
// _getwch is without echo and _getwche is with echo
|
||||||
@ -83,7 +81,7 @@ impl ITerminalInput for WindowsInput {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_async(&self, screen_manger: &Arc<Stdout>) -> AsyncReader {
|
fn read_async(&self, screen_manger: &Arc<TerminalOutput>) -> AsyncReader {
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
|
|
||||||
let is_raw_screen = screen_manger.is_in_raw_mode;
|
let is_raw_screen = screen_manger.is_in_raw_mode;
|
||||||
@ -115,7 +113,7 @@ impl ITerminalInput for WindowsInput {
|
|||||||
AsyncReader { recv: rx }
|
AsyncReader { recv: rx }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_until_async(&self, delimiter: u8, screen_manger: &Arc<Stdout>) -> AsyncReader {
|
fn read_until_async(&self, delimiter: u8, screen_manger: &Arc<TerminalOutput>) -> AsyncReader {
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
|
|
||||||
let is_raw_screen = screen_manger.is_in_raw_mode;
|
let is_raw_screen = screen_manger.is_in_raw_mode;
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
pub mod cursor;
|
pub mod cursor;
|
||||||
pub mod input;
|
pub mod input;
|
||||||
pub mod write;
|
pub mod output;
|
||||||
pub mod style;
|
pub mod style;
|
||||||
//pub mod handle;
|
pub mod terminal;
|
||||||
pub mod terminal;
|
|
||||||
|
|
||||||
use super::common::commands;
|
use super::common::commands;
|
||||||
use super::common::functions;
|
use super::common::functions;
|
||||||
use super::common::traits;
|
use super::common::traits;
|
||||||
pub use self::write::{Stdout, IStdout};
|
|
||||||
pub use super::common::Screen;
|
|
@ -44,8 +44,8 @@ impl TerminalOutput {
|
|||||||
pub fn new(is_in_raw_mode: bool) -> Self {
|
pub fn new(is_in_raw_mode: bool) -> Self {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let stdout: Box<IStdout + Send + Sync> = functions::get_module::<Box<IStdout + Send + Sync>>(
|
let stdout: Box<IStdout + Send + Sync> = functions::get_module::<Box<IStdout + Send + Sync>>(
|
||||||
Box::from(WinApiStdout::new()),
|
Box::from(WinApiOutput::new()),
|
||||||
Box::from(AnsiStdout::new()),
|
Box::from(AnsiOutput::new()),
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
@ -88,8 +88,8 @@ impl Default for TerminalOutput
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let stdout = functions::get_module::<Box<IStdout + Send + Sync>>(
|
let stdout = functions::get_module::<Box<IStdout + Send + Sync>>(
|
||||||
Box::from(WinApiStdout::new()),
|
Box::from(WinApiOutput::new()),
|
||||||
Box::from(AnsiStdout::new()),
|
Box::from(AnsiOutput::new()),
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! This is an ANSI specific implementation for styling related action.
|
//! This is an ANSI specific implementation for styling related action.
|
||||||
//! This module is used for windows 10 terminals and unix terminals by default.
|
//! This module is used for windows 10 terminals and unix terminals by default.
|
||||||
use std::sync::Arc;
|
|
||||||
use super::{Color, ColorType, ITerminalColor, Stdout};
|
use super::*;
|
||||||
|
|
||||||
/// This struct is an ANSI escape code implementation for color related actions.
|
/// This struct is an ANSI escape code implementation for color related actions.
|
||||||
pub struct AnsiColor;
|
pub struct AnsiColor;
|
||||||
@ -13,21 +13,21 @@ impl AnsiColor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ITerminalColor for AnsiColor {
|
impl ITerminalColor for AnsiColor {
|
||||||
fn set_fg(&self, fg_color: Color, stdout: &Arc<Stdout>) {
|
fn set_fg(&self, fg_color: Color, stdout: &Arc<TerminalOutput>) {
|
||||||
stdout.write_string(format!(
|
stdout.write_string(format!(
|
||||||
csi!("{}m"),
|
csi!("{}m"),
|
||||||
self.color_value(fg_color, ColorType::Foreground)
|
self.color_value(fg_color, ColorType::Foreground)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_bg(&self, bg_color: Color, stdout: &Arc<Stdout>) {
|
fn set_bg(&self, bg_color: Color, stdout: &Arc<TerminalOutput>) {
|
||||||
stdout.write_string(format!(
|
stdout.write_string(format!(
|
||||||
csi!("{}m"),
|
csi!("{}m"),
|
||||||
self.color_value(bg_color, ColorType::Background)
|
self.color_value(bg_color, ColorType::Background)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reset(&self, stdout: &Arc<Stdout>) {
|
fn reset(&self, stdout: &Arc<TerminalOutput>) {
|
||||||
stdout.write_str(csi!("0m"));
|
stdout.write_str(csi!("0m"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,12 +25,12 @@ use Screen;
|
|||||||
/// ```
|
/// ```
|
||||||
pub struct TerminalColor<'stdout> {
|
pub struct TerminalColor<'stdout> {
|
||||||
color: Box<ITerminalColor>,
|
color: Box<ITerminalColor>,
|
||||||
stdout: &'stdout Arc<Stdout>,
|
stdout: &'stdout Arc<TerminalOutput>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'stdout> TerminalColor<'stdout> {
|
impl<'stdout> TerminalColor<'stdout> {
|
||||||
/// Create new instance whereon color related actions can be performed.
|
/// Create new instance whereon color related actions can be performed.
|
||||||
pub fn new(stdout: &'stdout Arc<Stdout>) -> TerminalColor<'stdout> {
|
pub fn new(stdout: &'stdout Arc<TerminalOutput>) -> TerminalColor<'stdout> {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let color = functions::get_module::<Box<ITerminalColor>>(
|
let color = functions::get_module::<Box<ITerminalColor>>(
|
||||||
Box::from(WinApiColor::new()),
|
Box::from(WinApiColor::new()),
|
||||||
|
@ -20,7 +20,8 @@ use std::fmt::Display;
|
|||||||
pub use self::color::{TerminalColor, color};
|
pub use self::color::{TerminalColor, color};
|
||||||
pub use self::objectstyle::ObjectStyle;
|
pub use self::objectstyle::ObjectStyle;
|
||||||
pub use self::styledobject::StyledObject;
|
pub use self::styledobject::StyledObject;
|
||||||
use super::{functions, Stdout};
|
use super::functions;
|
||||||
|
use TerminalOutput;
|
||||||
|
|
||||||
/// This trait defines the actions that can be preformed with the terminal color.
|
/// This trait defines the actions that can be preformed with the terminal color.
|
||||||
/// This trait can be implemented so that an concrete implementation of the ITerminalColor can forfill
|
/// This trait can be implemented so that an concrete implementation of the ITerminalColor can forfill
|
||||||
@ -32,11 +33,11 @@ use super::{functions, Stdout};
|
|||||||
/// 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.
|
||||||
trait ITerminalColor {
|
trait ITerminalColor {
|
||||||
/// Set the foreground color to the given color.
|
/// Set the foreground color to the given color.
|
||||||
fn set_fg(&self, fg_color: Color, stdout: &Arc<Stdout>);
|
fn set_fg(&self, fg_color: Color, stdout: &Arc<TerminalOutput>);
|
||||||
/// Set the background color to the given color.
|
/// Set the background color to the given color.
|
||||||
fn set_bg(&self, fg_color: Color, stdout: &Arc<Stdout>);
|
fn set_bg(&self, fg_color: Color, stdout: &Arc<TerminalOutput>);
|
||||||
/// Reset the terminal color to default.
|
/// Reset the terminal color to default.
|
||||||
fn reset(&self, stdout: &Arc<Stdout>);
|
fn reset(&self, stdout: &Arc<TerminalOutput>);
|
||||||
/// Gets an value that represents an color from the given `Color` and `ColorType`.
|
/// Gets an value that represents an color from the given `Color` and `ColorType`.
|
||||||
fn color_value(&self, color: Color, color_type: ColorType) -> String;
|
fn color_value(&self, color: Color, color_type: ColorType) -> String;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! This module contains the `object style` that can be applied to an `styled object`.
|
//! This module contains the `object style` that can be applied to an `styled object`.
|
||||||
|
|
||||||
use super::{Color, Stdout, StyledObject};
|
use super::{Color, TerminalOutput, StyledObject};
|
||||||
|
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! This module contains the logic to style an object that contains some state witch can be styled.
|
//! This module contains the logic to style an object that contains some state witch can be styled.
|
||||||
|
|
||||||
use super::{Color, ObjectStyle, Stdout};
|
use super::{Color, ObjectStyle, TerminalOutput};
|
||||||
use Screen;
|
use Screen;
|
||||||
|
|
||||||
use std::fmt::{self, Display};
|
use std::fmt::{self, Display};
|
||||||
@ -10,7 +10,7 @@ use std::io::Write;
|
|||||||
use super::Attribute;
|
use super::Attribute;
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use super::super::super::write::WinApiStdout;
|
use super::super::super::output::WinApiOutput;
|
||||||
|
|
||||||
/// Struct that contains both the style and the content wits can be styled.
|
/// Struct that contains both the style and the content wits can be styled.
|
||||||
pub struct StyledObject<D: Display> {
|
pub struct StyledObject<D: Display> {
|
||||||
|
@ -3,13 +3,10 @@
|
|||||||
//!
|
//!
|
||||||
//! Windows versions lower then windows 10 are not supporting ANSI codes. Those versions will use this implementation instead.
|
//! Windows versions lower then windows 10 are not supporting ANSI codes. Those versions will use this implementation instead.
|
||||||
|
|
||||||
use super::super::super::write::WinApiStdout;
|
use super::*;
|
||||||
use super::{Color, ColorType, ITerminalColor, Stdout};
|
|
||||||
use kernel::windows_kernel::{csbi, kernel};
|
use kernel::windows_kernel::{csbi, kernel};
|
||||||
use winapi::um::wincon;
|
use winapi::um::wincon;
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
/// This struct is an windows implementation for color related actions.
|
/// This struct is an windows implementation for color related actions.
|
||||||
pub struct WinApiColor
|
pub struct WinApiColor
|
||||||
{
|
{
|
||||||
@ -23,7 +20,7 @@ impl WinApiColor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ITerminalColor for WinApiColor {
|
impl ITerminalColor for WinApiColor {
|
||||||
fn set_fg(&self, fg_color: Color, stdout: &Arc<Stdout>) {
|
fn set_fg(&self, fg_color: Color, stdout: &Arc<TerminalOutput>) {
|
||||||
let color_value = &self.color_value(fg_color, ColorType::Foreground);
|
let color_value = &self.color_value(fg_color, ColorType::Foreground);
|
||||||
|
|
||||||
let csbi = csbi::get_csbi(stdout).unwrap();
|
let csbi = csbi::get_csbi(stdout).unwrap();
|
||||||
@ -44,7 +41,7 @@ impl ITerminalColor for WinApiColor {
|
|||||||
kernel::set_console_text_attribute(color, stdout);
|
kernel::set_console_text_attribute(color, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_bg(&self, bg_color: Color, stdout: &Arc<Stdout>) {
|
fn set_bg(&self, bg_color: Color, stdout: &Arc<TerminalOutput>) {
|
||||||
let color_value = &self.color_value(bg_color, ColorType::Background);
|
let color_value = &self.color_value(bg_color, ColorType::Background);
|
||||||
|
|
||||||
let (csbi, handle) = csbi::get_csbi_and_handle(stdout).unwrap();
|
let (csbi, handle) = csbi::get_csbi_and_handle(stdout).unwrap();
|
||||||
@ -65,7 +62,7 @@ impl ITerminalColor for WinApiColor {
|
|||||||
kernel::set_console_text_attribute(color, stdout);
|
kernel::set_console_text_attribute(color, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reset(&self, stdout: &Arc<Stdout>) {
|
fn reset(&self, stdout: &Arc<TerminalOutput>) {
|
||||||
kernel::set_console_text_attribute(self.original_color, stdout);
|
kernel::set_console_text_attribute(self.original_color, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! This is an `ANSI escape code` specific implementation for terminal related action.
|
//! This is an `ANSI escape code` specific implementation for terminal related action.
|
||||||
//! This module is used for windows 10 terminals and unix terminals by default.
|
//! This module is used for windows 10 terminals and unix terminals by default.
|
||||||
|
|
||||||
use super::super::cursor::cursor;
|
use cursor::cursor;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// This struct is an ansi escape code implementation for terminal related actions.
|
/// This struct is an ansi escape code implementation for terminal related actions.
|
||||||
@ -14,45 +14,45 @@ impl AnsiTerminal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ITerminal for AnsiTerminal {
|
impl ITerminal for AnsiTerminal {
|
||||||
fn clear(&self, clear_type: ClearType, screen_manager: &Arc<Stdout>) {
|
fn clear(&self, clear_type: ClearType, stdout: &Arc<TerminalOutput>) {
|
||||||
match clear_type {
|
match clear_type {
|
||||||
ClearType::All => {
|
ClearType::All => {
|
||||||
screen_manager.write_str(csi!("2J"));
|
stdout.write_str(csi!("2J"));
|
||||||
}
|
}
|
||||||
ClearType::FromCursorDown => {
|
ClearType::FromCursorDown => {
|
||||||
screen_manager.write_str(csi!("J"));
|
stdout.write_str(csi!("J"));
|
||||||
}
|
}
|
||||||
ClearType::FromCursorUp => {
|
ClearType::FromCursorUp => {
|
||||||
screen_manager.write_str(csi!("1J"));
|
stdout.write_str(csi!("1J"));
|
||||||
}
|
}
|
||||||
ClearType::CurrentLine => {
|
ClearType::CurrentLine => {
|
||||||
screen_manager.write_str(csi!("2K"));
|
stdout.write_str(csi!("2K"));
|
||||||
}
|
}
|
||||||
ClearType::UntilNewLine => {
|
ClearType::UntilNewLine => {
|
||||||
screen_manager.write_str(csi!("K"));
|
stdout.write_str(csi!("K"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn terminal_size(&self, screen_manager: &Arc<Stdout>) -> (u16, u16) {
|
fn terminal_size(&self, stdout: &Arc<TerminalOutput>) -> (u16, u16) {
|
||||||
functions::get_terminal_size()
|
functions::get_terminal_size()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scroll_up(&self, count: i16, screen_manager: &Arc<Stdout>) {
|
fn scroll_up(&self, count: i16, stdout: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_string(format!(csi!("{}S"), count));
|
stdout.write_string(format!(csi!("{}S"), count));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scroll_down(&self, count: i16, screen_manager: &Arc<Stdout>) {
|
fn scroll_down(&self, count: i16, stdout: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_string(format!(csi!("{}T"), count));
|
stdout.write_string(format!(csi!("{}T"), count));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_size(&self, width: i16, height: i16, screen_manager: &Arc<Stdout>) {
|
fn set_size(&self, width: i16, height: i16, stdout: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_string(format!(csi!("8;{};{}t"), width, height));
|
stdout.write_string(format!(csi!("8;{};{}t"), width, height));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exit(&self,screen_manager: &Arc<Stdout>) {
|
fn exit(&self,stdout: &Arc<TerminalOutput>) {
|
||||||
// drop the screen with the current stdout. This will make sure when in raw mode this will be disabled first.
|
// drop the screen with the current stdout. This will make sure when in raw mode this will be disabled first.
|
||||||
let mut screen = Screen::from(screen_manager.clone());
|
let mut screen = Screen::from(stdout.clone());
|
||||||
drop(screen);
|
drop(screen);
|
||||||
functions::exit_terminal();
|
functions::exit_terminal();
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,10 @@ use self::ansi_terminal::AnsiTerminal;
|
|||||||
use self::winapi_terminal::WinApiTerminal;
|
use self::winapi_terminal::WinApiTerminal;
|
||||||
|
|
||||||
pub use self::terminal::{terminal, Terminal};
|
pub use self::terminal::{terminal, Terminal};
|
||||||
use super::{functions, Stdout};
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use Screen;
|
use super::functions;
|
||||||
|
use {Screen, TerminalOutput};
|
||||||
|
|
||||||
/// Enum that specifies a way of clearing.
|
/// Enum that specifies a way of clearing.
|
||||||
pub enum ClearType {
|
pub enum ClearType {
|
||||||
@ -34,15 +35,15 @@ pub enum ClearType {
|
|||||||
/// 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.
|
||||||
trait ITerminal {
|
trait ITerminal {
|
||||||
/// Clear the current cursor by specifying the clear type
|
/// Clear the current cursor by specifying the clear type
|
||||||
fn clear(&self, clear_type: ClearType, screen_manager: &Arc<Stdout>);
|
fn clear(&self, clear_type: ClearType, stdout: &Arc<TerminalOutput>);
|
||||||
/// Get the terminal size (x,y)
|
/// Get the terminal size (x,y)
|
||||||
fn terminal_size(&self, screen_manager: &Arc<Stdout>) -> (u16, u16);
|
fn terminal_size(&self, stdout: &Arc<TerminalOutput>) -> (u16, u16);
|
||||||
/// Scroll `n` lines up in the current terminal.
|
/// Scroll `n` lines up in the current terminal.
|
||||||
fn scroll_up(&self, count: i16, screen_manager: &Arc<Stdout>);
|
fn scroll_up(&self, count: i16, stdout: &Arc<TerminalOutput>);
|
||||||
/// Scroll `n` lines down in the current terminal.
|
/// Scroll `n` lines down in the current terminal.
|
||||||
fn scroll_down(&self, count: i16, screen_manager: &Arc<Stdout>);
|
fn scroll_down(&self, count: i16, stdout: &Arc<TerminalOutput>);
|
||||||
/// Resize terminal to the given width and height.
|
/// Resize terminal to the given width and height.
|
||||||
fn set_size(&self, width: i16, height: i16, screen_manager: &Arc<Stdout>);
|
fn set_size(&self, width: i16, height: i16, stdout: &Arc<TerminalOutput>);
|
||||||
/// Close the current terminal
|
/// Close the current terminal
|
||||||
fn exit(&self,screen_manager: &Arc<Stdout>);
|
fn exit(&self,stdout: &Arc<TerminalOutput>);
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,12 @@ use std::io::Write;
|
|||||||
/// ```
|
/// ```
|
||||||
pub struct Terminal<'stdout> {
|
pub struct Terminal<'stdout> {
|
||||||
terminal: Box<ITerminal>,
|
terminal: Box<ITerminal>,
|
||||||
screen: &'stdout Arc<Stdout>,
|
screen: &'stdout Arc<TerminalOutput>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'stdout> Terminal<'stdout> {
|
impl<'stdout> Terminal<'stdout> {
|
||||||
/// Create new terminal instance whereon terminal related actions can be performed.
|
/// Create new terminal instance whereon terminal related actions can be performed.
|
||||||
pub fn new(screen: &'stdout Arc<Stdout>) -> Terminal<'stdout> {
|
pub fn new(screen: &'stdout Arc<TerminalOutput>) -> Terminal<'stdout> {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let terminal = functions::get_module::<Box<ITerminal>>(
|
let terminal = functions::get_module::<Box<ITerminal>>(
|
||||||
Box::new(WinApiTerminal::new()),
|
Box::new(WinApiTerminal::new()),
|
||||||
|
@ -3,8 +3,9 @@
|
|||||||
//!
|
//!
|
||||||
//! Windows versions lower then windows 10 are not supporting ANSI codes. Those versions will use this implementation instead.
|
//! Windows versions lower then windows 10 are not supporting ANSI codes. Those versions will use this implementation instead.
|
||||||
|
|
||||||
use super::super::super::cursor::TerminalCursor;
|
use cursor::TerminalCursor;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use kernel::windows_kernel::{csbi, kernel, terminal, writing};
|
use kernel::windows_kernel::{csbi, kernel, terminal, writing};
|
||||||
use winapi::um::wincon::{CONSOLE_SCREEN_BUFFER_INFO, COORD, SMALL_RECT};
|
use winapi::um::wincon::{CONSOLE_SCREEN_BUFFER_INFO, COORD, SMALL_RECT};
|
||||||
|
|
||||||
@ -18,27 +19,27 @@ impl WinApiTerminal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ITerminal for WinApiTerminal {
|
impl ITerminal for WinApiTerminal {
|
||||||
fn clear(&self, clear_type: ClearType, screen_manager: &Arc<Stdout>) {
|
fn clear(&self, clear_type: ClearType, stdout: &Arc<TerminalOutput>) {
|
||||||
let csbi = csbi::get_csbi(screen_manager).unwrap();
|
let csbi = csbi::get_csbi(stdout).unwrap();
|
||||||
let pos = TerminalCursor::new(screen_manager).pos();
|
let pos = TerminalCursor::new(stdout).pos();
|
||||||
|
|
||||||
match clear_type {
|
match clear_type {
|
||||||
ClearType::All => {
|
ClearType::All => {
|
||||||
clear_entire_screen(csbi, screen_manager);
|
clear_entire_screen(csbi, stdout);
|
||||||
}
|
}
|
||||||
ClearType::FromCursorDown => clear_after_cursor(pos, csbi, screen_manager),
|
ClearType::FromCursorDown => clear_after_cursor(pos, csbi, stdout),
|
||||||
ClearType::FromCursorUp => clear_before_cursor(pos, csbi, screen_manager),
|
ClearType::FromCursorUp => clear_before_cursor(pos, csbi, stdout),
|
||||||
ClearType::CurrentLine => clear_current_line(pos, csbi, screen_manager),
|
ClearType::CurrentLine => clear_current_line(pos, csbi, stdout),
|
||||||
ClearType::UntilNewLine => clear_until_line(pos, csbi, screen_manager),
|
ClearType::UntilNewLine => clear_until_line(pos, csbi, stdout),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn terminal_size(&self, screen_manager: &Arc<Stdout>) -> (u16, u16) {
|
fn terminal_size(&self, stdout: &Arc<TerminalOutput>) -> (u16, u16) {
|
||||||
terminal::terminal_size()
|
terminal::terminal_size()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scroll_up(&self, count: i16, screen_manager: &Arc<Stdout>) {
|
fn scroll_up(&self, count: i16, stdout: &Arc<TerminalOutput>) {
|
||||||
let csbi = csbi::get_csbi(&screen_manager).unwrap();
|
let csbi = csbi::get_csbi(&stdout).unwrap();
|
||||||
|
|
||||||
// Set srctWindow to the current window size and location.
|
// Set srctWindow to the current window size and location.
|
||||||
let mut srct_window = csbi.srWindow;
|
let mut srct_window = csbi.srWindow;
|
||||||
@ -48,15 +49,15 @@ impl ITerminal for WinApiTerminal {
|
|||||||
srct_window.Top -= count; // move top down
|
srct_window.Top -= count; // move top down
|
||||||
srct_window.Bottom = count; // move bottom down
|
srct_window.Bottom = count; // move bottom down
|
||||||
|
|
||||||
let success = kernel::set_console_info(false, &mut srct_window, &screen_manager);
|
let success = kernel::set_console_info(false, &mut srct_window, &stdout);
|
||||||
if success {
|
if success {
|
||||||
panic!("Something went wrong when scrolling down");
|
panic!("Something went wrong when scrolling down");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scroll_down(&self, count: i16, screen_manager: &Arc<Stdout>) {
|
fn scroll_down(&self, count: i16, stdout: &Arc<TerminalOutput>) {
|
||||||
let csbi = csbi::get_csbi(&screen_manager).unwrap();
|
let csbi = csbi::get_csbi(&stdout).unwrap();
|
||||||
// Set srctWindow to the current window size and location.
|
// Set srctWindow to the current window size and location.
|
||||||
let mut srct_window = csbi.srWindow;
|
let mut srct_window = csbi.srWindow;
|
||||||
|
|
||||||
@ -68,7 +69,7 @@ impl ITerminal for WinApiTerminal {
|
|||||||
srct_window.Top += count; // move top down
|
srct_window.Top += count; // move top down
|
||||||
srct_window.Bottom += count; // move bottom down
|
srct_window.Bottom += count; // move bottom down
|
||||||
|
|
||||||
let success = kernel::set_console_info(true, &mut srct_window, &screen_manager);
|
let success = kernel::set_console_info(true, &mut srct_window, &stdout);
|
||||||
if success {
|
if success {
|
||||||
panic!("Something went wrong when scrolling down");
|
panic!("Something went wrong when scrolling down");
|
||||||
}
|
}
|
||||||
@ -76,7 +77,7 @@ impl ITerminal for WinApiTerminal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set the current terminal size
|
/// Set the current terminal size
|
||||||
fn set_size(&self, width: i16, height: i16, screen_manager: &Arc<Stdout>) {
|
fn set_size(&self, width: i16, height: i16, stdout: &Arc<TerminalOutput>) {
|
||||||
if width <= 0 {
|
if width <= 0 {
|
||||||
panic!("Cannot set the terminal width lower than 1");
|
panic!("Cannot set the terminal width lower than 1");
|
||||||
}
|
}
|
||||||
@ -86,7 +87,7 @@ impl ITerminal for WinApiTerminal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the position of the current console window
|
// Get the position of the current console window
|
||||||
let csbi = csbi::get_csbi(&screen_manager).unwrap();
|
let csbi = csbi::get_csbi(&stdout).unwrap();
|
||||||
let mut success = false;
|
let mut success = false;
|
||||||
|
|
||||||
// If the buffer is smaller than this new window size, resize the
|
// If the buffer is smaller than this new window size, resize the
|
||||||
@ -115,7 +116,7 @@ impl ITerminal for WinApiTerminal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if resize_buffer {
|
if resize_buffer {
|
||||||
success = csbi::set_console_screen_buffer_size(size, &screen_manager);
|
success = csbi::set_console_screen_buffer_size(size, &stdout);
|
||||||
|
|
||||||
if !success {
|
if !success {
|
||||||
panic!("Something went wrong when setting screen buffer size.");
|
panic!("Something went wrong when setting screen buffer size.");
|
||||||
@ -127,12 +128,12 @@ impl ITerminal for WinApiTerminal {
|
|||||||
fsr_window.Bottom = fsr_window.Top + height;
|
fsr_window.Bottom = fsr_window.Top + height;
|
||||||
fsr_window.Right = fsr_window.Left + width;
|
fsr_window.Right = fsr_window.Left + width;
|
||||||
|
|
||||||
let success = kernel::set_console_info(true, &fsr_window, &screen_manager);
|
let success = kernel::set_console_info(true, &fsr_window, &stdout);
|
||||||
|
|
||||||
if success {
|
if success {
|
||||||
// If we resized the buffer, un-resize it.
|
// If we resized the buffer, un-resize it.
|
||||||
if resize_buffer {
|
if resize_buffer {
|
||||||
csbi::set_console_screen_buffer_size(csbi.dwSize, &screen_manager);
|
csbi::set_console_screen_buffer_size(csbi.dwSize, &stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
let bounds = kernel::get_largest_console_window_size();
|
let bounds = kernel::get_largest_console_window_size();
|
||||||
@ -152,9 +153,9 @@ impl ITerminal for WinApiTerminal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exit(&self, screen_manager: &Arc<Stdout>) {
|
fn exit(&self, stdout: &Arc<TerminalOutput>) {
|
||||||
// drop the screen with the current stdout. This will make sure when in raw mode this will be disabled first.
|
// drop the screen with the current stdout. This will make sure when in raw mode this will be disabled first.
|
||||||
let mut screen = Screen::from(screen_manager.clone());
|
let mut screen = Screen::from(stdout.clone());
|
||||||
drop(screen);
|
drop(screen);
|
||||||
functions::exit_terminal();
|
functions::exit_terminal();
|
||||||
}
|
}
|
||||||
@ -163,7 +164,7 @@ impl ITerminal for WinApiTerminal {
|
|||||||
pub fn clear_after_cursor(
|
pub fn clear_after_cursor(
|
||||||
pos: (u16, u16),
|
pos: (u16, u16),
|
||||||
csbi: CONSOLE_SCREEN_BUFFER_INFO,
|
csbi: CONSOLE_SCREEN_BUFFER_INFO,
|
||||||
screen_manager: &Arc<Stdout>,
|
stdout: &Arc<TerminalOutput>,
|
||||||
) {
|
) {
|
||||||
let (mut x, mut y) = pos;
|
let (mut x, mut y) = pos;
|
||||||
|
|
||||||
@ -181,13 +182,13 @@ pub fn clear_after_cursor(
|
|||||||
// get sum cells before cursor
|
// get sum cells before cursor
|
||||||
let cells_to_write = csbi.dwSize.X as u32 * csbi.dwSize.Y as u32;
|
let cells_to_write = csbi.dwSize.X as u32 * csbi.dwSize.Y as u32;
|
||||||
|
|
||||||
clear(start_location, cells_to_write, screen_manager);
|
clear(start_location, cells_to_write, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_before_cursor(
|
pub fn clear_before_cursor(
|
||||||
pos: (u16, u16),
|
pos: (u16, u16),
|
||||||
csbi: CONSOLE_SCREEN_BUFFER_INFO,
|
csbi: CONSOLE_SCREEN_BUFFER_INFO,
|
||||||
screen_manager: &Arc<Stdout>,
|
stdout: &Arc<TerminalOutput>,
|
||||||
) {
|
) {
|
||||||
let (xpos, ypos) = pos;
|
let (xpos, ypos) = pos;
|
||||||
|
|
||||||
@ -204,10 +205,10 @@ pub fn clear_before_cursor(
|
|||||||
// get sum cells before cursor
|
// get sum cells before cursor
|
||||||
let cells_to_write = (csbi.dwSize.X as u32 * ypos as u32) + (xpos as u32 + 1);
|
let cells_to_write = (csbi.dwSize.X as u32 * ypos as u32) + (xpos as u32 + 1);
|
||||||
|
|
||||||
clear(start_location, cells_to_write, screen_manager);
|
clear(start_location, cells_to_write, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_entire_screen(csbi: CONSOLE_SCREEN_BUFFER_INFO, screen_manager: &Arc<Stdout>) {
|
pub fn clear_entire_screen(csbi: CONSOLE_SCREEN_BUFFER_INFO, stdout: &Arc<TerminalOutput>) {
|
||||||
// position x at start
|
// position x at start
|
||||||
let x = 0;
|
let x = 0;
|
||||||
// position y at start
|
// position y at start
|
||||||
@ -222,16 +223,16 @@ pub fn clear_entire_screen(csbi: CONSOLE_SCREEN_BUFFER_INFO, screen_manager: &Ar
|
|||||||
|
|
||||||
let cells_to_write = csbi.dwSize.X as u32 * csbi.dwSize.Y as u32;
|
let cells_to_write = csbi.dwSize.X as u32 * csbi.dwSize.Y as u32;
|
||||||
|
|
||||||
clear(start_location, cells_to_write, &screen_manager);
|
clear(start_location, cells_to_write, &stdout);
|
||||||
|
|
||||||
// put the cursor back at (0, 0)
|
// put the cursor back at (0, 0)
|
||||||
TerminalCursor::new(screen_manager).goto(0, 0);
|
TerminalCursor::new(stdout).goto(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_current_line(
|
pub fn clear_current_line(
|
||||||
pos: (u16, u16),
|
pos: (u16, u16),
|
||||||
csbi: CONSOLE_SCREEN_BUFFER_INFO,
|
csbi: CONSOLE_SCREEN_BUFFER_INFO,
|
||||||
screen_manager: &Arc<Stdout>,
|
stdout: &Arc<TerminalOutput>,
|
||||||
) {
|
) {
|
||||||
// position x at start
|
// position x at start
|
||||||
let x = 0;
|
let x = 0;
|
||||||
@ -247,16 +248,16 @@ pub fn clear_current_line(
|
|||||||
|
|
||||||
let cells_to_write = csbi.dwSize.X as u32;
|
let cells_to_write = csbi.dwSize.X as u32;
|
||||||
|
|
||||||
clear(start_location, cells_to_write, screen_manager);
|
clear(start_location, cells_to_write, stdout);
|
||||||
|
|
||||||
// put the cursor back at 1 cell on current row
|
// put the cursor back at 1 cell on current row
|
||||||
TerminalCursor::new(screen_manager).goto(0, y);
|
TerminalCursor::new(stdout).goto(0, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_until_line(
|
pub fn clear_until_line(
|
||||||
pos: (u16, u16),
|
pos: (u16, u16),
|
||||||
csbi: CONSOLE_SCREEN_BUFFER_INFO,
|
csbi: CONSOLE_SCREEN_BUFFER_INFO,
|
||||||
screen_manager: &Arc<Stdout>,
|
stdout: &Arc<TerminalOutput>,
|
||||||
) {
|
) {
|
||||||
let (x, y) = pos;
|
let (x, y) = pos;
|
||||||
|
|
||||||
@ -268,13 +269,13 @@ pub fn clear_until_line(
|
|||||||
// get sum cells before cursor
|
// get sum cells before cursor
|
||||||
let cells_to_write = (csbi.dwSize.X - x as i16) as u32;
|
let cells_to_write = (csbi.dwSize.X - x as i16) as u32;
|
||||||
|
|
||||||
clear(start_location, cells_to_write, &screen_manager);
|
clear(start_location, cells_to_write, &stdout);
|
||||||
|
|
||||||
// put the cursor back at original cursor position
|
// put the cursor back at original cursor position
|
||||||
TerminalCursor::new(screen_manager).goto(x, y);
|
TerminalCursor::new(stdout).goto(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear(start_loaction: COORD, cells_to_write: u32, screen_manager: &Arc<Stdout>) {
|
fn clear(start_loaction: COORD, cells_to_write: u32, stdout: &Arc<TerminalOutput>) {
|
||||||
let mut cells_written = 0;
|
let mut cells_written = 0;
|
||||||
let mut success = false;
|
let mut success = false;
|
||||||
|
|
||||||
@ -282,7 +283,7 @@ fn clear(start_loaction: COORD, cells_to_write: u32, screen_manager: &Arc<Stdout
|
|||||||
&mut cells_written,
|
&mut cells_written,
|
||||||
start_loaction,
|
start_loaction,
|
||||||
cells_to_write,
|
cells_to_write,
|
||||||
screen_manager,
|
stdout,
|
||||||
);
|
);
|
||||||
|
|
||||||
if !success {
|
if !success {
|
||||||
@ -295,7 +296,7 @@ fn clear(start_loaction: COORD, cells_to_write: u32, screen_manager: &Arc<Stdout
|
|||||||
&mut cells_written,
|
&mut cells_written,
|
||||||
start_loaction,
|
start_loaction,
|
||||||
cells_to_write,
|
cells_to_write,
|
||||||
screen_manager,
|
stdout,
|
||||||
);
|
);
|
||||||
|
|
||||||
if !success {
|
if !success {
|
||||||
|
Loading…
Reference in New Issue
Block a user