Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored winapi and moved code to (crossterm_winapi) #67

Merged
merged 2 commits into from
Dec 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ keywords = ["console", "color", "cursor", "input", "terminal"]
exclude = ["target", "Cargo.lock"]
readme = "README.md"

[dependencies]
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.5", features = ["winbase","winuser","consoleapi","processenv","wincon", "handleapi","errhandlingapi"] }
crossterm_winapi = { version = "0.0.0", git="https://github.com/TimonPost/crossterm_winapi" }

[target.'cfg(unix)'.dependencies]
libc = "0.2.43"
Expand Down
2 changes: 2 additions & 0 deletions docs/some_common_bugs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Power shell does not interpreter 'DarkYellow' and is instead using gray Winapi.
Arc and manjaro konsole are not seeming to resize the terminal instead they are resizeing the buffer.
9 changes: 6 additions & 3 deletions examples/color/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use self::crossterm::{terminal, Screen};
pub fn paint_foreground() {
// Create a styled object.
// Call the method `with()` on the object given by `style()` and pass in any Color from the Color enum.
let mut styledobject = style("Red foreground").with(Color::Red);
let styledobject = style("Red foreground").with(Color::Red);

// Print the object to the given screen and.
println!("Colored text: {}", styledobject);
Expand All @@ -26,7 +26,7 @@ pub fn paint_foreground() {
pub fn paint_background() {
// Create a styled object.
// Call the method `with()` on the object given by `style()` and pass in any Color from the Color enum.
let mut styledobject = style("Red foreground").on(Color::Red);
let styledobject = style("Red foreground").on(Color::Red);

// Print the object to the given screen and.
println!("Colored text: {}", styledobject);
Expand Down Expand Up @@ -109,7 +109,10 @@ pub fn print_all_foreground_colors() {
);

#[cfg(unix)]
println!("{}", style("RGB color (10,10,10) ").with(Color::AnsiValue(50)));
println!(
"{}",
style("RGB color (10,10,10) ").with(Color::AnsiValue(50))
);
}

/// Print all available foreground colors | demonstration.
Expand Down
14 changes: 8 additions & 6 deletions examples/cursor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ use self::crossterm::Screen;
/// Set the cursor to position X: 10, Y: 5 in the terminal.
pub fn goto() {
// Get the cursor
let mut cursor = cursor();
let cursor = cursor();
// Set the cursor to position X: 10, Y: 5 in the terminal
cursor.goto(10, 5);
}

/// get the cursor position
pub fn pos() {
// Get the cursor
let mut cursor = cursor();
let cursor = cursor();
// get the cursor position.
let (x, y) = cursor.pos();

println!("{} {}", x, y);
}

/// Move the cursor 3 up | demonstration.
Expand Down Expand Up @@ -81,7 +83,7 @@ pub fn move_left() {

/// Save and reset cursor position | demonstration..
pub fn safe_and_reset_position() {
let mut cursor = cursor();
let cursor = cursor();

// Goto X: 5 Y: 5
cursor.goto(5, 5);
Expand All @@ -101,19 +103,19 @@ pub fn safe_and_reset_position() {

/// Hide cursor display | demonstration.
pub fn hide_cursor() {
let mut cursor = cursor();
let cursor = cursor();
cursor.hide();
}

/// Show cursor display | demonstration.
pub fn show_cursor() {
let mut cursor = cursor();
let cursor = cursor();
cursor.show();
}

/// Show cursor display, only works on certain terminals.| demonstration
pub fn blink_cursor() {
let mut cursor = cursor();
let cursor = cursor();
cursor.blink(false);
cursor.blink(false);
}
21 changes: 16 additions & 5 deletions examples/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@
extern crate crossterm;

// modules that could be test
//mod color;
//mod cursor;
//mod input;
mod color;
mod cursor;
mod input;
//mod some_types;
//mod terminal;
mod terminal;

fn main() { }
fn main() {
use input::keyboard::input;

// color::print_all_foreground_colors();
// color::print_all_background_colors();

use terminal::alternate_screen;
// color::print_all_background_colors();
// color::print_all_foreground_colors();

alternate_screen::print_wait_screen_on_alternate_window();
}
6 changes: 3 additions & 3 deletions examples/input/keyboard/async_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ pub fn read_async_until() {
// init some modules we use for this demo
let input = crossterm.input();
let terminal = crossterm.terminal();
let mut cursor = crossterm.cursor();
let cursor = crossterm.cursor();

let mut stdin = input.read_until_async(b'\r').bytes();

for i in 0..100 {
for _i in 0..100 {
terminal.clear(ClearType::All);
cursor.goto(1, 1);
let a = stdin.next();
Expand Down Expand Up @@ -68,7 +68,7 @@ pub fn read_async_demo() {
// init some modules we use for this demo
let input = crossterm.input();
let terminal = crossterm.terminal();
let mut cursor = crossterm.cursor();
let cursor = crossterm.cursor();

// this will setup the async reading.
let mut stdin = input.read_async().bytes();
Expand Down
2 changes: 1 addition & 1 deletion examples/input/keyboard/input.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate crossterm;

use self::crossterm::input::{input, TerminalInput, KeyEvent};
use self::crossterm::input::{input, KeyEvent, TerminalInput};
use self::crossterm::Screen;

pub fn read_char() {
Expand Down
2 changes: 1 addition & 1 deletion examples/program_examples/snake/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn game_over_screen()

terminal.clear(ClearType::All);

println!("{}",messages::END_MESSAGE.join("\n\r"));
println!("{}", crossterm.style(format!("{}",messages::END_MESSAGE.join("\n\r"))).with(Color::Red));
// cursor.goto()
cursor.show();
}
Expand Down
24 changes: 12 additions & 12 deletions examples/terminal/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn print_test_data() {

/// Clear all lines in terminal | demonstration
pub fn clear_all_lines() {
let mut terminal = terminal();
let terminal = terminal();

print_test_data();

Expand All @@ -24,7 +24,7 @@ pub fn clear_all_lines() {

/// Clear all lines from cursor position X:4, Y:4 down | demonstration
pub fn clear_from_cursor_down() {
let mut terminal = terminal();
let terminal = terminal();

print_test_data();

Expand All @@ -37,7 +37,7 @@ pub fn clear_from_cursor_down() {

/// Clear all lines from cursor position X:4, Y:4 up | demonstration
pub fn clear_from_cursor_up() {
let mut terminal = terminal();
let terminal = terminal();

print_test_data();

Expand All @@ -50,20 +50,20 @@ pub fn clear_from_cursor_up() {

/// Clear all lines from cursor position X:4, Y:4 up | demonstration
pub fn clear_current_line() {
let mut terminal = terminal();
let terminal = terminal();

print_test_data();

// Set terminal cursor position (see example for more info).
cursor().goto(4, 4);
cursor().goto(4, 3);

// Clear current line cells.
terminal.clear(ClearType::CurrentLine);
}

/// Clear all lines from cursor position X:4, Y:7 up | demonstration
pub fn clear_until_new_line() {
let mut terminal = terminal();
let terminal = terminal();

print_test_data();

Expand All @@ -76,7 +76,7 @@ pub fn clear_until_new_line() {

/// Print the the current terminal size | demonstration.
pub fn print_terminal_size() {
let mut terminal = terminal();
let terminal = terminal();

// Get terminal size
let (width, height) = terminal.terminal_size();
Expand All @@ -87,14 +87,14 @@ pub fn print_terminal_size() {

/// Set the terminal size to width 10, height: 10 | demonstration.
pub fn set_terminal_size() {
let mut terminal = terminal();
let terminal = terminal();

terminal.set_size(10, 10);
}

/// Scroll down 10 lines | demonstration.
pub fn scroll_down() {
let mut terminal = terminal();
let terminal = terminal();

print_test_data();

Expand All @@ -104,7 +104,7 @@ pub fn scroll_down() {

/// Scroll down 10 lines | demonstration.
pub fn scroll_up() {
let mut terminal = terminal();
let terminal = terminal();

print_test_data();

Expand All @@ -114,14 +114,14 @@ pub fn scroll_up() {

/// Resize the terminal to X: 10, Y: 10 | demonstration.
pub fn resize_terminal() {
let mut terminal = terminal();
let terminal = terminal();

// Get terminal size
terminal.set_size(10, 10);
}

/// exit the current proccess.
pub fn exit() {
let mut terminal = terminal();
let terminal = terminal();
terminal.exit();
}
4 changes: 2 additions & 2 deletions src/common/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub trait IStateCommand {
}

pub trait IEnableAnsiCommand {
fn enable(&self) -> bool;
fn disable(&self) -> bool;
fn enable(&self) -> io::Result<bool>;
fn disable(&self) -> io::Result<()>;
}

// This trait provides an interface for switching to alternate screen and back.
Expand Down
Loading