2019-09-25 03:45:59 +10:00
< h1 align = "center" > < img width = "440" src = "docs/crossterm_full.png" / > < / h1 >
2019-09-26 00:09:16 +10:00
[![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]
2018-07-15 07:37:21 +10:00
2019-10-02 16:49:01 +10:00
# Cross-platform Terminal Manipulation Library
2019-09-13 05:39:39 +10:00
2020-04-11 03:09:14 +10:00
Crossterm is a pure-rust, terminal manipulation library that makes it possible to write cross-platform text-based interfaces (see [features ](#features )). It supports all UNIX and Windows terminals down to Windows 7 (not all terminals are tested,
2019-09-26 00:09:16 +10:00
see [Tested Terminals ](#tested-terminals ) for more info).
2018-07-31 05:35:35 +10:00
2019-10-02 16:49:01 +10:00
## Table of Contents
2018-07-31 05:35:35 +10:00
2019-10-02 16:49:01 +10:00
* [Features ](#features )
* [Tested Terminals ](#tested-terminals )
* [Getting Started ](#getting-started )
* [Feature Flags ](#feature-flags )
* [Other Resources ](#other-resources )
* [Used By ](#used-by )
* [Contributing ](#contributing )
2018-07-31 05:35:35 +10:00
2018-09-23 06:55:30 +10:00
## Features
2018-07-31 05:35:35 +10:00
2018-11-26 00:17:11 +11:00
- Cross-platform
2019-09-26 00:09:16 +10:00
- Multi-threaded (send, sync)
2019-10-02 16:49:01 +10:00
- Detailed documentation
- Few dependencies
2019-12-13 17:12:35 +11:00
- Full control over writing and flushing output buffer
2020-03-29 04:38:07 +11:00
- Is tty
2019-12-13 17:12:35 +11:00
- Cursor
2019-10-02 16:49:01 +10:00
- Move the cursor N times (up, down, left, right)
2019-12-13 17:12:35 +11:00
- Move to previous / next line
- Move to column
2019-10-02 16:49:01 +10:00
- Set/get the cursor position
- Store the cursor position and restore to it later
- Hide/show the cursor
- Enable/disable cursor blinking (not all terminals do support this feature)
2019-12-13 17:12:35 +11:00
- Styled output
2019-10-02 16:49:01 +10:00
- 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)
2019-12-13 17:12:35 +11:00
- Text attributes like bold, italic, underscore, crossed, etc
- Terminal
2019-10-02 16:49:01 +10:00
- Clear (all lines, current line, from cursor down and up, until new line)
- Scroll up, down
- Set/get the terminal size
- Exit current process
- Alternate screen
- Raw screen
2020-05-23 21:29:56 +10:00
- Set terminal title
2020-04-11 03:10:09 +10:00
- Event
2019-12-13 17:12:35 +11:00
- Input Events
- Mouse Events (press, release, position, button, drag)
- Terminal Resize Events
- Advanced modifier (SHIFT | ALT | CTRL) support for both mouse and key events and
- futures Stream (feature 'event-stream')
- Poll/read API
2019-10-02 16:49:01 +10:00
<!--
WARNING: Do not change following heading title as it's used in the URL by other crates!
-->
2019-03-22 02:00:30 +11:00
2019-10-02 16:49:01 +10:00
### Tested Terminals
2019-09-26 00:09:16 +10:00
2020-05-20 02:30:31 +10:00
- Console Host
2019-10-02 16:49:01 +10:00
- Windows 10 (Pro)
- Windows 8.1 (N)
- Ubuntu Desktop Terminal
- Ubuntu 17.10
- (Arch, Manjaro) KDE Konsole
2020-05-19 03:13:34 +10:00
- (Arch) Kitty
2019-10-02 16:49:01 +10:00
- Linux Mint
2019-03-22 02:00:30 +11:00
2019-10-02 16:49:01 +10:00
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!
2019-03-22 02:00:30 +11:00
2019-10-02 16:49:01 +10:00
## Getting Started
2020-04-11 03:13:29 +10:00
_see the [examples directory ](examples/ ) and [documentation ](https://docs.rs/crossterm/ ) for more advanced examples._
2019-09-26 00:09:16 +10:00
2019-10-02 16:49:01 +10:00
< details >
< summary >
Click to show Cargo.toml.
< / summary >
2019-03-22 02:00:30 +11:00
2019-10-02 16:49:01 +10:00
```toml
[dependencies]
2020-03-25 08:00:23 +11:00
crossterm = "0.17"
2019-03-22 02:00:30 +11:00
```
2019-09-26 00:09:16 +10:00
2019-10-02 16:49:01 +10:00
< / details >
< p > < / p >
2019-09-26 00:09:16 +10:00
2019-03-22 02:00:30 +11:00
```rust
2019-10-02 16:49:01 +10:00
use std::io::{stdout, Write};
2019-12-15 05:26:20 +11:00
use crossterm::{
execute,
style::{Color, Print, ResetColor, SetBackgroundColor, SetForegroundColor},
ExecutableCommand, Result,
2020-03-25 08:00:23 +11:00
event,
2019-12-15 05:26:20 +11:00
};
2019-10-02 16:49:01 +10:00
fn main() -> Result< ()> {
2019-11-02 04:09:05 +11:00
// using the macro
2019-10-02 16:49:01 +10:00
execute!(
stdout(),
2019-11-02 04:09:05 +11:00
SetForegroundColor(Color::Blue),
SetBackgroundColor(Color::Red),
2019-12-15 05:26:20 +11:00
Print("Styled text here."),
2019-10-02 16:49:01 +10:00
ResetColor
2019-11-02 04:09:05 +11:00
)?;
// or using functions
stdout()
.execute(SetForegroundColor(Color::Blue))?
.execute(SetBackgroundColor(Color::Red))?
2019-12-15 05:26:20 +11:00
.execute(Print("Styled text here."))?
2019-11-02 04:09:05 +11:00
.execute(ResetColor)?;
2020-03-25 08:00:23 +11:00
2019-11-02 04:09:05 +11:00
Ok(())
2019-10-02 16:49:01 +10:00
}
2018-07-31 05:35:35 +10:00
```
2019-03-22 02:00:30 +11:00
2019-12-15 05:26:20 +11:00
Checkout this [list ](https://docs.rs/crossterm/0.14.0/crossterm/index.html#supported-commands ) with all possible commands.
2019-11-02 04:09:05 +11:00
2019-10-02 16:49:01 +10:00
### Feature Flags
2019-09-26 00:09:16 +10:00
2019-12-13 17:12:35 +11:00
To optional feature flags.
2018-07-31 05:35:35 +10:00
2019-10-02 16:49:01 +10:00
```toml
[dependencies.crossterm]
2020-03-29 04:38:07 +11:00
version = "0.17"
2019-12-13 17:14:09 +11:00
features = ["event-stream"]
2018-07-31 05:35:35 +10:00
```
2019-10-23 01:33:38 +11:00
| Feature | Description |
2020-05-23 21:29:56 +10:00
| :----- | :----- |
2019-12-13 17:12:35 +11:00
| `event-stream` | `futures::Stream` producing `Result<Event>` .|
2019-03-11 10:09:41 +11:00
2020-05-23 21:29:56 +10:00
### Dependency Justification
| Dependency | Used for | Included |
| :----- | :----- | :-----
| `bitflags` | `KeyModifiers` , those are differ based on input.| always
| `lazy_static` | original console color, original terminal mode, saved cursor position, supports ANSI on windows, single event reader per application.| always
| `parking_lot` | used for an RW LOCK. | always
| `libc` | UNIX terminal_size/raw modes/set_title and several other lowlevel functionality. | UNIX only
| `Mio` | event readiness polling, waking up poller | UNIX only
| `signal-hook` | signalhook is used to handle terminal resize SIGNAL with Mio. | UNIX only
| `winapi` | Used for low-level windows system calls which ANSI codes can't replace| windows only
| `futures` | Can be used to for async stream of events | only with a feature flag
2020-06-14 22:46:33 +10:00
| `serde` | Se/dese/realizing of events | only with a feature flag
2020-05-23 21:29:56 +10:00
2019-10-02 16:49:01 +10:00
### Other Resources
2019-03-11 10:09:41 +11:00
2019-10-02 16:49:01 +10:00
- [API documentation ](https://docs.rs/crossterm/ )
2020-04-11 03:12:38 +10:00
- [Deprecated examples repository ](https://github.com/crossterm-rs/examples )
2019-03-11 10:09:41 +11:00
2019-10-02 16:49:01 +10:00
## Used By
2019-09-26 00:09:16 +10:00
2019-06-08 19:28:32 +10:00
- [Broot ](https://dystroy.org/broot/ )
- [Cursive ](https://github.com/gyscos/Cursive )
- [TUI ](https://github.com/fdehau/tui-rs )
2020-07-07 03:10:16 +10:00
- [Rust-sloth ](https://github.com/ecumene/rust-sloth )
2019-06-08 19:28:32 +10:00
2018-07-31 05:35:35 +10:00
## Contributing
2019-12-13 17:12:35 +11:00
We highly appreciate when anyone contributes to this crate. Before you do, please,
2019-10-02 16:49:01 +10:00
read the [Contributing ](docs/CONTRIBUTING.md ) guidelines.
2018-07-31 05:35:35 +10:00
## Authors
* **Timon Post** - *Project Owner & creator*
## License
2020-01-24 23:44:40 +11:00
This project, `crossterm` and all its sub-crates: `crossterm_screen` , `crossterm_cursor` , `crossterm_style` ,
2019-10-02 16:49:01 +10:00
`crossterm_input` , `crossterm_terminal` , `crossterm_winapi` , `crossterm_utils` are licensed under the MIT
License - see the [LICENSE ](https://github.com/crossterm-rs/crossterm/blob/master/LICENSE ) file for details.
2019-09-26 00:09:16 +10:00
[s1]: https://img.shields.io/crates/v/crossterm.svg
[l1]: https://crates.io/crates/crossterm
[s2]: https://img.shields.io/badge/license-MIT-blue.svg
2020-03-25 08:00:23 +11:00
[l2]: ./LICENSE
2019-09-26 00:09:16 +10:00
[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