Some errors solved for unix
This commit is contained in:
parent
524955f8c0
commit
2cc32394b5
@ -7,7 +7,9 @@ use std::ops::Drop;
|
||||
use {Construct, Context};
|
||||
use shared::functions::get_module;
|
||||
use super::base_cursor::ITerminalCursor;
|
||||
|
||||
use super::AnsiCursor;
|
||||
#[cfg(target_os = "windows")]
|
||||
use super::WinApiCursor;
|
||||
|
||||
/// Struct that stores an specific platform implementation for cursor related actions.
|
||||
|
@ -2,9 +2,13 @@ mod base_cursor;
|
||||
mod cursor;
|
||||
|
||||
mod ansi_cursor;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
mod winapi_cursor;
|
||||
|
||||
use self::ansi_cursor::AnsiCursor;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
use self::winapi_cursor::WinApiCursor;
|
||||
|
||||
pub use self::cursor::{ cursor, TerminalCursor };
|
||||
|
@ -12,6 +12,8 @@ use shared::functions::get_module;
|
||||
use super::super::Color;
|
||||
|
||||
use super::AnsiColor;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
use super::WinApiColor;
|
||||
|
||||
/// Struct that stores an specific platform implementation for color related actions.
|
||||
|
@ -2,7 +2,11 @@ pub mod base_color;
|
||||
pub mod color;
|
||||
|
||||
mod ansi_color;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
mod winapi_color;
|
||||
|
||||
use self::ansi_color::AnsiColor;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
use self::winapi_color::WinApiColor;
|
||||
|
@ -5,9 +5,13 @@ mod terminal;
|
||||
pub mod screen;
|
||||
|
||||
mod ansi_terminal;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
mod winapi_terminal;
|
||||
|
||||
use self::ansi_terminal::AnsiTerminal;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
use self::winapi_terminal::WinApiTerminal;
|
||||
|
||||
pub use self::base_terminal::ClearType;
|
||||
|
@ -2,9 +2,10 @@ use std::io::{self, Write};
|
||||
use std::ops;
|
||||
use std::any::Any;
|
||||
|
||||
use crossterm_state::commands::{shared_commands,win_commands,ICommand, CommandType};
|
||||
use crossterm_state::commands::IContextCommand;
|
||||
use shared::functions::get_module;
|
||||
use crossterm_state::commands::*;
|
||||
use shared::traits::Construct;
|
||||
use Context;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
@ -45,12 +46,13 @@ impl fmt::Display for ToAlternateScreen
|
||||
pub struct AlternateScreen<W: Write> {
|
||||
/// The output target.
|
||||
output: W,
|
||||
context: Context
|
||||
}
|
||||
|
||||
impl<W: Write> AlternateScreen< W> {
|
||||
pub fn from(mut output: W) -> Self {
|
||||
write!(output, "{}", ToAlternateScreen);
|
||||
AlternateScreen { output: output }
|
||||
AlternateScreen { output: output, context: Context::new()}
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,37 +84,20 @@ impl<W: Write> Drop for AlternateScreen<W>
|
||||
{
|
||||
fn drop(&mut self)
|
||||
{
|
||||
this
|
||||
write!(self, "{}", ToMainScreen).expect("switch to main screen");
|
||||
}
|
||||
}
|
||||
|
||||
fn get_to_alternate_screen_command() -> Box<ICommand>
|
||||
{
|
||||
// let mut does_support = true;
|
||||
let mut command: Option<Box<ICommand>> = None;
|
||||
//
|
||||
// let succeeded = false;
|
||||
//
|
||||
// if cfg!(target_os = "windows")
|
||||
// {
|
||||
// #[cfg(windows)]
|
||||
// use kernel::windows_kernel::ansi_support::try_enable_ansi_support;
|
||||
//
|
||||
// // Try to enable ansi on windows if not than use WINAPI.
|
||||
// does_support = try_enable_ansi_support();
|
||||
//
|
||||
// println!("does support: {}", does_support);
|
||||
// if !does_support
|
||||
// {
|
||||
command = Some(win_commands::ToAlternateScreenBufferCommand::new());
|
||||
command.unwrap()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if does_support
|
||||
// {
|
||||
// command = Some(shared_commands::ToAlternateScreenBufferCommand::new().0);
|
||||
// }
|
||||
//
|
||||
// command.unwrap()
|
||||
let mut context = Context::new();
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
let command = get_module::<Box<ICommand>>(win_commands::ToAlternateScreenBufferCommand::new(), shared_commands::ToAlternateScreenBufferCommand::new(), &mut context).unwrap();
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
let command = shared_commands::ToAlternateScreenBufferCommand::new();
|
||||
|
||||
command
|
||||
}
|
@ -8,6 +8,8 @@ use super::base_terminal::{ClearType, ITerminal};
|
||||
use shared::functions::get_module;
|
||||
|
||||
use super::AnsiTerminal;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
use super::WinApiTerminal;
|
||||
|
||||
/// Struct that stores an specific platform implementation for terminal related actions.
|
||||
|
@ -1,7 +1,9 @@
|
||||
use libc;
|
||||
use self::libc::{STDOUT_FILENO, TIOCGWINSZ, c_ushort, ioctl};
|
||||
pub use self::libc::termios as Termios;
|
||||
use crossterm_state::commands::{NoncanonicaModeCommand, IContextCommand};
|
||||
use std::io;
|
||||
use std::mem;
|
||||
|
||||
|
||||
/// A representation of the size of the current terminal
|
||||
@ -37,14 +39,14 @@ pub fn terminal_size() -> (u16,u16) {
|
||||
/// Get the current cursor position
|
||||
pub fn pos() -> (u16,u16)
|
||||
{
|
||||
use std::io::{Write,Read};
|
||||
use std::io::Error;
|
||||
use std::io::{ Write,Read };
|
||||
|
||||
let command = NoncanonicalModeCommand::new();
|
||||
command.execute();
|
||||
|
||||
// This code is original written by term_cursor credits to them.
|
||||
let mut stdout = std::io::stdout();
|
||||
let mut stdout = io::stdout();
|
||||
|
||||
// Write command
|
||||
stdout.write(b"\x1B[6n")?;
|
||||
@ -53,7 +55,7 @@ pub fn pos() -> (u16,u16)
|
||||
// Read back result
|
||||
let mut buf = [0u8; 2];
|
||||
// Expect `ESC[`
|
||||
std::io::stdin().read_exact(&mut buf)?;
|
||||
io::stdin().read_exact(&mut buf)?;
|
||||
if buf[0] != 0x1B || buf[1] as char != '[' {
|
||||
return (0,0);
|
||||
}
|
||||
@ -65,7 +67,7 @@ pub fn pos() -> (u16,u16)
|
||||
|
||||
loop {
|
||||
let mut buf = [0u8; 1];
|
||||
std::io::stdin().read_exact(&mut buf)?;
|
||||
io::stdin().read_exact(&mut buf)?;
|
||||
c = buf[0] as char;
|
||||
if let Some(d) = c.to_digit(10) {
|
||||
num = if num == 0 { 0 } else { num * 10 };
|
||||
|
Loading…
Reference in New Issue
Block a user