Skip to content

Commit

Permalink
Issue #3 and #4 are now solved, windows tested unix not yet
Browse files Browse the repository at this point in the history
  • Loading branch information
TimonPost committed Jan 30, 2018
1 parent 93bc97c commit 4212e72
Show file tree
Hide file tree
Showing 17 changed files with 442 additions and 335 deletions.
489 changes: 312 additions & 177 deletions .idea/workspace.xml

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions examples/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
extern crate crossterm;

// Add the usings for the crossterms modules to play with crossterm
use self::crossterm::crossterm_style;
use self::crossterm::crossterm_style::{paint, Color };
use self::crossterm::crossterm_cursor;
use self::crossterm::crossterm_terminal;

Expand All @@ -25,5 +25,6 @@ pub mod cursor;
pub mod terminal;

fn main() {

terminal::clear_all_lines();
cursor::print();
}
4 changes: 2 additions & 2 deletions examples/color/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub fn print_all_background_colors()
println!("RGB (10,10,10): \t {}", paint(" ").on(Color::AnsiValue(50)));
}

/// Print font with all available attributes. Note that this can only be used at unix systems and that some are not supported widely.
/// Print font with all available attributes. Note that this can only be used at unix systems and that some are not supported widely | demonstration..
#[cfg(unix)]
pub fn print_font_with_attributes()
{
Expand All @@ -119,7 +119,7 @@ pub fn print_font_with_attributes()
println!("{}", paint("Crossed out font").crossed_out());
}

/// Print all supported rgb colors
/// Print all supported rgb colors | demonstration.
#[cfg(unix)]#[cfg(unix)]
pub fn print_supported_colors()
{
Expand Down
30 changes: 15 additions & 15 deletions examples/cursor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
extern crate crossterm;

use self::crossterm::crossterm_cursor::{get, TerminalCursor};
use self::crossterm::crossterm_cursor::{cursor, TerminalCursor};

/// Set the cursor to position X: 10, Y: 5 in the terminal.
pub fn goto()
{
// Get the cursor
let mut cursor = get();
let mut cursor = cursor();
// Set the cursor to position X: 10, Y: 5 in the terminal
cursor.goto(10,5);
}
Expand All @@ -19,7 +19,7 @@ pub fn goto()
pub fn move_up()
{
// Get the cursor
let mut cursor = get();
let mut cursor = cursor();
// Move the cursor to position 3 times to the up in the terminal
cursor.move_up(3);
}
Expand All @@ -28,7 +28,7 @@ pub fn move_up()
pub fn move_right()
{
// Get the cursor
let mut cursor = get();
let mut cursor = cursor();
// Move the cursor to position 3 times to the right in the terminal
cursor.move_right(3);
}
Expand All @@ -37,7 +37,7 @@ pub fn move_right()
pub fn move_down()
{
// Get the cursor
let mut cursor = get();
let mut cursor = cursor();
// Move the cursor to position 3 times to the down in the terminal
cursor.move_down(3);
}
Expand All @@ -46,7 +46,7 @@ pub fn move_down()
pub fn move_left()
{
// Get the cursor
let mut cursor = get();
let mut cursor = cursor();
// Move the cursor to position 3 times to the left in the terminal
cursor.move_left(3);
}
Expand All @@ -57,7 +57,7 @@ pub fn print()
// To print an some displayable content on an certain position.

// Get the cursor
let mut cursor = get();
let mut cursor = cursor();
// Set the cursor to position X: 10, Y: 5 in the terminal
cursor.goto(10,5);
// Print the @ symbol at position X: 10, Y: 5 in the terminal
Expand All @@ -67,32 +67,32 @@ pub fn print()
use std::io::Write;
std::io::stdout().flush();

/* Because the above method is a little to mutch code,
/* Because the above method is a little to much code,
you can use the `print()` method for printing an value at an certain position in the terminal.
Crossterm provides method chaining so that the above points can be inlined.
*/
get().goto(10,5).print("@");

cursor.goto(10,5).print("@");
}

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

// Goto X: 5 Y: 5
cursor.goto(5,5);
// Safe cursor position: X: 5 Y: 5
cursor.safe_position();
cursor.save_position();
// Goto X: 5 Y: 20
cursor.goto(5,20);
// Print at X: 5 Y: 20.
print!("Yea!");
println!("Yea!");
// Reset back to X: 5 Y: 5.
cursor.reset_position();
// Print Back at X: 5 Y: 5.
print!("Back");
println!("Back");

println!()
}
Expand Down
45 changes: 23 additions & 22 deletions examples/terminal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
extern crate crossterm;

use crossterm::crossterm_terminal::{get, Terminal, ClearType};
use crossterm::crossterm_terminal::{ Terminal, ClearType, terminal};
use crossterm::crossterm_cursor;

fn print_test_data()
{
for i in 0..100 {
println!("abcdefghijTest data to test terminal: {}",i);
println!("Test data to test terminal: {}",i);
}
}

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

print_test_data();

Expand All @@ -30,12 +30,12 @@ pub fn clear_all_lines()
pub fn clear_from_cursor_down()
{
// Get terminal
let mut terminal = get();
let mut terminal = terminal();

print_test_data();

// Set terminal cursor position (see example for more info).
crossterm_cursor::get().goto(4,8);
crossterm_cursor::cursor().goto(4,8);

// Clear all cells from current cursor position down.
terminal.clear(ClearType::FromCursorDown);
Expand All @@ -45,12 +45,12 @@ pub fn clear_from_cursor_down()
pub fn clear_from_cursor_up()
{
// Get terminal
let mut terminal = get();
let mut terminal = terminal();

print_test_data();

// Set terminal cursor position (see example for more info).
crossterm_cursor::get().goto(4,8);
crossterm_cursor::cursor().goto(4,4);

// Clear all cells from current cursor position down.
terminal.clear(ClearType::FromCursorUp);
Expand All @@ -60,76 +60,77 @@ pub fn clear_from_cursor_up()
pub fn clear_current_line()
{
// Get terminal
let mut terminal = get();
let mut terminal = terminal();

print_test_data();

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

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

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

print_test_data();

// Set terminal cursor position (see example for more info).
crossterm_cursor::get().goto(4,7);
crossterm_cursor::cursor().goto(4,7);

// Clear all the cells until next line.
terminal.clear(ClearType::UntilNewLine);
}

/// Print the the current terminal size | demonstration.
pub fn print_terminal_size()
{
// Get terminal
let mut terminal = get();
let mut terminal = terminal();
// Get terminal size
let terminal_size = terminal.terminal_size().unwrap();
// Print results
print!("X: {}, y: {}", terminal_size.0, terminal_size.1);
}

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

terminal.set_size(10,10);
}

// scroll down 10 lines
/// Scroll down 10 lines | demonstration.
pub fn scroll_down()
{
print_test_data();
// Get terminal
let mut terminal = get();
let mut terminal = terminal();
// Scroll down 10 lines.
terminal.scroll_down(10);
}

// scroll down 10 lines
/// Scroll down 10 lines | demonstration.
pub fn scroll_up()
{
print_test_data();

// Get terminal
let mut terminal = get();
let mut terminal = terminal();
// Scroll up 10 lines.
terminal.scroll_up(10);
}

// Resize the terminal to X: 10, Y: 10
/// Resize the terminal to X: 10, Y: 10 | demonstration.
pub fn resize_terminal()
{
// Get terminal
let mut terminal = get();
let mut terminal = terminal();
// Get terminal size
terminal.set_size(1,1);
terminal.set_size(10,10);
}
2 changes: 1 addition & 1 deletion src/crossterm_cursor/ansi_cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl ITerminalCursor for AnsiCursor {
write!(&mut some_writer, csi!("{}D"), count);
}

fn safe_position(&mut self)
fn save_position(&mut self)
{
let mut some_writer = io::stdout();
write!(&mut some_writer, csi!("s"));
Expand Down
2 changes: 1 addition & 1 deletion src/crossterm_cursor/base_cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub trait ITerminalCursor {
/// Move the cursor `n` times left.
fn move_left(&self, count: u16);
/// Save cursor position for recall later. Note that this position is stored program based not per instance of the cursor struct.
fn safe_position(&mut self);
fn save_position(&mut self);
/// Return to saved cursor position
fn reset_position(&self);
}
Loading

0 comments on commit 4212e72

Please sign in to comment.