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

2018 edition #222

Merged
merged 18 commits into from
Sep 16, 2019
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
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,12 @@ script:
- if [ "$TRAVIS_RUST_VERSION" = "stable" ]; then cargo fmt --all -- --check; fi
- cargo build
- if [ "$TRAVIS_OS_NAME" = "windows" ]; then cargo test --all -- --nocapture --test-threads 1; else cargo test --all --exclude crossterm_winapi -- --nocapture --test-threads 1; fi
- |
pushd examples/program_examples
for d in */ ; do
pushd "$d"
cargo build
if [ "$TRAVIS_RUST_VERSION" = "stable" ]; then cargo fmt --all -- --check; fi
popd
done
popd
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license = "MIT"
keywords = ["console", "color", "cursor", "input", "terminal"]
exclude = ["target", "Cargo.lock"]
readme = "README.md"
edition = "2018"

[features]
default = ["cursor", "style","terminal","screen","input"]
Expand Down
2 changes: 0 additions & 2 deletions crossterm_cursor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ crossterm_cursor = "0.2"
Import the `crossterm_cursor` modules you want to use.

```rust
extern crate crossterm_cursor;

pub use crossterm_cursor::{cursor, TerminalCursor};
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@
//!
#![allow(unused_must_use, dead_code)]

extern crate crossterm_cursor;

use std::io::Write;
use std::time::Instant;

use crossterm_cursor::cursor;

use self::crossterm_cursor::{queue, Goto, Hide, Output, QueueableCommand};
use crossterm_cursor::{cursor, queue, Goto, Hide, Output, QueueableCommand};

/// Set the cursor to position X: 10, Y: 5 in the terminal.
pub fn goto() {
fn goto() {
// Get the 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() {
fn pos() {
// Get the cursor
let cursor = cursor();
// get the cursor position.
Expand All @@ -31,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 @@ -40,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() {
fn save_and_reset_position() {
let cursor = cursor();

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

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

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

/// Show cursor display, only works on certain terminals.| demonstration
pub fn blink_cursor() {
fn blink_cursor() {
let cursor = cursor();
cursor.blink(false);
cursor.blink(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
//!
//! Note that positions of the cursor are 0 -based witch means that the coordinates (cells) starts counting from 0

use crossterm_utils::Result;

use self::ansi_cursor::AnsiCursor;
pub use self::cursor::{
cursor, BlinkOff, BlinkOn, Down, Goto, Hide, Left, ResetPos, Right, SavePos, Show,
TerminalCursor, Up,
};
#[cfg(windows)]
use self::winapi_cursor::WinApiCursor;

mod cursor;

#[cfg(test)]
Expand All @@ -12,17 +22,6 @@ mod ansi_cursor;
#[cfg(windows)]
mod winapi_cursor;

use self::ansi_cursor::AnsiCursor;
#[cfg(windows)]
use self::winapi_cursor::WinApiCursor;

pub use self::cursor::{
cursor, BlinkOff, BlinkOn, Down, Goto, Hide, Left, ResetPos, Right, SavePos, Show,
TerminalCursor, Up,
};

use crossterm_utils::Result;

///! This trait defines the actions that can be performed with the terminal cursor.
///! This trait can be implemented so that a concrete implementation of the ITerminalCursor can fulfill
///! the wishes to work on a specific platform.
Expand Down
5 changes: 3 additions & 2 deletions crossterm_cursor/src/cursor/ansi_cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
//! This module is used for windows 10 terminals and UNIX terminals by default.
//! Note that the cursor position is 0 based. This means that we start counting at 0 when setting the cursor position etc.

use super::ITerminalCursor;
use crossterm_utils::{csi, write_cout, Result};

use crate::sys::{get_cursor_position, show_cursor};

use crossterm_utils::{write_cout, Result};
use super::ITerminalCursor;

#[inline]
pub fn get_goto_ansi(x: u16, y: u16) -> String {
Expand Down
7 changes: 3 additions & 4 deletions crossterm_cursor/src/cursor/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
//! A module that contains all the actions related to cursor movement in the terminal.
//! Like: moving the cursor position; saving and resetting the cursor position; hiding showing and control the blinking of the cursor.

use super::*;

use crossterm_utils::{Command, Result};

#[cfg(windows)]
use crossterm_utils::supports_ansi;
use crossterm_utils::{impl_display, Command, Result};

use super::*;

/// Allows you to preform actions with the terminal cursor.
///
Expand Down
3 changes: 2 additions & 1 deletion crossterm_cursor/src/cursor/test.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#![allow(unused_must_use)]

use super::AnsiCursor;
use super::ITerminalCursor;

/* ======================== WinApi =========================== */
#[cfg(windows)]
mod winapi_tests {

use super::super::WinApiCursor;
use super::*;

#[test]
fn goto_winapi() {
let cursor = WinApiCursor::new();
Expand Down
6 changes: 4 additions & 2 deletions crossterm_cursor/src/cursor/winapi_cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
//! This module is used for Windows terminals that do not support ANSI escape codes.
//! Note that the cursor position is 0 based. This means that we start counting at 0 when setting the cursor position.

use super::ITerminalCursor;
use crate::sys::winapi::{Cursor, Handle};
use crossterm_utils::Result;

use crate::sys::winapi::{Cursor, Handle};

use super::ITerminalCursor;

/// This struct is a windows implementation for cursor related actions.
pub struct WinApiCursor;

Expand Down
15 changes: 5 additions & 10 deletions crossterm_cursor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
#[macro_use]
extern crate crossterm_utils;

#[cfg(windows)]
extern crate winapi;

mod cursor;
pub mod sys;

pub use self::crossterm_utils::{
pub use crossterm_utils::{
execute, queue, Command, ErrorKind, ExecutableCommand, Output, QueueableCommand, Result,
};

pub use self::cursor::{
cursor, BlinkOff, BlinkOn, Down, Goto, Hide, Left, ResetPos, Right, SavePos, Show,
TerminalCursor, Up,
};

mod cursor;
pub mod sys;
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#[cfg(unix)]
pub mod unix;

#[cfg(windows)]
pub mod winapi;

#[cfg(unix)]
pub use self::unix::get_cursor_position;
#[cfg(unix)]
pub use self::unix::show_cursor;
#[cfg(windows)]
pub use self::winapi::get_cursor_position;
#[cfg(windows)]
pub use self::winapi::show_cursor;

#[cfg(unix)]
pub use self::unix::show_cursor;
pub mod unix;

#[cfg(windows)]
pub use self::winapi::show_cursor;
pub mod winapi;
6 changes: 4 additions & 2 deletions crossterm_cursor/src/sys/unix.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::io::{self, BufRead, Write};

use crossterm_utils::{
csi,
sys::unix::{self, RAW_MODE_ENABLED},
Result,
write_cout, Result,
};
use std::io::{self, BufRead, Write};

#[cfg(unix)]
pub fn get_cursor_position() -> (u16, u16) {
Expand Down
2 changes: 0 additions & 2 deletions crossterm_input/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ crossterm_input = "0.3"
Import the `crossterm_input` modules you want to use.

```rust
extern crate crossterm_input;

pub use crossterm_input::{input, AsyncReader, InputEvent, KeyEvent, MouseButton, MouseEvent, SyncReader, TerminalInput};
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
extern crate crossterm_input;
use crossterm_input::input;

use self::crossterm_input::input;

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

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

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

match input.read_line() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
extern crate crossterm_input;
extern crate crossterm_screen;
#![allow(dead_code)]

use crossterm_input::{input, InputEvent, KeyEvent, MouseButton, MouseEvent, RawScreen};
use std::{thread, time::Duration};

use crossterm_input::{input, InputEvent, KeyEvent, MouseButton, MouseEvent, RawScreen};

fn process_input_event(key_event: InputEvent) -> bool {
match key_event {
InputEvent::Keyboard(k) => {
Expand Down Expand Up @@ -76,7 +76,7 @@ fn process_input_event(key_event: InputEvent) -> bool {
return false;
}

pub fn read_asynchronously() {
fn read_asynchronously() {
// make sure to enable raw mode, this will make sure key events won't be handled by the terminal it's self and allows crossterm to read the input and pass it back to you.
if let Ok(_raw) = RawScreen::into_raw_mode() {
let input = input();
Expand All @@ -100,7 +100,7 @@ pub fn read_asynchronously() {
} // <=== raw modes will be disabled here
} // <=== background reader will be disposed when dropped.

pub fn read_synchronously() {
fn read_synchronously() {
// make sure to enable raw mode, this will make sure key events won't be handled by the terminal it's self and allows crossterm to read the input and pass it back to you.
if let Ok(_raw) = RawScreen::into_raw_mode() {
let input = input();
Expand Down
30 changes: 15 additions & 15 deletions crossterm_input/src/input/mod.rs → crossterm_input/src/input.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
//! A module that contains all the actions related to reading input from the terminal.
//! Like reading a line, reading a character and reading asynchronously.

mod input;
use std::io;
use std::sync::{
mpsc::{Receiver, Sender},
Arc,
};

#[cfg(unix)]
mod unix_input;
#[cfg(windows)]
mod windows_input;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use crossterm_utils::Result;

pub use self::input::{input, TerminalInput};
#[cfg(unix)]
pub use self::unix_input::AsyncReader;
#[cfg(unix)]
pub use self::unix_input::SyncReader;
#[cfg(unix)]
use self::unix_input::UnixInput;

#[cfg(windows)]
pub use self::windows_input::AsyncReader;
#[cfg(windows)]
pub use self::windows_input::SyncReader;
#[cfg(windows)]
use self::windows_input::WindowsInput;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
mod input;

pub use self::input::{input, TerminalInput};
use crossterm_utils::Result;
use std::io;
use std::sync::{
mpsc::{Receiver, Sender},
Arc,
};
#[cfg(unix)]
mod unix_input;
#[cfg(windows)]
mod windows_input;

/// This trait defines the actions that can be performed with the terminal input.
/// This trait can be implemented so that a concrete implementation of the ITerminalInput can fulfill
Expand Down
3 changes: 2 additions & 1 deletion crossterm_input/src/input/input.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! A module that contains all the actions related to reading input from the terminal.
//! Like reading a line, reading a character and reading asynchronously.

use super::*;
use std::io;

use super::*;

/// Allows you to read user input.
///
/// # Features:
Expand Down
Loading