Shitload unused iports and unused mut removed alos renamed some variables
This commit is contained in:
parent
f64a405236
commit
a367169bb7
@ -2,10 +2,8 @@
|
|||||||
|
|
||||||
use super::super::output::TerminalOutput;
|
use super::super::output::TerminalOutput;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::sync::Mutex;
|
|
||||||
|
|
||||||
pub mod shared_commands;
|
pub mod shared_commands;
|
||||||
use common::screen::Screen;
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
pub mod unix_command;
|
pub mod unix_command;
|
||||||
@ -26,8 +24,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 TerminalOutput) -> io::Result<()>;
|
fn enable(&self, stdout: &mut TerminalOutput) -> io::Result<()>;
|
||||||
fn disable(&self, screen_manager: &TerminalOutput) -> io::Result<()>;
|
fn disable(&self, stdout: &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.
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
use super::{IAlternateScreenCommand, TerminalOutput};
|
use super::{IAlternateScreenCommand, TerminalOutput};
|
||||||
|
|
||||||
use std::sync::Mutex;
|
use std::io::{ Result};
|
||||||
use std::io::{ Result, stdout, Write};
|
|
||||||
|
|
||||||
/// This command is used for switching to alternate screen and back to main screen.
|
/// This command is used for switching to alternate screen and back to main screen.
|
||||||
pub struct ToAlternateScreenCommand;
|
pub struct ToAlternateScreenCommand;
|
||||||
@ -17,14 +16,14 @@ impl ToAlternateScreenCommand {
|
|||||||
impl IAlternateScreenCommand for ToAlternateScreenCommand {
|
impl IAlternateScreenCommand for ToAlternateScreenCommand {
|
||||||
|
|
||||||
/// enable alternate screen.
|
/// enable alternate screen.
|
||||||
fn enable(&self, screen_manager: &mut TerminalOutput) -> Result<()> {
|
fn enable(&self, stdout: &mut TerminalOutput) -> Result<()> {
|
||||||
screen_manager.write_str(csi!("?1049h"));
|
stdout.write_str(csi!("?1049h"));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// disable alternate screen.
|
/// disable alternate screen.
|
||||||
fn disable(&self, screen_manager: &TerminalOutput) -> Result<()> {
|
fn disable(&self, stdout: &TerminalOutput) -> Result<()> {
|
||||||
screen_manager.write_str(csi!("?1049l"));
|
stdout.write_str(csi!("?1049l"));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! This module contains the commands that can be used for unix systems.
|
//! This module contains the commands that can be used for unix systems.
|
||||||
|
|
||||||
use super::{ IStateCommand, IRawScreenCommand};
|
use super::{ IStateCommand};
|
||||||
use kernel::unix_kernel::terminal;
|
use kernel::unix_kernel::terminal;
|
||||||
use termios::{tcsetattr, Termios, CREAD, ECHO, ICANON, TCSAFLUSH};
|
use termios::{tcsetattr, Termios, CREAD, ECHO, ICANON, TCSAFLUSH};
|
||||||
|
|
||||||
@ -55,9 +55,3 @@ impl NoncanonicalModeCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This command is used for enabling and disabling raw mode for the terminal.
|
|
||||||
pub struct RawModeCommand {
|
|
||||||
original_mode: Result<Termios>,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,16 +1,13 @@
|
|||||||
//! 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, TerminalOutput};
|
use super::{IAlternateScreenCommand, IEnableAnsiCommand, TerminalOutput};
|
||||||
|
|
||||||
use kernel::windows_kernel::{ansi_support, csbi, handle, kernel};
|
use kernel::windows_kernel::{ansi_support, csbi, handle, kernel};
|
||||||
use modules::output::IStdout;
|
|
||||||
use std::mem;
|
|
||||||
use winapi::shared::minwindef::DWORD;
|
|
||||||
use winapi::um::wincon;
|
use winapi::um::wincon;
|
||||||
use winapi::um::wincon::{CHAR_INFO, COORD, ENABLE_VIRTUAL_TERMINAL_PROCESSING, SMALL_RECT};
|
use winapi::shared::minwindef::DWORD;
|
||||||
|
use winapi::um::wincon::{ENABLE_VIRTUAL_TERMINAL_PROCESSING};
|
||||||
|
|
||||||
use std::io::{Error, ErrorKind, Result};
|
use std::io::{Error, ErrorKind, Result};
|
||||||
use std::sync::Mutex;
|
|
||||||
|
|
||||||
/// This command is used for enabling and disabling ANSI code support for windows systems,
|
/// This command is used for enabling and disabling ANSI code support for windows systems,
|
||||||
/// For more info check: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences.
|
/// For more info check: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences.
|
||||||
@ -148,7 +145,7 @@ impl ToAlternateScreenCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl IAlternateScreenCommand for ToAlternateScreenCommand {
|
impl IAlternateScreenCommand for ToAlternateScreenCommand {
|
||||||
fn enable(&self, screen_manager: &mut TerminalOutput) -> Result<()> {
|
fn enable(&self, stdout: &mut TerminalOutput) -> Result<()> {
|
||||||
use super::super::super::modules::output::WinApiOutput;
|
use super::super::super::modules::output::WinApiOutput;
|
||||||
|
|
||||||
let handle = handle::get_output_handle()?;
|
let handle = handle::get_output_handle()?;
|
||||||
@ -159,7 +156,7 @@ 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 WinApiOutput = match screen_manager
|
let b: &mut WinApiOutput = match stdout
|
||||||
.as_any_mut()
|
.as_any_mut()
|
||||||
.downcast_mut::<WinApiOutput>()
|
.downcast_mut::<WinApiOutput>()
|
||||||
{
|
{
|
||||||
@ -172,7 +169,7 @@ impl IAlternateScreenCommand for ToAlternateScreenCommand {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disable(&self, screen_manager: &TerminalOutput) -> Result<()> {
|
fn disable(&self, stdout: &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);
|
||||||
|
|
||||||
|
@ -1,27 +1,13 @@
|
|||||||
use super::commands::{IAlternateScreenCommand};
|
use {Screen, TerminalOutput};
|
||||||
|
|
||||||
use super::screen::{AlternateScreen, Screen};
|
|
||||||
|
|
||||||
use super::super::cursor;
|
use super::super::cursor;
|
||||||
use super::super::input;
|
use super::super::input;
|
||||||
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::sync::RwLock;
|
|
||||||
use std::io::Result;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
use common::commands::unix_command;
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
use common::commands::win_commands;
|
|
||||||
|
|
||||||
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.
|
||||||
///
|
///
|
||||||
|
@ -7,7 +7,7 @@ use std::sync::Arc;
|
|||||||
use kernel::windows_kernel::ansi_support::{try_enable_ansi_support, windows_supportable};
|
use kernel::windows_kernel::ansi_support::{try_enable_ansi_support, windows_supportable};
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use kernel::windows_kernel::terminal::{buffer_size, exit, terminal_size};
|
use kernel::windows_kernel::terminal::{ exit, terminal_size};
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use kernel::windows_kernel::cursor::pos;
|
use kernel::windows_kernel::cursor::pos;
|
||||||
|
@ -7,11 +7,10 @@
|
|||||||
//! 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, TerminalOutput, RawScreen};
|
use super::{functions, Screen, TerminalOutput};
|
||||||
|
|
||||||
|
use std::io;
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
use std::io::{self, Write};
|
|
||||||
use std::sync::Mutex;
|
|
||||||
|
|
||||||
/// With this type you will be able to switch to alternate screen and back to main screen.
|
/// With this type you will be able to switch to alternate screen and back to main screen.
|
||||||
pub struct AlternateScreen
|
pub struct AlternateScreen
|
||||||
|
@ -15,9 +15,8 @@
|
|||||||
//! 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, TerminalOutput};
|
|
||||||
|
|
||||||
use std::io::{self, Write};
|
use std::io;
|
||||||
|
|
||||||
/// A wrapper for the raw terminal state. Which can be used to write to.
|
/// A wrapper for the raw terminal state. Which can be used to write to.
|
||||||
pub struct RawScreen;
|
pub struct RawScreen;
|
||||||
@ -39,9 +38,9 @@ impl RawScreen {
|
|||||||
pub fn disable_raw_modes() -> io::Result<()>
|
pub fn disable_raw_modes() -> io::Result<()>
|
||||||
{
|
{
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
let mut command = unix_command::NoncanonicalModeCommand::new();
|
let command = unix_command::NoncanonicalModeCommand::new();
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let mut command = win_commands::RawModeCommand::new();
|
let command = win_commands::RawModeCommand::new();
|
||||||
|
|
||||||
command.disable()?;
|
command.disable()?;
|
||||||
return Ok(())
|
return Ok(())
|
||||||
|
@ -1,11 +1,3 @@
|
|||||||
#[cfg(not(windows))]
|
|
||||||
use common::commands::unix_command;
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
use common::commands::win_commands;
|
|
||||||
|
|
||||||
use common::commands::IAlternateScreenCommand;
|
|
||||||
|
|
||||||
use super::{AlternateScreen,RawScreen};
|
use super::{AlternateScreen,RawScreen};
|
||||||
use TerminalOutput;
|
use TerminalOutput;
|
||||||
|
|
||||||
@ -98,7 +90,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 = TerminalOutput::new(raw_mode);
|
let stdout = TerminalOutput::new(raw_mode);
|
||||||
|
|
||||||
if raw_mode
|
if raw_mode
|
||||||
{
|
{
|
||||||
|
@ -13,7 +13,7 @@ use common::commands::IEnableAnsiCommand;
|
|||||||
/// Try enable `ANSI escape codes` and return the result.
|
/// Try enable `ANSI escape codes` and return the result.
|
||||||
pub fn try_enable_ansi_support() -> bool {
|
pub fn try_enable_ansi_support() -> bool {
|
||||||
ENABLE_ANSI.call_once(|| {
|
ENABLE_ANSI.call_once(|| {
|
||||||
let mut command = EnableAnsiCommand::new();
|
let command = EnableAnsiCommand::new();
|
||||||
let success = command.enable();
|
let success = command.enable();
|
||||||
|
|
||||||
set_is_windows_ansi_supportable(success);
|
set_is_windows_ansi_supportable(success);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! This contains the logic for working with the console buffer.
|
//! This contains the logic for working with the console buffer.
|
||||||
|
|
||||||
use winapi::shared::minwindef::{FALSE, TRUE};
|
use winapi::shared::minwindef::TRUE;
|
||||||
use winapi::shared::ntdef::NULL;
|
use winapi::shared::ntdef::NULL;
|
||||||
use winapi::um::minwinbase::SECURITY_ATTRIBUTES;
|
use winapi::um::minwinbase::SECURITY_ATTRIBUTES;
|
||||||
use winapi::um::wincon::{
|
use winapi::um::wincon::{
|
||||||
@ -12,18 +12,18 @@ use winapi::um::winnt::{FILE_SHARE_READ, FILE_SHARE_WRITE, GENERIC_READ, GENERIC
|
|||||||
|
|
||||||
use super::{handle, kernel, Empty, TerminalOutput, HANDLE};
|
use super::{handle, kernel, Empty, TerminalOutput, HANDLE};
|
||||||
|
|
||||||
use std::io::{self, ErrorKind, Result};
|
use std::io::{self, Result};
|
||||||
use std::sync::{Once, ONCE_INIT};
|
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<TerminalOutput>) -> Result<CONSOLE_SCREEN_BUFFER_INFO> {
|
pub fn get_csbi(stdout: &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;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
success = GetConsoleScreenBufferInfo(handle::get_current_handle(screen_manager)?, &mut csbi)
|
success = GetConsoleScreenBufferInfo(handle::get_current_handle(stdout)?, &mut csbi)
|
||||||
}
|
}
|
||||||
|
|
||||||
if success == 0 {
|
if success == 0 {
|
||||||
@ -38,9 +38,9 @@ pub fn get_csbi(screen_manager: &Arc<TerminalOutput>) -> Result<CONSOLE_SCREEN_B
|
|||||||
|
|
||||||
/// 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<TerminalOutput>,
|
stdout: &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(stdout)?;
|
||||||
let csbi = get_csbi_by_handle(&handle)?;
|
let csbi = get_csbi_by_handle(&handle)?;
|
||||||
|
|
||||||
return Ok((csbi, handle));
|
return Ok((csbi, handle));
|
||||||
@ -63,8 +63,8 @@ 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<TerminalOutput>) -> bool {
|
pub fn set_console_screen_buffer_size(size: COORD, stdout: &Arc<TerminalOutput>) -> bool {
|
||||||
let handle = handle::get_current_handle(screen_manager).unwrap();
|
let handle = handle::get_current_handle(stdout).unwrap();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
if !kernel::is_true(SetConsoleScreenBufferSize(handle, size)) {
|
if !kernel::is_true(SetConsoleScreenBufferSize(handle, size)) {
|
||||||
|
@ -5,7 +5,7 @@ use winapi::um::wincon::{
|
|||||||
SetConsoleCursorInfo, SetConsoleCursorPosition, CONSOLE_CURSOR_INFO, COORD,
|
SetConsoleCursorInfo, SetConsoleCursorPosition, CONSOLE_CURSOR_INFO, COORD,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{csbi, handle, kernel, TerminalOutput, WinApiOutput};
|
use super::{csbi, handle, kernel, TerminalOutput};
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -6,14 +6,13 @@ use winapi::um::winbase::{STD_INPUT_HANDLE, STD_OUTPUT_HANDLE};
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::io::{self, Result};
|
||||||
|
|
||||||
/// 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<TerminalOutput>) -> Result<HANDLE> {
|
pub fn get_current_handle(stdout: &Arc<TerminalOutput>) -> Result<HANDLE> {
|
||||||
let mut mutex = screen_manager;
|
|
||||||
|
|
||||||
let handle: Result<HANDLE>;
|
let handle: Result<HANDLE>;
|
||||||
|
|
||||||
let winapi_screen_manager: &WinApiOutput = match screen_manager
|
let winapi_stdout: &WinApiOutput = match stdout
|
||||||
.as_any()
|
.as_any()
|
||||||
.downcast_ref::<WinApiOutput>()
|
.downcast_ref::<WinApiOutput>()
|
||||||
{
|
{
|
||||||
@ -22,13 +21,11 @@ pub fn get_current_handle(screen_manager: &Arc<TerminalOutput>) -> Result<HANDLE
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
handle = Ok(winapi_screen_manager.get_handle());
|
handle = Ok(winapi_stdout.get_handle());
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
use std::io::{self, ErrorKind, Result};
|
|
||||||
|
|
||||||
/// Get the std_output_handle of the console
|
/// Get the std_output_handle of the console
|
||||||
pub fn get_output_handle() -> Result<HANDLE> {
|
pub fn get_output_handle() -> Result<HANDLE> {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -6,8 +6,6 @@ use winapi::um::wincon::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use std::io::{ErrorKind, Result};
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
/// Get the largest console window size possible.
|
/// Get the largest console window size possible.
|
||||||
|
@ -17,7 +17,7 @@ pub fn terminal_size() -> (u16, u16) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn buffer_size(screen_manager: &Arc<TerminalOutput>) -> (u16, u16) {
|
pub fn buffer_size(stdout: &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) {
|
||||||
|
@ -4,13 +4,13 @@ use winapi::ctypes::c_void;
|
|||||||
use winapi::shared::ntdef::NULL;
|
use winapi::shared::ntdef::NULL;
|
||||||
use winapi::um::consoleapi::WriteConsoleW;
|
use winapi::um::consoleapi::WriteConsoleW;
|
||||||
use winapi::um::wincon::{
|
use winapi::um::wincon::{
|
||||||
self, FillConsoleOutputAttribute, FillConsoleOutputCharacterA, WriteConsoleOutputA, CHAR_INFO,
|
FillConsoleOutputAttribute, FillConsoleOutputCharacterA, WriteConsoleOutputA, CHAR_INFO,
|
||||||
COORD, PSMALL_RECT,
|
COORD, PSMALL_RECT,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{csbi, handle, kernel, TerminalOutput, HANDLE};
|
use super::{csbi, handle, kernel, TerminalOutput, HANDLE};
|
||||||
|
|
||||||
use std::io::{self, ErrorKind, Result};
|
use std::io::{self, Result};
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@ -19,9 +19,9 @@ 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<TerminalOutput>,
|
stdout: &Arc<TerminalOutput>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let handle = handle::get_current_handle(screen_manager).unwrap();
|
let handle = handle::get_current_handle(stdout).unwrap();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
// fill the cells in console with blanks
|
// fill the cells in console with blanks
|
||||||
@ -41,11 +41,11 @@ 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<TerminalOutput>,
|
stdout: &Arc<TerminalOutput>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
// Get the position of the current console window
|
// Get the position of the current console window
|
||||||
|
|
||||||
let (csbi, mut handle) = csbi::get_csbi_and_handle(screen_manager).unwrap();
|
let (csbi, handle) = csbi::get_csbi_and_handle(stdout).unwrap();
|
||||||
|
|
||||||
let success;
|
let success;
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ pub fn write_console_output(
|
|||||||
/// Write utf8 buffer to console.
|
/// Write utf8 buffer to console.
|
||||||
pub fn write_char_buffer(handle: &HANDLE, buf: &[u8]) -> ::std::io::Result<usize> {
|
pub fn write_char_buffer(handle: &HANDLE, buf: &[u8]) -> ::std::io::Result<usize> {
|
||||||
// get string from u8[] and parse it to an c_str
|
// get string from u8[] and parse it to an c_str
|
||||||
let mut utf8 = match str::from_utf8(buf) {
|
let utf8 = match str::from_utf8(buf) {
|
||||||
Ok(string) => string,
|
Ok(string) => string,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
return Err(io::Error::new(
|
return Err(io::Error::new(
|
||||||
|
@ -27,39 +27,39 @@ impl ITerminalCursor for AnsiCursor {
|
|||||||
stdout.write_string(format!(csi!("{}A"), count));
|
stdout.write_string(format!(csi!("{}A"), count));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_right(&self, count: u16, screen_manager: &Arc<TerminalOutput>) {
|
fn move_right(&self, count: u16, stdout: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_string(format!(csi!("{}C"), count));
|
stdout.write_string(format!(csi!("{}C"), count));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_down(&self, count: u16, screen_manager: &Arc<TerminalOutput>) {
|
fn move_down(&self, count: u16, stdout: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_string(format!(csi!("{}B"), count));
|
stdout.write_string(format!(csi!("{}B"), count));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_left(&self, count: u16, screen_manager: &Arc<TerminalOutput>) {
|
fn move_left(&self, count: u16, stdout: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_string(format!(csi!("{}D"), count));
|
stdout.write_string(format!(csi!("{}D"), count));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_position(&self, screen_manager: &Arc<TerminalOutput>) {
|
fn save_position(&self, stdout: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_str(csi!("s"));
|
stdout.write_str(csi!("s"));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reset_position(&self, screen_manager: &Arc<TerminalOutput>) {
|
fn reset_position(&self, stdout: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_str(csi!("u"));
|
stdout.write_str(csi!("u"));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hide(&self, screen_manager: &Arc<TerminalOutput>) {
|
fn hide(&self, stdout: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_str(csi!("?25l"));
|
stdout.write_str(csi!("?25l"));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show(&self, screen_manager: &Arc<TerminalOutput>) {
|
fn show(&self, stdout: &Arc<TerminalOutput>) {
|
||||||
screen_manager.write_str(csi!("?25h"));
|
stdout.write_str(csi!("?25h"));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn blink(&self, blink: bool, screen_manager: &Arc<TerminalOutput>) {
|
fn blink(&self, blink: bool, stdout: &Arc<TerminalOutput>) {
|
||||||
if blink {
|
if blink {
|
||||||
screen_manager.write_str(csi!("?12h"));
|
stdout.write_str(csi!("?12h"));
|
||||||
} else {
|
} else {
|
||||||
screen_manager.write_str(csi!("?12l"));
|
stdout.write_str(csi!("?12l"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,6 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use Screen;
|
use Screen;
|
||||||
|
|
||||||
use std::fmt::Display;
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
/// 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.
|
||||||
|
@ -27,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<TerminalOutput>);
|
fn goto(&self, x: u16, y: u16, stdout: &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<TerminalOutput>) -> (u16, u16);
|
fn pos(&self, stdout: &Arc<TerminalOutput>) -> (u16, u16);
|
||||||
/// Move cursor n times up
|
/// Move cursor n times up
|
||||||
fn move_up(&self, count: u16, screen_manager: &Arc<TerminalOutput>);
|
fn move_up(&self, count: u16, stdout: &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<TerminalOutput>);
|
fn move_right(&self, count: u16, stdout: &Arc<TerminalOutput>);
|
||||||
/// Move the cursor `n` times down.
|
/// Move the cursor `n` times down.
|
||||||
fn move_down(&self, count: u16, screen_manager: &Arc<TerminalOutput>);
|
fn move_down(&self, count: u16, stdout: &Arc<TerminalOutput>);
|
||||||
/// Move the cursor `n` times left.
|
/// Move the cursor `n` times left.
|
||||||
fn move_left(&self, count: u16, screen_manager: &Arc<TerminalOutput>);
|
fn move_left(&self, count: u16, stdout: &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<TerminalOutput>);
|
fn save_position(&self, stdout: &Arc<TerminalOutput>);
|
||||||
/// Return to saved cursor position
|
/// Return to saved cursor position
|
||||||
fn reset_position(&self, screen_manager: &Arc<TerminalOutput>);
|
fn reset_position(&self, stdout: &Arc<TerminalOutput>);
|
||||||
/// Hide the terminal cursor.
|
/// Hide the terminal cursor.
|
||||||
fn hide(&self, screen_manager: &Arc<TerminalOutput>);
|
fn hide(&self, stdout: &Arc<TerminalOutput>);
|
||||||
/// Show the terminal cursor
|
/// Show the terminal cursor
|
||||||
fn show(&self, screen_manager: &Arc<TerminalOutput>);
|
fn show(&self, stdout: &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<TerminalOutput>);
|
fn blink(&self, blink: bool, stdout: &Arc<TerminalOutput>);
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
//! 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::output::WinApiOutput;
|
use kernel::windows_kernel::cursor;
|
||||||
use kernel::windows_kernel::{cursor, kernel};
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@ -17,48 +16,48 @@ impl WinApiCursor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ITerminalCursor for WinApiCursor {
|
impl ITerminalCursor for WinApiCursor {
|
||||||
fn goto(&self, x: u16, y: u16, screen_manager: &Arc<TerminalOutput>) {
|
fn goto(&self, x: u16, y: u16, stdout: &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, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pos(&self, screen_manager: &Arc<TerminalOutput>) -> (u16, u16) {
|
fn pos(&self, stdout: &Arc<TerminalOutput>) -> (u16, u16) {
|
||||||
cursor::pos(screen_manager)
|
cursor::pos(stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_up(&self, count: u16, screen_manager: &Arc<TerminalOutput>) {
|
fn move_up(&self, count: u16, stdout: &Arc<TerminalOutput>) {
|
||||||
let (xpos, ypos) = self.pos(screen_manager);
|
let (xpos, ypos) = self.pos(stdout);
|
||||||
self.goto(xpos, ypos - count, screen_manager);
|
self.goto(xpos, ypos - count, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_right(&self, count: u16, screen_manager: &Arc<TerminalOutput>) {
|
fn move_right(&self, count: u16, stdout: &Arc<TerminalOutput>) {
|
||||||
let (xpos, ypos) = self.pos(screen_manager);
|
let (xpos, ypos) = self.pos(stdout);
|
||||||
self.goto(xpos + count, ypos, screen_manager);
|
self.goto(xpos + count, ypos, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_down(&self, count: u16, screen_manager: &Arc<TerminalOutput>) {
|
fn move_down(&self, count: u16, stdout: &Arc<TerminalOutput>) {
|
||||||
let (xpos, ypos) = self.pos(screen_manager);
|
let (xpos, ypos) = self.pos(stdout);
|
||||||
self.goto(xpos, ypos + count, screen_manager);
|
self.goto(xpos, ypos + count, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_left(&self, count: u16, screen_manager: &Arc<TerminalOutput>) {
|
fn move_left(&self, count: u16, stdout: &Arc<TerminalOutput>) {
|
||||||
let (xpos, ypos) = self.pos(screen_manager);
|
let (xpos, ypos) = self.pos(stdout);
|
||||||
self.goto(xpos - count, ypos, screen_manager);
|
self.goto(xpos - count, ypos, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_position(&self, screen_manager: &Arc<TerminalOutput>) {
|
fn save_position(&self, stdout: &Arc<TerminalOutput>) {
|
||||||
cursor::save_cursor_pos(screen_manager);
|
cursor::save_cursor_pos(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reset_position(&self, screen_manager: &Arc<TerminalOutput>) {
|
fn reset_position(&self, stdout: &Arc<TerminalOutput>) {
|
||||||
cursor::reset_to_saved_position(screen_manager);
|
cursor::reset_to_saved_position(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hide(&self, screen_manager: &Arc<TerminalOutput>) {
|
fn hide(&self, stdout: &Arc<TerminalOutput>) {
|
||||||
cursor::cursor_visibility(false, screen_manager);
|
cursor::cursor_visibility(false, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show(&self, screen_manager: &Arc<TerminalOutput>) {
|
fn show(&self, stdout: &Arc<TerminalOutput>) {
|
||||||
cursor::cursor_visibility(true, screen_manager);
|
cursor::cursor_visibility(true, stdout);
|
||||||
}
|
}
|
||||||
fn blink(&self, blink: bool, screen_manager: &Arc<TerminalOutput>) {}
|
fn blink(&self, blink: bool, stdout: &Arc<TerminalOutput>) {}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use winapi::um::winnt::INT;
|
use winapi::um::winnt::INT;
|
||||||
use winapi::um::winuser;
|
|
||||||
|
|
||||||
use std::char;
|
use std::char;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
@ -129,7 +128,7 @@ impl ITerminalInput for WindowsInput {
|
|||||||
}
|
}
|
||||||
} as u8;
|
} as u8;
|
||||||
|
|
||||||
let end_of_stream = (pressed_char == delimiter);
|
let end_of_stream = pressed_char == delimiter;
|
||||||
|
|
||||||
// we could return error but maybe option to keep listening until valid character is inputted.
|
// we could return error but maybe option to keep listening until valid character is inputted.
|
||||||
if pressed_char == 0 || pressed_char == 0xe0 || end_of_stream {
|
if pressed_char == 0 || pressed_char == 0xe0 || end_of_stream {
|
||||||
|
@ -6,4 +6,3 @@ pub mod terminal;
|
|||||||
|
|
||||||
use super::common::commands;
|
use super::common::commands;
|
||||||
use super::common::functions;
|
use super::common::functions;
|
||||||
use super::common::traits;
|
|
||||||
|
@ -5,10 +5,7 @@
|
|||||||
use super::IStdout;
|
use super::IStdout;
|
||||||
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::cell::RefCell;
|
use std::io::{self, Write,Stdout, stdout};
|
||||||
use std::sync::{Arc,Mutex};
|
|
||||||
use std::io::{self, Read, Write,Stdout, stdout};
|
|
||||||
use std::str::from_utf8;
|
|
||||||
|
|
||||||
/// This struct is a wrapper for `Stdout`
|
/// This struct is a wrapper for `Stdout`
|
||||||
pub struct AnsiOutput {
|
pub struct AnsiOutput {
|
||||||
|
@ -21,15 +21,8 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::fmt::Display;
|
|
||||||
use std::io::{self, Write};
|
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
use winapi::um::winnt::HANDLE;
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
/// Struct that is an handle to an terminal screen.
|
/// Struct that is an handle to an terminal screen.
|
||||||
/// This handle could be used to write to the current screen
|
/// This handle could be used to write to the current screen
|
||||||
///
|
///
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
use super::IStdout;
|
use super::IStdout;
|
||||||
use kernel::windows_kernel::{handle, kernel, writing};
|
use kernel::windows_kernel::{handle, writing};
|
||||||
use winapi::um::wincon::ENABLE_PROCESSED_OUTPUT;
|
|
||||||
use winapi::um::winnt::HANDLE;
|
use winapi::um::winnt::HANDLE;
|
||||||
|
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::ptr::NonNull;
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
|
|
||||||
/// This struct is a wrapper for WINAPI `HANDLE`
|
/// This struct is a wrapper for WINAPI `HANDLE`
|
||||||
pub struct WinApiOutput {
|
pub struct WinApiOutput {
|
||||||
pub handle: Mutex<HANDLE>,
|
pub handle: Mutex<HANDLE>,
|
||||||
@ -24,6 +21,7 @@ impl IStdout for WinApiOutput {
|
|||||||
writing::write_char_buffer(&self.handle.lock().unwrap(), buf)
|
writing::write_char_buffer(&self.handle.lock().unwrap(), buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn flush(&self) -> io::Result<()> {
|
fn flush(&self) -> io::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
//! 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, TerminalOutput, StyledObject};
|
use super::{Color, StyledObject};
|
||||||
|
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use super::Attribute;
|
use super::Attribute;
|
||||||
|
@ -1,17 +1,13 @@
|
|||||||
//! 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, TerminalOutput};
|
use super::{Color, ObjectStyle};
|
||||||
use Screen;
|
use Screen;
|
||||||
|
|
||||||
use std::fmt::{self, Display};
|
use std::fmt::Display;
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use super::Attribute;
|
use super::Attribute;
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
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> {
|
||||||
pub object_style: ObjectStyle,
|
pub object_style: ObjectStyle,
|
||||||
@ -154,7 +150,7 @@ impl<D: Display> StyledObject<D> {
|
|||||||
/// ```
|
/// ```
|
||||||
pub fn paint(&self, screen: &Screen)
|
pub fn paint(&self, screen: &Screen)
|
||||||
{
|
{
|
||||||
let mut colored_terminal = super::super::super::style::color::color(&screen);
|
let colored_terminal = ::color(&screen);
|
||||||
let mut reset = true;
|
let mut reset = true;
|
||||||
|
|
||||||
if let Some(bg) = self.object_style.bg_color {
|
if let Some(bg) = self.object_style.bg_color {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
//! 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 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.
|
||||||
@ -52,7 +51,7 @@ impl ITerminal for AnsiTerminal {
|
|||||||
|
|
||||||
fn exit(&self,stdout: &Arc<TerminalOutput>) {
|
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(stdout.clone());
|
let screen = Screen::from(stdout.clone());
|
||||||
drop(screen);
|
drop(screen);
|
||||||
functions::exit_terminal();
|
functions::exit_terminal();
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
/// Struct that stores an specific platform implementation for terminal related actions.
|
/// Struct that stores an specific platform implementation for terminal related actions.
|
||||||
///
|
///
|
||||||
|
@ -61,9 +61,6 @@ impl ITerminal for WinApiTerminal {
|
|||||||
// 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;
|
||||||
|
|
||||||
// Set srctWindow to the current window size and location.
|
|
||||||
srct_window = csbi.srWindow;
|
|
||||||
|
|
||||||
// Check whether the window is too close to the screen buffer top
|
// Check whether the window is too close to the screen buffer top
|
||||||
if srct_window.Bottom < csbi.dwSize.Y - count {
|
if srct_window.Bottom < csbi.dwSize.Y - count {
|
||||||
srct_window.Top += count; // move top down
|
srct_window.Top += count; // move top down
|
||||||
|
Loading…
Reference in New Issue
Block a user