This documentation is only for Crossterm version `0.4.0` if you have an older version of Crossterm I suggest you check the [Upgrade Manual](https://github.com/TimonPost/crossterm/blob/master/docs/UpgradeManual.md) for more information about how to upgrade to a newer version or check the [examples](https://github.com/TimonPost/crossterm/tree/master/examples) folders which contains a readme for every specific version. Also, you could take a look at the [examples](https://github.com/TimonPost/crossterm/tree/master/examples) from the previous versions of Crossterm.
Add the Crossterm package to your `Cargo.toml` file.
```
[dependencies]
crossterm = "0.4.0"
```
And import the Crossterm modules you want to use.
```rust
extern crate crossterm;
// this module is used for styling the terminal
use self::crossterm::style::*;
// this module is used for cursor related actions
use self::crossterm::cursor::*;
// this mudule is used for terminal related actions
use self::crossterm::terminal::*;
```
## Useful Links
- Code documentation:
version [0.1.0](https://docs.rs/crossterm/0.1.0/crossterm/),
Check these links: [AlternateScreen](https://github.com/TimonPost/crossterm/blob/master/examples/Crossterm%200.3.0/terminal/alternate_screen.rs) and [RawScreen](https://github.com/TimonPost/crossterm/blob/master/examples/Crossterm%200.3.0/terminal/raw_mode.rs) for information about how to work with these features.
## Tested terminals
- Windows Powershell
- Windows 10 (pro)
- Windows CMD
- Windows 10 (pro)
- Ubuntu Desktop Terminal
- Ubuntu 17.10
- Arch linux Konsole
This crate supports all Unix terminals and windows terminals down to Windows XP 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.
## How it works
Crossterm is using ANSI escape codes by default for both Unix and Windows systems.
But for Windows, it is a bit more complicated since Windows versions 8 or lower are not supporting ANSI escape codes. This is why we use WinApi for those machines. For Windows 10 ANSI codes will be the default.
## Notice
This library is not stable yet but I expect it to not to change that much anymore.
And if there are any changes that affect previous versions I will [describe](https://github.com/TimonPost/crossterm/blob/master/docs/UpgradeManual.md) what to change when upgrading Crossterm to a newer version.
## Todo
I still have some things in mind to implement.
- Handling mouse events
I want to be able to do something based on the clicks the user has done with its mouse.
- Handling key events
I want to be able to read key combination inputs.
- reading from the console.
I want to be able to read the input of the console.
- Error handling
Currently, I am not doing that much with returned errors. This is bad since I suspect that everything is working. I want to manage this better. When you build this crate you will see the warnings about not used return values. This is what needs to be improved.
- Tests
Also, I want to have tests for this crate, and yes maybe a little late :). But I find it difficult to test some functionalities because how would you ever test if the screen is indeed int alternate, raw modes or how would you ever test if the terminal cursor is moved certainly.
## Contributing
If you would like to contribute to Crossterm, than please design the code as it is now.
For example, a module like cursor has the following file structure:
- mod.rs
This file contains some trait, in this case, `ITerminalCursor`, for other modules to implement. So that it can work at a specific platform.
- cursor.rs
The end user will call this module to access the cursor functionalities. This module will decide which implementation to use based on the current platform.
- winapi_cursor
This is the cursor trait (located in mod.rs) implementation with WinApi.
- ansi_cursor
This is the cursor trait (located in mod.rs) implementation with ANSI escape codes.
The above structure is the same for the terminal, color, manager modules.
Why I have chosen for this design:
- Because you can easily extend to multiple platforms by implementing the trait int the mod.rs.
- You keep the functionalities for different platforms separated in different files.
- Also, you have one API the user can call like in the `cursor.rs` above. This file should be avoided to change that much. All the other code could change a lot because it has no impact on the user side.
I highly appreciate it when you are contributing to this crate. Also Since my native language is not English my grammar and sentence order will not be perfect. So improving this by correcting these mistakes will help both me and the reader of the docs.
## Authors
* **Timon Post** - *Project Owner & creator*
## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details