From 54bab519768e7d530487fa8acf739605f0d3b60d Mon Sep 17 00:00:00 2001 From: Timon Date: Sat, 28 Jul 2018 17:46:05 +0000 Subject: [PATCH] unix errors fixed --- examples/Crossterm 0.3.1/bin.rs | 1 - src/common/commands/mod.rs | 8 +------- src/common/commands/unix_command.rs | 15 +++------------ src/common/screen/raw.rs | 3 ++- src/kernel/unix_kernel/terminal.rs | 15 ++++++++------- src/modules/style/color.rs | 2 +- src/modules/style/objectstyle.rs | 2 +- src/modules/style/styledobject.rs | 20 ++++++++++---------- src/modules/terminal/terminal.rs | 2 +- 9 files changed, 27 insertions(+), 41 deletions(-) diff --git a/examples/Crossterm 0.3.1/bin.rs b/examples/Crossterm 0.3.1/bin.rs index 85d614d..701eaa5 100644 --- a/examples/Crossterm 0.3.1/bin.rs +++ b/examples/Crossterm 0.3.1/bin.rs @@ -30,7 +30,6 @@ fn main() { let mut cursor = term.cursor(); cursor.goto(10, 10); cursor.print("test"); - term.terminal().set_size(20,20); let mut color = term.color(); color.set_fg(Color::Red); } diff --git a/src/common/commands/mod.rs b/src/common/commands/mod.rs index eb35d21..6f2f1af 100644 --- a/src/common/commands/mod.rs +++ b/src/common/commands/mod.rs @@ -8,18 +8,12 @@ use std::io::Result; pub mod shared_commands; -#[cfg(target_os = "unix")] +#[cfg(not(target_os = "windows"))] pub mod unix_command; #[cfg(target_os = "windows")] pub mod win_commands; -#[cfg(target_os = "windows")] -pub use self::win_commands::*; -#[cfg(target_os = "unix")] -pub use self::unix_commands::*; - -pub use self::shared_commands::*; /// This command is used for complex commands whits change the terminal state. /// By passing an `Context` instance this command will register it self to notify the terminal state change. diff --git a/src/common/commands/unix_command.rs b/src/common/commands/unix_command.rs index 4c5f17b..b92a73a 100644 --- a/src/common/commands/unix_command.rs +++ b/src/common/commands/unix_command.rs @@ -10,20 +10,11 @@ use std::io::{Result,Error, ErrorKind}; /// This command is used for switching to NoncanonicalMode. #[derive(Copy, Clone)] -pub struct NoncanonicalModeCommand { - key: u16, -} +pub struct NoncanonicalModeCommand; impl NoncanonicalModeCommand { - pub fn new(state_manager: &Mutex) -> u16 { - let mut state = state_manager.lock().unwrap(); - { - let key = state.get_changes_count(); - let command = NoncanonicalModeCommand { key: key }; - - state.register_change(Box::from(command), key); - key - } + pub fn new() -> NoncanonicalModeCommand { + NoncanonicalModeCommand { } } } diff --git a/src/common/screen/raw.rs b/src/common/screen/raw.rs index 89a3b18..57b1e08 100644 --- a/src/common/screen/raw.rs +++ b/src/common/screen/raw.rs @@ -13,7 +13,8 @@ //! With these modes you can easier design the terminal screen. #[cfg(not(windows))] -use common::commands::EnableRawModeCommand; +use common::commands::unix_command::EnableRawModeCommand; + #[cfg(windows)] use common::commands::EnableRawModeCommand; diff --git a/src/kernel/unix_kernel/terminal.rs b/src/kernel/unix_kernel/terminal.rs index f6636fd..e44e917 100644 --- a/src/kernel/unix_kernel/terminal.rs +++ b/src/kernel/unix_kernel/terminal.rs @@ -3,12 +3,18 @@ use libc; pub use libc::termios; use self::libc::{c_int, c_ushort, ioctl, STDOUT_FILENO, TIOCGWINSZ}; -use common::commands::{NoncanonicalModeCommand, EnableRawModeCommand}; +use common::commands::unix_command::{NoncanonicalModeCommand, EnableRawModeCommand}; use std::io::Error; use std::os::unix::io::AsRawFd; use std::{fs, io, mem}; use termios::{cfmakeraw, tcsetattr, Termios, TCSADRAIN}; +use std::io::ErrorKind; +use std::io::Read; +use std::time::{SystemTime, Duration}; + + +use Crossterm; /// A representation of the size of the current terminal. #[repr(C)] @@ -41,14 +47,9 @@ pub fn terminal_size() -> (u16, u16) { } } - -use std::time::{SystemTime, Duration}; -use std::io::ErrorKind; -use Terminal; -use std::io::Read; /// Get the current cursor position. pub fn pos() -> (u16, u16) { - let crossterm = Terminal::new(); + let crossterm = Crossterm::new(); let input = crossterm.input(); let delimiter = b'R'; diff --git a/src/modules/style/color.rs b/src/modules/style/color.rs index 0512ac7..0a9fd43 100644 --- a/src/modules/style/color.rs +++ b/src/modules/style/color.rs @@ -21,7 +21,7 @@ impl<'terminal> TerminalColor<'terminal> { ).unwrap(); #[cfg(not(target_os = "windows"))] - let color = AnsiColor::new() as Box; + let color = Box::from(AnsiColor::new()) as Box; TerminalColor { color, diff --git a/src/modules/style/objectstyle.rs b/src/modules/style/objectstyle.rs index 6a5f5dc..01c5d98 100644 --- a/src/modules/style/objectstyle.rs +++ b/src/modules/style/objectstyle.rs @@ -5,7 +5,7 @@ use super::{ScreenManager, Color, StyledObject}; use std::fmt::Display; #[cfg(unix)] -use super::super::Attribute; +use super::Attribute; /// Struct that contains the style properties that can be applied to an displayable object. #[derive(Clone)] diff --git a/src/modules/style/styledobject.rs b/src/modules/style/styledobject.rs index f659465..4b37f35 100644 --- a/src/modules/style/styledobject.rs +++ b/src/modules/style/styledobject.rs @@ -5,7 +5,7 @@ use std::fmt::{self, Display}; use std::io::Write; #[cfg(unix)] -use super::super::Attribute; +use super::Attribute; #[cfg(windows)] use super::super::super::manager::WinApiScreenManager; @@ -89,55 +89,55 @@ impl<'terminal,D: Display> StyledObject<'terminal,D> { /// Increase the font intensity. #[cfg(unix)] #[inline(always)] - pub fn bold(self) -> StyledObject { + pub fn bold(self) -> StyledObject<'terminal,D> { self.attr(Attribute::Bold) } /// Faint (decreased intensity) (Not widely supported). #[cfg(unix)] #[inline(always)] - pub fn dim(self) -> StyledObject { + pub fn dim(self) -> StyledObject<'terminal,D> { self.attr(Attribute::Dim) } /// Make the font italic (Not widely supported; Sometimes treated as inverse). #[cfg(unix)] #[inline(always)] - pub fn italic(self) -> StyledObject { + pub fn italic(self) -> StyledObject<'terminal,D> { self.attr(Attribute::Italic) } /// Underline font. #[cfg(unix)] #[inline(always)] - pub fn underlined(self) -> StyledObject { + pub fn underlined(self) -> StyledObject<'terminal,D> { self.attr(Attribute::Underlined) } /// Slow Blink (less than 150 per minute; not widely supported). #[cfg(unix)] #[inline(always)] - pub fn slow_blink(self) -> StyledObject { + pub fn slow_blink(self) -> StyledObject<'terminal,D> { self.attr(Attribute::SlowBlink) } /// Rapid Blink (MS-DOS ANSI.SYS; 150+ per minute; not widely supported). #[cfg(unix)] #[inline(always)] - pub fn rapid_blink(self) -> StyledObject { + pub fn rapid_blink(self) -> StyledObject<'terminal,D> { self.attr(Attribute::RapidBlink) } /// Swap foreground and background colors. #[cfg(unix)] #[inline(always)] - pub fn reverse(self) -> StyledObject { + pub fn reverse(self) -> StyledObject<'terminal,D> { self.attr(Attribute::Reverse) } /// Hide text (Not widely supported). #[cfg(unix)] #[inline(always)] - pub fn hidden(self) -> StyledObject { + pub fn hidden(self) -> StyledObject<'terminal,D> { self.attr(Attribute::Hidden) } /// Characters legible, but marked for deletion. Not widely supported. #[cfg(unix)] #[inline(always)] - pub fn crossed_out(self) -> StyledObject { + pub fn crossed_out(self) -> StyledObject<'terminal,D> { self.attr(Attribute::CrossedOut) } } diff --git a/src/modules/terminal/terminal.rs b/src/modules/terminal/terminal.rs index ed17126..22e3f92 100644 --- a/src/modules/terminal/terminal.rs +++ b/src/modules/terminal/terminal.rs @@ -22,7 +22,7 @@ impl<'terminal> Terminal<'terminal> { ).unwrap(); #[cfg(not(target_os = "windows"))] - let terminal = AnsiTerminal::new() as Box; + let terminal = Box::from(AnsiTerminal::new()) as Box; Terminal { terminal,