From 0df9ad1015f49a6ce5f1fd4e0c66b13bdccdc60a Mon Sep 17 00:00:00 2001 From: T Date: Thu, 25 Jan 2018 18:26:08 +0100 Subject: [PATCH 1/3] Added resizing terminal. Styling font with attributes for unix systems inplemented. Windows kernel refactored and cleared out some grammer mistakes. (Windows tested and unix jet to be tested). --- .idea/workspace.xml | 854 ++++++++++++--------- Cargo.toml | 3 + examples/bin.rs | 3 + examples/color/mod.rs | 2 +- examples/cursor/mod.rs | 12 + examples/terminal/mod.rs | 19 +- src/crossterm_cursor/ansi_cursor.rs | 12 + src/crossterm_cursor/base_cursor.rs | 4 + src/crossterm_cursor/cursor.rs | 46 ++ src/crossterm_cursor/winapi_cursor.rs | 26 +- src/crossterm_mouse/mod.rs | 0 src/crossterm_style/color/base_color.rs | 2 +- src/crossterm_style/color/color.rs | 77 +- src/crossterm_style/color/winapi_color.rs | 2 +- src/crossterm_style/mod.rs | 88 +++ src/crossterm_style/styles/objectstyle.rs | 13 +- src/crossterm_style/styles/styledobject.rs | 31 + src/crossterm_terminal/ansi_terminal.rs | 5 + src/crossterm_terminal/base_terminal.rs | 2 + src/crossterm_terminal/terminal.rs | 11 + src/crossterm_terminal/winapi_terminal.rs | 2 + src/kernel/windows_kernel/ansi_support.rs | 17 +- src/kernel/windows_kernel/color.rs | 30 +- src/kernel/windows_kernel/cursor.rs | 64 +- src/kernel/windows_kernel/handle.rs | 31 - src/kernel/windows_kernel/kernel.rs | 167 +++- src/kernel/windows_kernel/mod.rs | 1 - src/kernel/windows_kernel/terminal.rs | 169 ++-- src/shared/functions.rs | 6 - src/shared/traits.rs | 2 + todo.txt | 6 +- 31 files changed, 1087 insertions(+), 620 deletions(-) create mode 100644 src/crossterm_mouse/mod.rs delete mode 100644 src/kernel/windows_kernel/handle.rs diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 7bf73c3..aa2c112 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,26 +2,37 @@ + - + + + + + + + + + + + - + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - @@ -85,10 +164,27 @@ winapi kernel32 HANDLE - CONSOLE_SCREEN_BUFFER_INFO handleapi terminal_cursor terminal + r + short + console_mode + set + fsr_window + resizeBuffer + set_console_text_attribute + set( + kern + pos + csbi + kernel + success + count + xpos + handle:: + wincon + CONSOLE_SCREEN_BUFFER_INFO crossterm_cursor @@ -105,25 +201,40 @@ @@ -136,8 +247,8 @@ @@ -154,6 +265,7 @@ + @@ -166,21 +278,107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + @@ -498,16 +285,16 @@ - + + - - @@ -522,7 +309,7 @@ - + @@ -654,13 +441,6 @@ - - - - - - - @@ -767,13 +547,6 @@ - - - - - - - @@ -809,14 +582,6 @@ - - - - - - - - @@ -825,21 +590,13 @@ - - - - - - - - - - + + @@ -852,19 +609,6 @@ - - - - - - - - - - - - - @@ -873,37 +617,77 @@ + + + + + + + + + + + + + + + + - - + + - - + + - - + + - + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/crossterm_style/mod.rs b/src/crossterm_style/mod.rs index b9924be..b526f9d 100644 --- a/src/crossterm_style/mod.rs +++ b/src/crossterm_style/mod.rs @@ -9,7 +9,6 @@ pub use self::styles::styledobject::StyledObject; use std::convert::From; use std::str::FromStr; -#[cfg(unix)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd)] pub enum Attribute { Bold = 1, diff --git a/src/crossterm_style/styles/objectstyle.rs b/src/crossterm_style/styles/objectstyle.rs index 43ab86c..e43d82b 100644 --- a/src/crossterm_style/styles/objectstyle.rs +++ b/src/crossterm_style/styles/objectstyle.rs @@ -1,11 +1,14 @@ use crossterm_style::{Color, StyledObject}; use std::fmt::Display; + use super::super::Attribute; + /// Struct that contains the style properties that can be applied to an displayable object. #[derive(Clone)] pub struct ObjectStyle { pub fg_color: Option, pub bg_color: Option, + #[cfg(unix)] pub attrs: Vec } @@ -55,6 +58,7 @@ impl ObjectStyle { self } + #[cfg(unix)] pub fn add_attr(&mut self, attr: Attribute) { self.attrs.push(attr); diff --git a/src/crossterm_style/styles/styledobject.rs b/src/crossterm_style/styles/styledobject.rs index e91006f..4f239bf 100644 --- a/src/crossterm_style/styles/styledobject.rs +++ b/src/crossterm_style/styles/styledobject.rs @@ -1,6 +1,7 @@ use std; use std::fmt; use std::io::Write; + use super::super::Attribute; use crossterm_style::{Color, ObjectStyle}; diff --git a/src/kernel/windows_kernel/color.rs b/src/kernel/windows_kernel/color.rs index aac968e..018b7ad 100644 --- a/src/kernel/windows_kernel/color.rs +++ b/src/kernel/windows_kernel/color.rs @@ -81,7 +81,6 @@ pub fn winapi_color_val(color: style::Color, color_type: style::ColorType) -> u1 Color::DarkCyan => fg_green | fg_blue, Color::Grey => fg_intensity, Color::White => fg_intensity | fg_red | fg_green | fg_blue, - _ => Color::White }; } ColorType::Background => { @@ -101,7 +100,6 @@ pub fn winapi_color_val(color: style::Color, color_type: style::ColorType) -> u1 Color::DarkCyan => bg_green | bg_blue, Color::Grey => bg_intensity, Color::White => bg_intensity | bg_red | bg_green | bg_blue, - _ => Color::White }; } }; diff --git a/src/kernel/windows_kernel/kernel.rs b/src/kernel/windows_kernel/kernel.rs index c7f9a9e..0ee22c9 100644 --- a/src/kernel/windows_kernel/kernel.rs +++ b/src/kernel/windows_kernel/kernel.rs @@ -151,7 +151,7 @@ pub fn fill_console_output_attribute(cells_written: &mut u32, start_location: CO let csbi = get_console_screen_buffer_info(); let output_handle = get_output_handle(); - let mut success; + let success; unsafe { success = FillConsoleOutputAttribute (