From 46e7ad720f5682e31e02d8dd02dd720bae5c8eb1 Mon Sep 17 00:00:00 2001 From: Timon Date: Tue, 26 Jun 2018 16:48:50 +0000 Subject: [PATCH 1/2] fixed unix compile error --- .idea/workspace.xml | 342 ++++++++---------- .../bin.rs | 11 +- .../color/mod.rs | 2 +- src/cursor/ansi_cursor.rs | 2 +- src/style/styles/styledobject.rs | 7 +- 5 files changed, 169 insertions(+), 195 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 325ca54..6e5268e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,14 +3,9 @@ - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -79,20 +35,69 @@ - + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -100,30 +105,12 @@ - + - - - - - - - - - - - - - - - - - - @@ -135,7 +122,6 @@ - terminal_cursor term ScreenManager color @@ -165,6 +151,7 @@ data context WinApiScreenManager + color( crossterm_cursor @@ -205,7 +192,6 @@ @@ -291,6 +278,26 @@ + + + + + + + + + + + + + + + + + + + + @@ -557,11 +564,12 @@ + - @@ -573,50 +581,28 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + @@ -624,12 +610,12 @@ - + @@ -640,7 +626,7 @@ - + @@ -666,13 +652,6 @@ - - - - - - - @@ -774,13 +753,6 @@ - - - - - - - @@ -795,13 +767,6 @@ - - - - - - - @@ -823,13 +788,6 @@ - - - - - - - @@ -886,20 +844,6 @@ - - - - - - - - - - - - - - @@ -918,31 +862,19 @@ - - - - - - - - - - - - - + - + @@ -956,14 +888,14 @@ - + - + @@ -975,10 +907,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/Crossterm 0.2.2 - New Version (Not finished)/bin.rs b/examples/Crossterm 0.2.2 - New Version (Not finished)/bin.rs index cf3732b..4f4f8d8 100644 --- a/examples/Crossterm 0.2.2 - New Version (Not finished)/bin.rs +++ b/examples/Crossterm 0.2.2 - New Version (Not finished)/bin.rs @@ -30,15 +30,10 @@ use std::io::Write; use std::{time, thread}; fn main() { -//// alternate_screen::switch_between_main_and_alternate_screen(); let context = Context::new(); -// let mut scre = screen::AlternateScreen::from(context.clone()); -// write!(scre, "asdf"); -// scre.flush(); -// thread::sleep(time::Duration::from_secs(3)); - use crossterm::terminal::terminal; + use crossterm::cursor::cursor; - let curs = terminal(context.clone()); - curs.set_title(String::from("Test")); + let curs = cursor(context.clone()); + curs.blink(false); } \ No newline at end of file diff --git a/examples/Crossterm 0.2.2 - New Version (Not finished)/color/mod.rs b/examples/Crossterm 0.2.2 - New Version (Not finished)/color/mod.rs index 81b65af..603c70f 100644 --- a/examples/Crossterm 0.2.2 - New Version (Not finished)/color/mod.rs +++ b/examples/Crossterm 0.2.2 - New Version (Not finished)/color/mod.rs @@ -146,7 +146,7 @@ pub fn print_supported_colors() let context = Context::new(); let terminal = terminal::terminal(context.clone()); - let count = crossterm::style::color(context.screen_manager.clone()).get_available_color_count().unwrap(); + let count = crossterm::style::color(context.clone()).get_available_color_count().unwrap(); for i in 0..count { diff --git a/src/cursor/ansi_cursor.rs b/src/cursor/ansi_cursor.rs index d880abe..83fe35b 100644 --- a/src/cursor/ansi_cursor.rs +++ b/src/cursor/ansi_cursor.rs @@ -100,7 +100,7 @@ impl ITerminalCursor for AnsiCursor { screen.write_ansi_str(csi!("?12h")); } else { - screen.write_ansi_str(csi!("?12l")); + screen.write_ansi_str(csi!("?12")); } } } diff --git a/src/style/styles/styledobject.rs b/src/style/styles/styledobject.rs index 8d3cd9a..8fcaa3f 100644 --- a/src/style/styles/styledobject.rs +++ b/src/style/styles/styledobject.rs @@ -124,18 +124,19 @@ macro_rules! impl_fmt colored_terminal.set_bg(bg); reset = true; } + if let Some(fg) = self.object_style.fg_color { colored_terminal.set_fg(fg); reset = true; } - #[cfg(unix)] +// #[cfg(unix)] for attr in self.object_style.attrs.iter() { - let mutex = self.context.screen_manager; + let mutex = &self.context.screen_manager; { let mut screen = mutex.lock().unwrap(); - screen.write_ansi_str(format!(csi!("{}m"), *attr as i16)); + screen.write_ansi(format!(csi!("{}m"), *attr as i16)); } reset = true; } From 043bac575f379109fbfde2dc187701abfb4fc656 Mon Sep 17 00:00:00 2001 From: Timon Date: Tue, 26 Jun 2018 18:21:47 +0000 Subject: [PATCH 2/2] exit current proccess added --- .idea/workspace.xml | 407 +++++++++--------- .../bin.rs | 10 +- src/kernel/unix_kernel/terminal.rs | 4 + src/kernel/windows_kernel/terminal.rs | 5 + src/shared/functions.rs | 18 +- src/terminal/ansi_terminal.rs | 5 + src/terminal/mod.rs | 2 + src/terminal/terminal.rs | 7 + src/terminal/winapi_terminal.rs | 6 + 9 files changed, 249 insertions(+), 215 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6e5268e..476a865 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,11 +2,14 @@ - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + - - + + - - + + - - + + + + + + + + + + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -175,7 +190,6 @@ @@ -289,26 +304,20 @@ - + - + - - - - - - @@ -326,7 +335,8 @@ - + + @@ -334,39 +344,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -564,12 +541,12 @@ - + - @@ -641,13 +618,6 @@ - - - - - - - @@ -659,20 +629,6 @@ - - - - - - - - - - - - - - @@ -739,20 +695,6 @@ - - - - - - - - - - - - - - @@ -774,13 +716,6 @@ - - - - - - - @@ -788,20 +723,6 @@ - - - - - - - - - - - - - - @@ -809,13 +730,6 @@ - - - - - - - @@ -823,20 +737,6 @@ - - - - - - - - - - - - - - @@ -946,17 +846,110 @@ - + - - + + - + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/Crossterm 0.2.2 - New Version (Not finished)/bin.rs b/examples/Crossterm 0.2.2 - New Version (Not finished)/bin.rs index 4f4f8d8..b952917 100644 --- a/examples/Crossterm 0.2.2 - New Version (Not finished)/bin.rs +++ b/examples/Crossterm 0.2.2 - New Version (Not finished)/bin.rs @@ -29,11 +29,15 @@ use crossterm::raw::IntoRawMode; use std::io::Write; use std::{time, thread}; +use std::process::exit; + fn main() { let context = Context::new(); - use crossterm::cursor::cursor; + use crossterm::terminal::terminal; + + let curs = terminal(context.clone()); + curs.exit(); + thread::sleep(time::Duration::from_secs(3)); - let curs = cursor(context.clone()); - curs.blink(false); } \ No newline at end of file diff --git a/src/kernel/unix_kernel/terminal.rs b/src/kernel/unix_kernel/terminal.rs index 2dff600..7f10506 100644 --- a/src/kernel/unix_kernel/terminal.rs +++ b/src/kernel/unix_kernel/terminal.rs @@ -132,6 +132,10 @@ pub fn get_terminal_mode() -> io::Result } } +pub fn exit() +{ + ::std::process::exit(0); + /// Is the return value true? fn is_true(value: i32) -> Result<(), Error> { diff --git a/src/kernel/windows_kernel/terminal.rs b/src/kernel/windows_kernel/terminal.rs index 2771f44..9a31e1a 100644 --- a/src/kernel/windows_kernel/terminal.rs +++ b/src/kernel/windows_kernel/terminal.rs @@ -5,4 +5,9 @@ pub fn terminal_size() -> (u16, u16) { (csbi.srWindow.Right - csbi.srWindow.Left) as u16, (csbi.srWindow.Bottom - csbi.srWindow.Top) as u16, ) +} + +pub fn exit() +{ + ::std::process::exit(256); } \ No newline at end of file diff --git a/src/shared/functions.rs b/src/shared/functions.rs index 58514bd..1408552 100644 --- a/src/shared/functions.rs +++ b/src/shared/functions.rs @@ -4,15 +4,13 @@ use Context; use std::rc::Rc; #[cfg(windows)] -use kernel::windows_kernel::terminal::terminal_size; - -#[cfg(unix)] -use kernel::unix_kernel::terminal::terminal_size; +use kernel::windows_kernel::terminal::{exit, terminal_size}; #[cfg(windows)] use kernel::windows_kernel::cursor::pos; + #[cfg(unix)] -use kernel::unix_kernel::terminal::pos; +use kernel::unix_kernel::terminal::{pos, exit,terminal_size }; /// Get the terminal size based on the current platform. pub fn get_terminal_size() -> (u16, u16) @@ -30,6 +28,16 @@ pub fn get_cursor_position(context: Rc) -> (u16, u16) return pos(); } +/// exit the current terminal. +pub fn exit_terminal() +{ + #[cfg(unix)] + exit(); + + #[cfg(windows)] + exit(); +} + #[cfg(windows)] /// Get an module specific implementation based on the current platform. pub fn get_module(winapi_impl: T, unix_impl: T) -> Option diff --git a/src/terminal/ansi_terminal.rs b/src/terminal/ansi_terminal.rs index 378a4e4..264d121 100644 --- a/src/terminal/ansi_terminal.rs +++ b/src/terminal/ansi_terminal.rs @@ -74,4 +74,9 @@ impl ITerminal for AnsiTerminal { screen.write_ansi_str("\x1b]2;New terminal titleBEL"); } } + + fn exit(&self) + { + functions::exit_terminal(); + } } diff --git a/src/terminal/mod.rs b/src/terminal/mod.rs index 1d0d23e..2003aaa 100644 --- a/src/terminal/mod.rs +++ b/src/terminal/mod.rs @@ -50,4 +50,6 @@ pub trait ITerminal { fn set_size(&self,width: i16, height: i16); /// Set the terminal title. fn set_title(&self, title: String); + /// Close the current terminal + fn exit(&self); } diff --git a/src/terminal/terminal.rs b/src/terminal/terminal.rs index faab9d4..00d9069 100644 --- a/src/terminal/terminal.rs +++ b/src/terminal/terminal.rs @@ -193,6 +193,13 @@ impl Terminal { terminal.set_title(title ); } } + + pub fn exit(&self) + { + if let Some (ref terminal) = self.terminal { + terminal.exit(); + } + } } /// Get an Terminal implementation whereon terminal related actions can be performed. diff --git a/src/terminal/winapi_terminal.rs b/src/terminal/winapi_terminal.rs index 866c6c7..e40fd44 100644 --- a/src/terminal/winapi_terminal.rs +++ b/src/terminal/winapi_terminal.rs @@ -6,6 +6,7 @@ use cursor::cursor; use super::{ClearType, ITerminal, Rc}; use winapi::um::wincon::{SMALL_RECT, COORD, CONSOLE_SCREEN_BUFFER_INFO,}; use kernel::windows_kernel::{kernel, terminal}; +use super::super::shared::functions; /// This struct is an windows implementation for terminal related actions. pub struct WinApiTerminal @@ -142,6 +143,11 @@ impl ITerminal for WinApiTerminal { { } + + fn exit(&self) + { + functions::exit_terminal(); + } } pub fn clear_after_cursor(pos: (u16,u16), csbi: CONSOLE_SCREEN_BUFFER_INFO, context: Rc) {