2019-01-28 07:16:14 +11:00
# Crossterm Terminal | cross-platform terminal actions.
2019-04-11 07:46:30 +10:00
![Lines of Code][s7] [![Latest Version][s1]][l1] [![MIT][s2]][l2] [![docs][s3]][l3] [![Join us on Discord][s5]][l5]
2019-01-28 07:16:14 +11:00
[s1]: https://img.shields.io/crates/v/crossterm_terminal.svg
[l1]: https://crates.io/crates/crossterm_terminal
[s2]: https://img.shields.io/badge/license-MIT-blue.svg
[l2]: ./LICENSE
[s3]: https://docs.rs/crossterm_terminal/badge.svg
[l3]: https://docs.rs/crossterm_terminal/
2019-04-11 07:46:30 +10:00
[s5]: https://img.shields.io/discord/560857607196377088.svg?logo=discord
2019-04-12 01:37:06 +10:00
[l5]: https://discord.gg/K4nyTDB
2019-01-28 07:16:14 +11:00
2019-09-25 03:45:59 +10:00
[s7]: https://travis-ci.org/crossterm-rs/crossterm.svg?branch=master
2019-01-28 07:16:14 +11:00
This crate allows you to perform terminal related actions cross-platform e.g clearing, resizing etc.
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 perform terminal related actions, and can be use individually.
Other sub-crates are:
- [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 )
2019-09-25 03:45:59 +10:00
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 ).
2019-01-28 07:16:14 +11:00
## 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
2019-09-25 03:45:59 +10:00
All examples of how `crossterm_terminal` works can be found in the [examples ](https://github.com/crossterm-rs/crossterm/tree/master/examples ) directory.
2019-01-28 07:16:14 +11:00
Add the `crossterm_terminal` package to your `Cargo.toml` file.
```
[dependencies]
2019-04-11 07:46:30 +10:00
crossterm_terminal = "0.2"
2019-01-28 07:16:14 +11:00
```
And import the `crossterm_terminal` modules you want to use.
```rust
pub use crossterm_terminal::{terminal, Terminal, ClearType};
```
### Useful Links
- [Documentation ](https://docs.rs/crossterm_terminal/ )
- [Crates.io ](https://crates.io/crates/crossterm_terminal )
- [Examples ](/examples )
## Features
These are the features of this crate:
- Cross-platform
2019-04-11 07:46:30 +10:00
- Multithreaded (send, sync)
- Detailed Documentation
- Few Dependencies
2019-01-28 07:16:14 +11:00
- Terminal
- Clearing (all lines, current line, from cursor down and up, until new line)
2019-04-11 07:46:30 +10:00
- Scrolling (up, down)
- Terminal Size (get/set)
- Exit Current Process
2019-01-28 07:16:14 +11:00
2019-07-26 03:57:14 +10:00
## Command API
2019-09-25 03:45:59 +10:00
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.
2019-07-26 03:57:14 +10:00
Because it is more convenient, faster, and easier to use.
2019-01-28 07:16:14 +11:00
## Examples
2019-07-26 03:57:14 +10:00
2019-09-25 03:45:59 +10:00
The [examples ](https://github.com/crossterm-rs/crossterm/tree/master/examples ) folder has more complete and verbose examples.
2019-01-28 07:16:14 +11:00
```rust
use crossterm::terminal::{terminal,ClearType};
let mut terminal = terminal();
// Clear all lines in terminal;
2019-09-19 21:12:16 +10:00
terminal.clear(ClearType::All)?;
2019-01-28 07:16:14 +11:00
// Clear all cells from current cursor position down.
2019-09-19 21:12:16 +10:00
terminal.clear(ClearType::FromCursorDown)?;
2019-01-28 07:16:14 +11:00
// Clear all cells from current cursor position down.
2019-09-19 21:12:16 +10:00
terminal.clear(ClearType::FromCursorUp)?;
2019-01-28 07:16:14 +11:00
// Clear current line cells.
2019-09-19 21:12:16 +10:00
terminal.clear(ClearType::CurrentLine)?;
2019-01-28 07:16:14 +11:00
// Clear all the cells until next line.
2019-09-19 21:12:16 +10:00
terminal.clear(ClearType::UntilNewLine)?;
2019-01-28 07:16:14 +11:00
// Get terminal size
2019-09-19 21:12:16 +10:00
let (width, height) = terminal.size()?;
2019-01-28 07:16:14 +11:00
print!("X: {}, y: {}", width, height);
// Scroll down, up 10 lines.
2019-09-19 21:12:16 +10:00
terminal.scroll_down(10)?;
terminal.scroll_up(10)?;
2019-01-28 07:16:14 +11:00
// Set terminal size (width, height)
2019-09-19 21:12:16 +10:00
terminal.set_size(10,10)?;
2019-01-28 07:16:14 +11:00
// 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");
```
## 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
2019-04-11 07:46:30 +10:00
This project is licensed under the MIT License - see the [LICENSE.md ](./LICENSE ) file for details