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