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

io::Result cleanup #232

Merged
merged 8 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Remove pub from all examples and allow dead_code
Signed-off-by: Robert Vojta <rvojta@me.com>
  • Loading branch information
zrzka committed Sep 18, 2019
commit 64db7772659bc076186822c5ce6e597c7d9e077a
10 changes: 6 additions & 4 deletions examples/command.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#![allow(dead_code)]

use std::io::{stdout, Write};

use crossterm::{
execute, queue, Clear, ClearType, ExecutableCommand, Goto, Output, QueueableCommand, Result,
};

/// execute commands by using normal functions
pub fn execute_command_directly_using_functions() -> Result<()> {
fn execute_command_directly_using_functions() -> Result<()> {
// single command
stdout().execute(Output("Text1 ".to_string()))?;

Expand All @@ -18,7 +20,7 @@ pub fn execute_command_directly_using_functions() -> Result<()> {
}

/// execute commands by using macro's
pub fn execute_command_directly_using_macros() -> Result<()> {
fn execute_command_directly_using_macros() -> Result<()> {
// single command
execute!(stdout(), Output("Text1 ".to_string()))?;

Expand All @@ -31,7 +33,7 @@ pub fn execute_command_directly_using_macros() -> Result<()> {
}

/// queue commands without executing them directly by using normal functions
pub fn later_execution_command_using_functions() -> Result<()> {
fn later_execution_command_using_functions() -> Result<()> {
let mut sdout = stdout();

// single command
Expand All @@ -54,7 +56,7 @@ pub fn later_execution_command_using_functions() -> Result<()> {
}

/// queue commands without executing them directly by using macro's
pub fn later_execution_command_directly_using_macros() -> Result<()> {
fn later_execution_command_directly_using_macros() -> Result<()> {
let mut stdout = stdout();

// single command
Expand Down
20 changes: 11 additions & 9 deletions examples/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
//! Examples of actions that could be performed with the cursor.
//!

#![allow(dead_code)]

use crossterm::{cursor, Result};

/// Set the cursor to position X: 10, Y: 5 in the terminal.
pub fn goto() -> Result<()> {
fn goto() -> Result<()> {
// Get the cursor
let cursor = cursor();
// Set the cursor to position X: 10, Y: 5 in the terminal
Expand All @@ -15,7 +17,7 @@ pub fn goto() -> Result<()> {
}

/// get the cursor position
pub fn pos() {
fn pos() {
// Get the cursor
let cursor = cursor();
// get the cursor position.
Expand All @@ -25,7 +27,7 @@ pub fn pos() {
}

/// Move the cursor 3 up | demonstration.
pub fn move_up() {
fn move_up() {
// Get the cursor
let mut cursor = cursor();

Expand All @@ -34,21 +36,21 @@ pub fn move_up() {
}

/// Move the cursor 3 to the right | demonstration.
pub fn move_right() {
fn move_right() {
let mut cursor = cursor();
// Move the cursor to position 3 times to the right in the terminal
cursor.move_right(3);
}

/// Move the cursor 3 down | demonstration.
pub fn move_down() {
fn move_down() {
let mut cursor = cursor();
// Move the cursor to position 3 times to the down in the terminal
cursor.move_down(3);
}

/// Save and reset cursor position | demonstration..
pub fn save_and_reset_position() -> Result<()> {
fn save_and_reset_position() -> Result<()> {
let cursor = cursor();

// Goto X: 5 Y: 5
Expand All @@ -70,19 +72,19 @@ pub fn save_and_reset_position() -> Result<()> {
}

/// Hide cursor display | demonstration.
pub fn hide_cursor() -> Result<()> {
fn hide_cursor() -> Result<()> {
let cursor = cursor();
cursor.hide()
}

/// Show cursor display | demonstration.
pub fn show_cursor() -> Result<()> {
fn show_cursor() -> Result<()> {
let cursor = cursor();
cursor.show()
}

/// Show cursor display, only works on certain terminals.| demonstration
pub fn blink_cursor(enable: bool) -> Result<()> {
fn blink_cursor(enable: bool) -> Result<()> {
let cursor = cursor();
cursor.blink(enable)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/input.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crossterm::input;

pub fn read_char() {
fn read_char() {
let input = input();

match input.read_char() {
Expand All @@ -9,7 +9,7 @@ pub fn read_char() {
}
}

pub fn read_line() {
fn read_line() {
let input = input();

match input.read_line() {
Expand Down
2 changes: 2 additions & 0 deletions examples/key_events.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

use std::{thread, time::Duration};

use crossterm::{input, InputEvent, KeyEvent, MouseButton, MouseEvent, RawScreen, Result};
Expand Down
23 changes: 13 additions & 10 deletions examples/style.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
//!
//! Examples of coloring the terminal.
//!

#![allow(dead_code)]

use crossterm::{color, Attribute, Color, Colored, Colorize, Styler};

/// print some red text | demonstration.
pub fn paint_foreground() {
fn paint_foreground() {
println!("{}", "Red foreground text: {}".red());
println!("{} Red foreground text", Colored::Fg(Color::Red));
}

/// print some text on red background | demonstration.
pub fn paint_background() {
fn paint_background() {
println!("{}", "Red background text: {}".on_red());
println!("{} Red background text", Colored::Bg(Color::Red));
}

/// Print all available foreground colors | demonstration.
pub fn print_all_foreground_colors_with_enum() {
fn print_all_foreground_colors_with_enum() {
// we use `Reset` to restore the foreground back to normal at the end of the line.
println!(
"Black : \t\t {} ■ {}\n",
Expand Down Expand Up @@ -114,7 +117,7 @@ pub fn print_all_foreground_colors_with_enum() {
}

/// Print all available foreground colors | demonstration.
pub fn print_all_foreground_colors_with_method() {
fn print_all_foreground_colors_with_method() {
println!(
"Black : \t\t {} {}\n",
"■".black(),
Expand Down Expand Up @@ -182,7 +185,7 @@ pub fn print_all_foreground_colors_with_method() {
}

/// Print all available foreground colors | demonstration.
pub fn print_all_background_colors_with_enum() {
fn print_all_background_colors_with_enum() {
println!(
"Black : \t\t {} ■ {}\n",
Colored::Bg(Color::Black),
Expand Down Expand Up @@ -279,7 +282,7 @@ pub fn print_all_background_colors_with_enum() {
}

/// Print all available foreground colors | demonstration.
pub fn print_all_background_colors_with_method() {
fn print_all_background_colors_with_method() {
println!(
"Black : \t\t {} {}\n",
"■".on_black(),
Expand Down Expand Up @@ -364,7 +367,7 @@ pub fn print_all_background_colors_with_method() {

/// Print text 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_text_with_attributes() {
fn print_text_with_attributes() {
println!("{}", "Normal text");
println!("{}", "Bold text".bold());
println!("{}", "Italic text".italic());
Expand All @@ -387,23 +390,23 @@ pub fn print_text_with_attributes() {

// Print text with all available attributes. Note that this can only be used at unix systems and that some are not supported widely | demonstration..
#[cfg(windows)]
pub fn print_text_with_attributes() {
fn print_text_with_attributes() {
println!("{}", "Normal text");
println!("{}", "Bold text".bold());
println!("{}", "Underlined text".underlined());
println!("{}", "Negative text".negative());
}

/// Print all supported RGB colors, not supported for Windows systems < 10 | demonstration.
pub fn print_supported_colors() {
fn print_supported_colors() {
let count = color().get_available_color_count().unwrap();

for i in 0..count {
println!("Test {}", Colored::Bg(Color::AnsiValue(i as u8)));
}
}

pub fn reset_fg_and_bg() {
fn reset_fg_and_bg() {
println!("{}", Colored::Fg(Color::Reset));
println!("{}", Colored::Bg(Color::Reset));
}
Expand Down
22 changes: 12 additions & 10 deletions examples/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//! Terminal Examples
//!

#![allow(dead_code)]

use crossterm::{cursor, terminal, ClearType, Result};

fn print_test_data() {
Expand All @@ -11,7 +13,7 @@ fn print_test_data() {
}

/// Clear all lines in terminal | demonstration
pub fn clear_all_lines() -> Result<()> {
fn clear_all_lines() -> Result<()> {
let terminal = terminal();

print_test_data();
Expand All @@ -21,7 +23,7 @@ pub fn clear_all_lines() -> Result<()> {
}

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

print_test_data();
Expand All @@ -34,7 +36,7 @@ pub fn clear_from_cursor_down() -> Result<()> {
}

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

print_test_data();
Expand All @@ -47,7 +49,7 @@ pub fn clear_from_cursor_up() -> Result<()> {
}

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

print_test_data();
Expand All @@ -60,7 +62,7 @@ pub fn clear_current_line() -> Result<()> {
}

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

print_test_data();
Expand All @@ -73,7 +75,7 @@ pub fn clear_until_new_line() -> Result<()> {
}

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

// Get terminal size
Expand All @@ -84,14 +86,14 @@ pub fn print_terminal_size() {
}

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

terminal.set_size(10, 10)
}

/// Scroll down 10 lines | demonstration.
pub fn scroll_down() -> Result<()> {
fn scroll_down() -> Result<()> {
let terminal = terminal();

print_test_data();
Expand All @@ -101,7 +103,7 @@ pub fn scroll_down() -> Result<()> {
}

/// Scroll down 10 lines | demonstration.
pub fn scroll_up() -> Result<()> {
fn scroll_up() -> Result<()> {
let terminal = terminal();

print_test_data();
Expand All @@ -111,7 +113,7 @@ pub fn scroll_up() -> Result<()> {
}

/// exit the current proccess.
pub fn exit() {
fn exit() {
let terminal = terminal();
terminal.exit();
}
Expand Down