diff --git a/.github/workflows/crossterm_test.yml b/.github/workflows/crossterm_test.yml deleted file mode 100644 index 01d2ab5..0000000 --- a/.github/workflows/crossterm_test.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Crossterm Test - -on: - push: - branches: - - master -jobs: - linux_mac: - name: Running on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, windows-2019, macOS-10.14] - rust: [stable, nightly] - steps: - - uses: hecrj/setup-rust-action@master - with: - rust-version: ${{ matrix.rust }} - - uses: actions/checkout@master - - name: Run Build - run: cargo build - - name: Check Examples - run: cargo check --examples - - name: Run Tests - run: cargo test -v diff --git a/.gitignore b/.gitignore index d483145..6696b18 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -target/ -.idea/ -.vscode/ +**/target/ +**/.idea/ +**/.vscode/ **/*.rs.bk -Cargo.lock +**/Cargo.lock diff --git a/.travis.yml b/.travis.yml index 4a119fa..978cc69 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,3 @@ -# Set up the Rust toolchain. language: rust rust: @@ -28,5 +27,4 @@ script: - rustc --version - if [ "$TRAVIS_RUST_VERSION" = "stable" ]; then cargo fmt --all -- --check; fi - cargo build - - cargo test --all -- --nocapture --test-threads 1 - - scripts/test-examples.sh + - cargo test --all-features -- --nocapture --test-threads 1 diff --git a/crossterm_cursor/CHANGELOG.md b/CHANGELOG.md similarity index 69% rename from crossterm_cursor/CHANGELOG.md rename to CHANGELOG.md index b53af9e..5ba6ec7 100644 --- a/crossterm_cursor/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ -# Changes crossterm_cursor 0.3 +# Version 0.3.1 + +- Maintenance release only +- Moved to a [separate repository](https://github.com/crossterm-rs/crossterm-cursor) + +# Version 0.3.0 + - `TerminalCursor::pos()` returns `crossterm::Result<(u16, u16)>` - `TerminalCursor::move_*` returns `crossterm::Result` - `TerminalCursor::reset_position()` to `restore_position()` @@ -8,8 +14,10 @@ - `QueueableCommand::queue` returns `crossterm::Result` - Command API takes mutable self instead of self -# Changes crossterm_cursor 0.2 +# Version 0.2.0 + - Removed `TerminalCursor::from_output()` -# Changes crossterm_cursor 0.1 -- Moved out of `crossterm` 5.4 crate. \ No newline at end of file +# Version 0.1.0 + +- Moved out of `crossterm` 5.4 crate. diff --git a/Cargo.toml b/Cargo.toml index 5634b20..6c35d9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,49 +1,19 @@ [package] -name = "crossterm" -version = "0.11.0" +name = "crossterm_cursor" +version = "0.3.1" authors = ["T. Post"] -description = "An crossplatform terminal library for manipulating terminals." -repository = "https://github.com/crossterm-rs/crossterm" -documentation = "https://docs.rs/crossterm/" +description = "A cross-platform library for moving the terminal cursor." +repository = "https://github.com/crossterm-rs/crossterm-cursor" +documentation = "https://docs.rs/crossterm_cursor/" license = "MIT" -keywords = ["console", "color", "cursor", "input", "terminal"] +keywords = ["cursor", "cli", "crossterm", "crossplatform", "terminal"] exclude = ["target", "Cargo.lock"] readme = "README.md" edition = "2018" -[features] -default = ["cursor", "style","terminal","screen","input"] - -cursor = ["crossterm_cursor"] -style = ["crossterm_style"] -terminal = ["crossterm_terminal"] -screen = ["crossterm_screen"] -input = ["crossterm_input"] - -[workspace] - -members = [ - "crossterm_winapi", - "crossterm_utils", - "crossterm_cursor", - "crossterm_style", - "crossterm_terminal", - "crossterm_input", - "crossterm_screen" -] - -exclude = [ - "examples/program_examples" -] +[target.'cfg(windows)'.dependencies] +winapi = { version = "0.3.8", features = ["wincon", "winnt", "minwindef"] } +crossterm_winapi = { version = "0.2.1" } [dependencies] -crossterm_screen = { path = "./crossterm_screen", version = "0.3.0" , optional = true } -crossterm_cursor = { path = "./crossterm_cursor", version = "0.3.0" , optional = true } -crossterm_terminal = { path = "./crossterm_terminal", version = "0.3.0", optional = true } -crossterm_style = { path = "./crossterm_style", version = "0.5.0" , optional = true } -crossterm_input = { path = "./crossterm_input", version = "0.4.0" , optional = true } -crossterm_utils = { path = "./crossterm_utils", version = "0.3.0" , optional = false } - -[lib] -name = "crossterm" -path = "src/lib.rs" +crossterm_utils = { version = "0.3.1" } diff --git a/README.md b/README.md index 4751057..56230f9 100644 --- a/README.md +++ b/README.md @@ -1,78 +1,59 @@ -
+![Lines of Code][s7] [![Latest Version][s1]][l1] [![MIT][s2]][l2] [![docs][s3]][l3] [![Join us on Discord][s5]][l5] -# cross-platform terminal manipulating library. - [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Z8QK6XU749JB2) ![Travis][s7] [![Latest Version][s1]][l1] [![MIT][s2]][l2] [![docs][s3]][l3] ![Lines of Code][s6] [![Join us on Discord][s5]][l5] +# Crossterm Cursor -[s1]: https://img.shields.io/crates/v/crossterm.svg -[l1]: https://crates.io/crates/crossterm +This crate allows you to move the terminal cursor cross-platform. +It supports all UNIX and windows terminals down to windows 7 (not all terminals are tested +see [Tested Terminals](#tested-terminals) for more info) -[s2]: https://img.shields.io/badge/license-MIT-blue.svg -[l2]: crossterm/LICENSE - -[s3]: https://docs.rs/crossterm/badge.svg -[l3]: https://docs.rs/crossterm/ - -[s3]: https://docs.rs/crossterm/badge.svg -[l3]: https://docs.rs/crossterm/ - -[s5]: https://img.shields.io/discord/560857607196377088.svg?logo=discord -[l5]: https://discord.gg/K4nyTDB - -[s6]: https://tokei.rs/b1/github/crossterm-rs/crossterm?category=code -[s7]: https://travis-ci.org/crossterm-rs/crossterm.svg?branch=master +This crate is a sub-crate of [crossterm](https://crates.io/crates/crossterm) to move the cursor, and can be +use individually. -Have you ever been disappointed when a terminal library for rust was only written for UNIX systems? -Crossterm provides clearing, input handling, styling, cursor movement, and terminal actions for both Windows and UNIX systems. - -Crossterm aims to be simple and easy to call in code. -Through the simplicity of Crossterm, you do not have to worry about the platform you are working with. - -This crate supports all UNIX and Windows terminals down to Windows 7 (not all terminals are tested see [Tested Terminals](#tested-terminals) for more info). - -This crate consists of five modules that are provided behind [feature flags](https://crossterm-rs.github.io/crossterm/docs/feature_flags.html) so that you can define which features you'd like to have; by default, all features are enabled. -- [Crossterm Style](https://crates.io/crates/crossterm_style) -- [Crossterm Input](https://crates.io/crates/crossterm_input) -- [Crossterm Screen](https://crates.io/crates/crossterm_screen) -- [Crossterm Cursor](https://crates.io/crates/crossterm_cursor) -- [Crossterm Terminal](https://crates.io/crates/crossterm_terminal) +Other sub-crates are: +- [crossterm_style](https://crates.io/crates/crossterm_style) +- [crossterm_terminal](https://crates.io/crates/crossterm_terminal) +- [crossterm_screen](https://crates.io/crates/crossterm_screen) +- [crossterm_input](https://crates.io/crates/crossterm_input) + +When you want to use other modules as well you might want to use crossterm with +[feature flags](https://crossterm-rs.github.io/crossterm/docs/feature_flags.html). + ## Table of contents: + - [Getting started](#getting-started) - [Useful links](#useful-links) - [Features](#features) - [Examples](#examples) - - [Crossterm Type](#crossterm-type) - - [Styled Text](#styled-text) - - [Cursor](#cursor) - - [Terminal](#terminal) - - [Input Reading](#input-reading) - [Tested Terminals](#tested-terminals) -- [Notice](#notice) -- [Todo](#todo) -- [Contributing](#contributing) - [Authors](#authors) - [License](#license) ## Getting Started -All [examples](https://github.com/crossterm-rs/crossterm/tree/master/examples) of how crossterm works can be found in the example directory. +All examples of how `crossterm_cursor` works can be found in the [examples](https://github.com/crossterm-rs/examples) +repository. -Add the Crossterm package to your `Cargo.toml` file. +Add the `crossterm_cursor` package to your `Cargo.toml` file. ``` [dependencies] -crossterm = "^0.11" +crossterm_cursor = "0.2" +``` +Import the `crossterm_cursor` modules you want to use. + +```rust +pub use crossterm_cursor::{cursor, TerminalCursor}; ``` ### Useful Links -- [Book](https://crossterm-rs.github.io/crossterm/docs//) -- [Documentation](https://docs.rs/crossterm/) -- [Crates.io](https://crates.io/crates/crossterm) -- [Program Examples](https://github.com/crossterm-rs/crossterm/tree/master/examples/program_examples) -- [Examples](https://github.com/crossterm-rs/crossterm/tree/master/examples) +- [Documentation](https://docs.rs/crossterm_cursor/) +- [Crates.io](https://crates.io/crates/crossterm_cursor) +- [Examples](/examples) ## Features +These are the features of this crate: - Cross-platform - Multithreaded (send, sync) @@ -83,81 +64,20 @@ crossterm = "^0.11" - Position (set/get) - Store cursor position and resetting to that later - Hiding/Showing - - Blinking Cursor (supported by only some terminals) -- Styled output - - Foreground Color (16 base colors) - - Background Color (16 base colors) - - 256 (ANSI) Color Support (Windows 10 and UNIX Only) - - RGB Color Support (Windows 10 and UNIX only) - - Text Attributes: bold, italic, underscore and crossed word and [more](https://crossterm-rs.github.io/crossterm/docs//styling.html#attributes) (Windows 10 and UNIX only) -- Terminal - - Clearing (all lines, current line, from cursor down and up, until new line) - - Scrolling (up, down) - - Terminal Size (get/set) - - Alternate Screen - - Raw Screen - - Exit Current Process -- Input - - Read character - - Read line - - Read key input events (async / sync) - - Read mouse input events (press, release, position, button) - -## Examples -These are some basic examples demonstrating how to use this crate. See [examples](https://github.com/crossterm-rs/crossterm/blob/master/examples/) for more. - -### Command API - -My first recommendation is to use the [command API](https://crossterm-rs.github.io/crossterm/docs/command.html) because this might replace some of the existing API in the future. -Because it is more convenient, faster, and easier to use. - -### Styled Text -This module enables you to style the terminal text. - -Good documentation can be found at the following places: [docs](https://docs.rs/crossterm_style/), [book](https://crossterm-rs.github.io/crossterm/docs/styling.html), [examples](https://github.com/crossterm-rs/crossterm/tree/master/examples/key_events.rs) - -_style text with attributes_ -```rust -use crossterm::{Colored, Color, Colorize, Styler, Attribute}; - -// pass any `Attribute` value to the formatting braces. -println!("{} Underlined {} No Underline", Attribute::Underlined, Attribute::NoUnderline); - -// you could also call different attribute methods on a `&str` and keep on chaining if needed. -let styled_text = "Bold Underlined".bold().underlined(); -println!("{}", styled_text); -``` - -_style text with colors_ -```rust -println!("{} Red foreground color", Colored::Fg(Color::Red)); -println!("{} Blue background color", Colored::Bg(Color::Blue)); - -// you can also call different coloring methods on a `&str`. -let styled_text = "Bold Underlined".red().on_blue(); -println!("{}", styled_text); -``` -_style text with RGB and ANSI Value_ -```rust -// custom rgb value (Windows 10 and UNIX systems) -println!("{} some colored text", Colored::Fg(Color::Rgb { - r: 10, - g: 10, - b: 10 -})); - -// custom ansi color value (Windows 10 and UNIX systems) -println!("{} some colored text", Colored::Fg(Color::AnsiValue(10))); -``` + - Blinking Cursor (only some terminals are supporting this) + +## Command API +My first recommendation is to use the [command API](https://crossterm-rs.github.io/crossterm/docs/command.html), +because this might replace some of the existing API in the future. It is more convenient, faster and +easier to use. -### Cursor -This module enables you to work with the terminal cursor. +## Examples -Good documentation could be found on the following places: [docs](https://docs.rs/crossterm_cursor/), [examples](https://github.com/crossterm-rs/crossterm/tree/master/examples/cursor.rs) +The [examples](https://github.com/crossterm-rs/examples) repository has more complete and verbose examples. ```rust -use crossterm::cursor; +use crossterm_cursor::cursor; let mut cursor = cursor(); @@ -193,113 +113,6 @@ cursor.show(); cursor.blink(true) ``` -### Terminal -This module enables you to work with the terminal in general. - -Good documentation could be found on the following places: [docs](https://docs.rs/crossterm_terminal/), [examples](https://github.com/crossterm-rs/crossterm/tree/master/examples/terminal.rs). - -```rust -use crossterm::{terminal,ClearType}; - -let mut terminal = terminal(); - -// Clear all lines in terminal; -terminal.clear(ClearType::All); -// Clear all cells from current cursor position down. -terminal.clear(ClearType::FromCursorDown); -// Clear all cells from current cursor position down. -terminal.clear(ClearType::FromCursorUp); -// Clear current line cells. -terminal.clear(ClearType::CurrentLine); -// Clear all the cells until next line. -terminal.clear(ClearType::UntilNewLine); - -// Get terminal size -let (width, height) = terminal.terminal_size(); -print!("X: {}, y: {}", width, height); - -// Scroll down, up 10 lines. -terminal.scroll_down(10); -terminal.scroll_up(10); - -// Set terminal size (width, height) -terminal.set_size(10,10); - -// exit the current process. -terminal.exit(); - -// write to the terminal whether you are on the main screen or alternate screen. -terminal.write("Some text\n Some text on new line"); -``` - -### Input Reading -This module enables you to read user input events. - -Good documentation could be found on the following places: [docs](https://docs.rs/crossterm_input/), [book](https://crossterm-rs.github.io/crossterm/docs/input.html), [examples](https://github.com/crossterm-rs/crossterm/tree/master/examples/key_events.rs) - -_available imports_ -```rust -use crossterm_input::{ - input, InputEvent, KeyEvent, MouseButton, MouseEvent, TerminalInput, AsyncReader, SyncReader, Screen -}; -``` - -_Simple Readings_ -```rust -let mut input = input(); - - match input.read_char() { - Ok(s) => println!("char typed: {}", s), - Err(e) => println!("char error : {}", e), - } - - match input.read_line() { - Ok(s) => println!("string typed: {}", s), - Err(e) => println!("error: {}", e), - } -``` - -_Read input events synchronously or asynchronously._ -```rust -// 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. -let screen = RawScreen::into_raw_mode(); - -let mut input = input(); - -// either read the input synchronously -let stdin = input.read_sync(); - -// or asynchronously -let stdin = input.read_async(); - -if let Some(key_event) = stdin.next() { - match key_event { - InputEvent::Keyboard(event: KeyEvent) => match event { /* check key event */ } - InputEvent::Mouse(event: MouseEvent) => match event { /* check mouse event */ } - } - } -``` - -_Enable mouse input events._ -```rust -let input = input(); - -// enable mouse events to be captured. -input.enable_mouse_mode().unwrap(); - -// disable mouse events to be captured. -input.disable_mouse_mode().unwrap(); -``` - -### Alternate and Raw Screen -These concepts are a little more complex and would take over the README, please check out the [docs](https://docs.rs/crossterm_screen/), [book](https://crossterm-rs.github.io/crossterm/docs/screen.html), and [examples](https://github.com/crossterm-rs/crossterm/tree/master/examples). - -## Used By -- [Broot](https://dystroy.org/broot/) -- [Cursive](https://github.com/gyscos/Cursive) -- [TUI](https://github.com/fdehau/tui-rs) -- [Rust-sloth](https://github.com/jonathandturner/rust-sloth/tree/crossterm-port) - ## Tested terminals - Windows Powershell @@ -312,24 +125,28 @@ These concepts are a little more complex and would take over the README, please - (Arch, Manjaro) KDE Konsole - Linux Mint -This crate supports all Unix terminals and Windows terminals down to Windows 7; however, not all of the terminals have been tested. -If you have used this library for a terminal other than the above list without issues, then feel free to add it to the above list - I really would appreciate it! - -## Contributing - -I highly appreciate it when you contribute to this crate. -Please visit the discord or issue list for more information +This crate supports all Unix terminals and windows terminals down to Windows 7 but not all of them have been tested. +If you have used this library for a terminal other than the above list without issues feel free to add it to the above list, I really would appreciate it. ## Authors * **Timon Post** - *Project Owner & creator* -## Support +## License -Would you like crossterm to be even more gorgeous and beautiful? You can help with this by donating. +This project is licensed under the MIT License - see the [LICENSE.md](./LICENSE) file for details -[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Z8QK6XU749JB2) -## License +[s1]: https://img.shields.io/crates/v/crossterm_cursor.svg +[l1]: https://crates.io/crates/crossterm_cursor -This project, crossterm and all it's sub-modules: crossterm_screen, crossterm_cursor, crossterm_style, crossterm_input, crossterm_terminal, crossterm_winapi, crossterm_utils are licensed under the MIT License - see the [LICENSE.md](https://github.com/crossterm-rs/crossterm/blob/master/LICENSE) file for details +[s2]: https://img.shields.io/badge/license-MIT-blue.svg +[l2]: ./LICENSE + +[s3]: https://docs.rs/crossterm_cursor/badge.svg +[l3]: https://docs.rs/crossterm_cursor/ + +[s5]: https://img.shields.io/discord/560857607196377088.svg?logo=discord +[l5]: https://discord.gg/K4nyTDB + +[s7]: https://travis-ci.org/crossterm-rs/crossterm.svg?branch=master diff --git a/crossterm_cursor/.gitignore b/crossterm_cursor/.gitignore deleted file mode 100644 index 53eaa21..0000000 --- a/crossterm_cursor/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target -**/*.rs.bk diff --git a/crossterm_cursor/Cargo.toml b/crossterm_cursor/Cargo.toml deleted file mode 100644 index ca93fcb..0000000 --- a/crossterm_cursor/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "crossterm_cursor" -version = "0.3.0" -authors = ["T. Post"] -description = "A cross-platform library for moving the terminal cursor." -repository = "https://github.com/crossterm-rs/crossterm" -documentation = "https://docs.rs/crossterm_cursor/" -license = "MIT" -keywords = ["cursor", "cli", "crossterm", "crossplatform", "terminal"] -exclude = ["target", "Cargo.lock"] -readme = "README.md" -edition = "2018" - -[target.'cfg(windows)'.dependencies] -winapi = { version = "0.3.8", features = ["wincon","winnt","minwindef"] } -crossterm_winapi = { path="../crossterm_winapi", version = "0.2.0"} - -[dependencies] -crossterm_utils = { path="../crossterm_utils", version = "0.3.0"} diff --git a/crossterm_cursor/LICENSE b/crossterm_cursor/LICENSE deleted file mode 100644 index 8b02a7f..0000000 --- a/crossterm_cursor/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2019 Timon - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/crossterm_cursor/README.md b/crossterm_cursor/README.md deleted file mode 100644 index d63754f..0000000 --- a/crossterm_cursor/README.md +++ /dev/null @@ -1,141 +0,0 @@ -# Crossterm Cursor | cross-platform cursor movement. - ![Lines of Code][s7] [![Latest Version][s1]][l1] [![MIT][s2]][l2] [![docs][s3]][l3] [![Join us on Discord][s5]][l5] - -[s1]: https://img.shields.io/crates/v/crossterm_cursor.svg -[l1]: https://crates.io/crates/crossterm_cursor - -[s2]: https://img.shields.io/badge/license-MIT-blue.svg -[l2]: ./LICENSE - -[s3]: https://docs.rs/crossterm_cursor/badge.svg -[l3]: https://docs.rs/crossterm_cursor/ - -[s5]: https://img.shields.io/discord/560857607196377088.svg?logo=discord -[l5]: https://discord.gg/K4nyTDB - -[s7]: https://travis-ci.org/crossterm-rs/crossterm.svg?branch=master - -This crate allows you to move the terminal cursor cross-platform. -It supports all UNIX and windows terminals down to windows 7 (not all terminals are tested see [Tested Terminals](#tested-terminals) for more info) - -This crate is a sub-crate of [crossterm](https://crates.io/crates/crossterm) to move the cursor, and can be use individually. - -Other sub-crates are: -- [Crossterm Style](https://crates.io/crates/crossterm_style) -- [Crossterm Terminal](https://crates.io/crates/crossterm_terminal) -- [Crossterm Screen](https://crates.io/crates/crossterm_screen) -- [Crossterm Input](https://crates.io/crates/crossterm_input) - -When you want to use other modules as well you might want to use crossterm with [feature flags](https://crossterm-rs.github.io/crossterm/docs/feature_flags.html). - -## Table of contents: -- [Getting started](#getting-started) -- [Useful links](#useful-links) -- [Features](#features) -- [Examples](#examples) -- [Tested Terminals](#tested-terminals) -- [Authors](#authors) -- [License](#license) - -## Getting Started - -All examples of how `crossterm_cursor` works can be found in the [examples](https://github.com/crossterm-rs/crossterm/tree/master/examples) directory. - -Add the `crossterm_cursor` package to your `Cargo.toml` file. - -``` -[dependencies] -crossterm_cursor = "0.2" -``` -Import the `crossterm_cursor` modules you want to use. - -```rust -pub use crossterm_cursor::{cursor, TerminalCursor}; -``` - -### Useful Links - -- [Documentation](https://docs.rs/crossterm_cursor/) -- [Crates.io](https://crates.io/crates/crossterm_cursor) -- [Examples](/examples) - -## Features -These are the features of this crate: - -- Cross-platform -- Multithreaded (send, sync) -- Detailed Documentation -- Few Dependencies -- Cursor - - Moving _n_ times (up, down, left, right) - - Position (set/get) - - Store cursor position and resetting to that later - - Hiding/Showing - - Blinking Cursor (only some terminals are supporting this) - -## Command API - -My first recommendation is to use the [command API](https://crossterm-rs.github.io/crossterm/docs/command.html) because this might replace some of the existing API in the future. -Because it is more convenient, faster, and easier to use. - -## Examples -The [examples](https://github.com/crossterm-rs/crossterm/tree/master/examples) folder has more complete and verbose examples. - -```rust -use crossterm_cursor::cursor; - -let mut cursor = cursor(); - -/// Moving the cursor -// Set the cursor to position X: 10, Y: 5 in the terminal -cursor.goto(10,5); - -// Move the cursor up,right,down,left 3 cells. -cursor.move_up(3); -cursor.move_right(3); -cursor.move_down(3); -cursor.move_left(3); - -/// Safe the current cursor position to recall later -// Goto X: 5 Y: 5 -cursor.goto(5,5); -// Safe cursor position: X: 5 Y: 5 -cursor.save_position(); -// Goto X: 5 Y: 20 -cursor.goto(5,20); -// Print at X: 5 Y: 20. -print!("Yea!"); -// Reset back to X: 5 Y: 5. -cursor.restore_position(); -// Print 'Back' at X: 5 Y: 5. -print!("Back"); - -// hide cursor -cursor.hide(); -// show cursor -cursor.show(); -// blink or not blinking of the cursor (not widely supported) -cursor.blink(true) - -``` -## Tested terminals - -- Windows Powershell - - Windows 10 (pro) -- Windows CMD - - Windows 10 (pro) - - Windows 8.1 (N) -- Ubuntu Desktop Terminal - - Ubuntu 17.10 -- (Arch, Manjaro) KDE Konsole -- Linux Mint - -This crate supports all Unix terminals and windows terminals down to Windows 7 but not all of them have been tested. -If you have used this library for a terminal other than the above list without issues feel free to add it to the above list, I really would appreciate it. - -## Authors - -* **Timon Post** - *Project Owner & creator* - -## License -This project is licensed under the MIT License - see the [LICENSE.md](./LICENSE) file for details diff --git a/crossterm_cursor/src/lib.rs b/crossterm_cursor/src/lib.rs deleted file mode 100644 index a267434..0000000 --- a/crossterm_cursor/src/lib.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![deny(unused_imports)] - -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; diff --git a/crossterm_input/.gitignore b/crossterm_input/.gitignore deleted file mode 100644 index 53eaa21..0000000 --- a/crossterm_input/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target -**/*.rs.bk diff --git a/crossterm_input/CHANGELOG.md b/crossterm_input/CHANGELOG.md deleted file mode 100644 index 0dcb44e..0000000 --- a/crossterm_input/CHANGELOG.md +++ /dev/null @@ -1,39 +0,0 @@ -# Changes crossterm_input 0.4.0 -- `TerminalInput::read_line` returns `crossterm::Result` instead of `io::Result` -- `TerminalInput::read_char` returns `crossterm::Result` instead of `io::Result` -- `Command::get_anis_code()` to `ansi_code()` -- Added KeyEvent::Enter and KeyEvent::Tab: [added-key-event-enter], [added-key-event-tab] -- `ExecutableCommand::queue` returns `crossterm::Result` -- `QueueableCommand::queue` returns `crossterm::Result` -- Added derives: Serialize/Deserialize for key events [serde] -- Command API takes mutable self instead of self - -[added-key-event-tab]: https://github.com/crossterm-rs/crossterm/pull/239 -[added-key-event-enter]: https://github.com/crossterm-rs/crossterm/pull/236 -[serde]: https://github.com/crossterm-rs/crossterm/pull/190 - -# Changes crossterm_input 0.3.3 -- Removed println from `SyncReader` - -# Changes crossterm_input 0.3.2 -- Fixed some special key combination detections for UNIX systems -- Windows mouse input event position was 0-based and should be 1-based - -# Changes crossterm_input 0.3.1 -- Updated crossterm_utils - -# Changes crossterm_input 0.3 -- Removed `TerminalInput::from_output()` - -# Changes crossterm_input 0.2.1 -- Fixed SyncReade bug. - -# Changes crossterm_input 0.2.1 -- Introduced SyncReader - -# Changes crossterm_input 0.2 -- Introduced KeyEvents -- Introduced MouseEvents - -# Changes crossterm_input 0.1 -- Moved out of `crossterm` 5.4 crate. \ No newline at end of file diff --git a/crossterm_input/Cargo.toml b/crossterm_input/Cargo.toml deleted file mode 100644 index 2b0c68e..0000000 --- a/crossterm_input/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "crossterm_input" -version = "0.4.0" -authors = ["T. Post"] -description = "A cross-platform library for reading userinput." -repository = "https://github.com/crossterm-rs/crossterm" -documentation = "https://docs.rs/crossterm_input/" -license = "MIT" -keywords = ["input", "keys", "crossterm", "events", "terminal"] -exclude = ["target", "Cargo.lock"] -readme = "README.md" -edition = "2018" - -[target.'cfg(windows)'.dependencies] -winapi = { version = "0.3.8", features = ["winnt", "winuser"] } -crossterm_winapi = { path="../crossterm_winapi", version = "0.2.0"} - -[target.'cfg(unix)'.dependencies] -libc = "0.2.51" - -[dependencies] -crossterm_utils = { path="../crossterm_utils", version = "0.3.0"} -crossterm_screen = {path="../crossterm_screen", version = "0.3.0"} -serde = { version = "1.0", features = ["derive"], optional = true } diff --git a/crossterm_input/LICENSE b/crossterm_input/LICENSE deleted file mode 100644 index 8b02a7f..0000000 --- a/crossterm_input/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2019 Timon - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/crossterm_input/README.md b/crossterm_input/README.md deleted file mode 100644 index 3966641..0000000 --- a/crossterm_input/README.md +++ /dev/null @@ -1,151 +0,0 @@ -# Crossterm Input | cross-platform input reading . - ![Lines of Code][s7] [![Latest Version][s1]][l1] [![MIT][s2]][l2] [![docs][s3]][l3] [![Join us on Discord][s5]][l5] - -[s1]: https://img.shields.io/crates/v/crossterm_input.svg -[l1]: https://crates.io/crates/crossterm_input - -[s2]: https://img.shields.io/badge/license-MIT-blue.svg -[l2]: ./LICENSE - -[s3]: https://docs.rs/crossterm_input/badge.svg -[l3]: https://docs.rs/crossterm_input/ - -[s5]: https://img.shields.io/discord/560857607196377088.svg?logo=discord -[l5]: https://discord.gg/K4nyTDB - -[s7]: https://travis-ci.org/crossterm-rs/crossterm.svg?branch=master - -This crate allows you to read the user input cross-platform. -It supports all UNIX and windows terminals down to windows 7 (not all terminals are tested see [Tested Terminals](#tested-terminals) for more info) - -This crate is a sub-crate of [crossterm](https://crates.io/crates/crossterm) to read the user input and can be used individually. - -Other sub-crates are: -- [Crossterm Style](https://crates.io/crates/crossterm_style) -- [Crossterm Terminal](https://crates.io/crates/crossterm_terminal) -- [Crossterm Screen](https://crates.io/crates/crossterm_screen) -- [Crossterm Cursor](https://crates.io/crates/crossterm_cursor) - -When you want to use other modules as well you might want to use crossterm with [feature flags](https://crossterm-rs.github.io/crossterm/docs/feature_flags.html). - -## Table of contents: -- [Getting started](#getting-started) -- [Useful links](#useful-links) -- [Features](#features) -- [Examples](#examples) -- [Tested Terminals](#tested-terminals) -- [Notice](#notice) -- [Contributing](#contributing) -- [Authors](#authors) -- [License](#license) - -## Getting Started - -All examples of how `crossterm_input` works can be found in the [examples](https://github.com/crossterm-rs/crossterm/tree/master/examples) directory. - -Add the `crossterm_input` package to your `Cargo.toml` file. - -``` -[dependencies] -crossterm_input = "0.3" -``` -Import the `crossterm_input` modules you want to use. - -```rust -pub use crossterm_input::{input, AsyncReader, InputEvent, KeyEvent, MouseButton, MouseEvent, SyncReader, TerminalInput}; -``` - -### Useful Links - -- [Documentation](https://docs.rs/crossterm_input/) -- [Crates.io](https://crates.io/crates/crossterm_input) -- [Book](https://crossterm-rs.github.io/crossterm/docs/input.html) -- [Examples](./examples) - -## Features -These are the features of this crate: - -- Cross-platform -- Multithreaded (send, sync) -- Detailed Documentation -- Few Dependencies -- Input - - Read character - - Read line - - Read key input events (async / sync) - - Read mouse input events (press, release, position, button) - - RawScreen (from `crossterm_screen`) - -## Examples -The [examples](https://github.com/crossterm-rs/crossterm/tree/master/examples) folder has more complete and verbose examples. - -_Simple Readings_ -```rust -let mut input = input(); - - match input.read_char() { - Ok(s) => println!("char typed: {}", s), - Err(e) => println!("char error : {}", e), - } - - match input.read_line() { - Ok(s) => println!("string typed: {}", s), - Err(e) => println!("error: {}", e), - } -``` - -_Read input events synchronously or asynchronously._ -```rust -// 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. -let screen = RawScreen::into_raw_mode(); - -let mut input = input(); - -// either read the input synchronously -let stdin = input.read_sync(); - -// or asynchronously -let stdin = input.read_async(); - -if let Some(key_event) = stdin.next() { - match key_event { - InputEvent::Keyboard(event: KeyEvent) => match event { /* check key event */ } - InputEvent::Mouse(event: MouseEvent) => match event { /* check mouse event */ } - } - } -``` - -_Enable mouse input events._ -```rust -let input = input(); - -// enable mouse events to be captured. -input.enable_mouse_mode().unwrap(); - -// disable mouse events to be captured. -input.disable_mouse_mode().unwrap(); -``` - -## Tested terminals - -- Windows Powershell - - Windows 10 (pro) -- Windows CMD - - Windows 10 (pro) - - Windows 8.1 (N) -- Ubuntu Desktop Terminal - - Ubuntu 17.10 -- (Arch, Manjaro) KDE Konsole -- Linux Mint - -This crate supports all Unix terminals and windows terminals down to Windows 7 but not all of them have been tested. -If you have used this library for a terminal other than the above list without issues feel free to add it to the above list, I really would appreciate it. - -## Authors - -* **Timon Post** - *Project Owner & creator* -* **Dave Ho** - *Contributor* - -## License - -This project is licensed under the MIT License - see the [LICENSE.md](./LICENSE) file for details diff --git a/crossterm_input/src/input.rs b/crossterm_input/src/input.rs deleted file mode 100644 index 4f7cf38..0000000 --- a/crossterm_input/src/input.rs +++ /dev/null @@ -1,119 +0,0 @@ -//! A module that contains all the actions related to reading input from the terminal. -//! Like reading a line, reading a character and reading asynchronously. - -#[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, SyncReader}; -#[cfg(windows)] -pub use self::windows_input::{AsyncReader, SyncReader}; - -mod input; - -#[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 -/// the wishes to work on a specific platform. -/// -/// ## For example: -/// -/// This trait is implemented for Windows and UNIX systems. -/// Unix is using the 'TTY' and windows is using 'libc' C functions to read the input. -trait ITerminalInput { - /// Read one character from the user input - fn read_char(&self) -> Result