Debian Codegraph @

README.md

raw
1 <h1 align="center"><img width="440" src="docs/crossterm_full.png" /></h1>
2
3 [![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]
4
5 # Cross-platform Terminal Manipulation Library
6
7 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,
8 see [Tested Terminals](#tested-terminals) for more info).
9
10 ## Table of Contents
11
12 - [Cross-platform Terminal Manipulation Library](#cross-platform-terminal-manipulation-library)
13 - [Table of Contents](#table-of-contents)
14 - [Features](#features)
15 - [Tested Terminals](#tested-terminals)
16 - [Getting Started](#getting-started)
17 - [Feature Flags](#feature-flags)
18 - [Dependency Justification](#dependency-justification)
19 - [Other Resources](#other-resources)
20 - [Used By](#used-by)
21 - [Contributing](#contributing)
22 - [Authors](#authors)
23 - [License](#license)
24
25 ## Features
26
27 - Cross-platform
28 - Multi-threaded (send, sync)
29 - Detailed documentation
30 - Few dependencies
31 - Full control over writing and flushing output buffer
32 - Is tty
33 - Cursor
34 - Move the cursor N times (up, down, left, right)
35 - Move to previous / next line
36 - Move to column
37 - Set/get the cursor position
38 - Store the cursor position and restore to it later
39 - Hide/show the cursor
40 - Enable/disable cursor blinking (not all terminals do support this feature)
41 - Styled output
42 - Foreground color (16 base colors)
43 - Background color (16 base colors)
44 - 256 (ANSI) color support (Windows 10 and UNIX only)
45 - RGB color support (Windows 10 and UNIX only)
46 - Text attributes like bold, italic, underscore, crossed, etc
47 - Terminal
48 - Clear (all lines, current line, from cursor down and up, until new line)
49 - Scroll up, down
50 - Set/get the terminal size
51 - Exit current process
52 - Alternate screen
53 - Raw screen
54 - Set terminal title
55 - Enable/disable line wrapping
56 - Event
57 - Input Events
58 - Mouse Events (press, release, position, button, drag)
59 - Terminal Resize Events
60 - Advanced modifier (SHIFT | ALT | CTRL) support for both mouse and key events and
61 - futures Stream (feature 'event-stream')
62 - Poll/read API
63
64 <!--
65 WARNING: Do not change following heading title as it's used in the URL by other crates!
66 -->
67
68 ### Tested Terminals
69
70 - Console Host
71 - Windows 10 (Pro)
72 - Windows 8.1 (N)
73 - Windows Terminal
74 - Windows 10 x86_64 (Enterprise)
75 - Windows 11 arm64 (Enterprise)
76 - Ubuntu Desktop Terminal
77 - Ubuntu 23.04 64-bit
78 - Ubuntu 17.10
79 - Pop!_OS ( Ubuntu ) 20.04
80 - (Arch, Manjaro) KDE Konsole
81 - (Arch, NixOS) Kitty
82 - Linux Mint
83 - (OpenSuse) Alacritty
84 - (Chrome OS) Crostini
85 - Apple
86 - macOS Monterey 12.7.1 (Intel-Chip)
87 - macOS Sonama 14.4 (M1 Max, Apple Silicon-Chip)
88
89 This crate supports all UNIX terminals and Windows terminals down to Windows 7; however, not all of the
90 terminals have been tested. If you have used this library for a terminal other than the above list without
91 issues, then feel free to add it to the above list - I really would appreciate it!
92
93 ## Getting Started
94 _see the [examples directory](examples/) and [documentation](https://docs.rs/crossterm/) for more advanced examples._
95
96 <details>
97 <summary>
98 Click to show Cargo.toml.
99 </summary>
100
101 ```toml
102 [dependencies]
103 crossterm = "0.27"
104 ```
105
106 </details>
107 <p></p>
108
109 ```rust
110 use std::io::{stdout, Write};
111
112 use crossterm::{
113 execute,
114 style::{Color, Print, ResetColor, SetBackgroundColor, SetForegroundColor},
115 ExecutableCommand,
116 event,
117 };
118
119 fn main() -> std::io::Result<()> {
120 // using the macro
121 execute!(
122 stdout(),
123 SetForegroundColor(Color::Blue),
124 SetBackgroundColor(Color::Red),
125 Print("Styled text here."),
126 ResetColor
127 )?;
128
129 // or using functions
130 stdout()
131 .execute(SetForegroundColor(Color::Blue))?
132 .execute(SetBackgroundColor(Color::Red))?
133 .execute(Print("Styled text here."))?
134 .execute(ResetColor)?;
135
136 Ok(())
137 }
138 ```
139
140 Checkout this [list](https://docs.rs/crossterm/latest/crossterm/index.html#supported-commands) with all possible commands.
141
142 ### Feature Flags
143
144 ```toml
145 [dependencies.crossterm]
146 version = "0.27"
147 features = ["event-stream"]
148 ```
149
150 | Feature | Description |
151 |:---------------|:---------------------------------------------|
152 | `event-stream` | `futures::Stream` producing `Result<Event>`. |
153 | `serde` | (De)serializing of events. |
154 | `events` | Reading input/system events (enabled by default) |
155 | `filedescriptor` | Use raw filedescriptor for all events rather then mio dependency |
156 | `derive-more` | Adds `is_*` helper functions for event types |
157 | `osc52` | Enables crossterm::clipboard |
158
159
160 To use crossterm as a very thin layer you can disable the `events` feature or use `filedescriptor` feature.
161 This can disable `mio` / `signal-hook` / `signal-hook-mio` dependencies.
162
163 ### Dependency Justification
164
165 | Dependency | Used for | Included |
166 |:---------------|:---------------------------------------------------------------------------------|:--------------------------------------|
167 | `bitflags` | `KeyModifiers`, those are differ based on input. | always |
168 | `parking_lot` | locking `RwLock`s with a timeout, const mutexes. | always |
169 | `libc` | UNIX terminal_size/raw modes/set_title and several other low level functionality. | optional (`events` feature), UNIX only |
170 | `Mio` | event readiness polling, waking up poller | optional (`events` feature), UNIX only |
171 | `signal-hook` | signal-hook is used to handle terminal resize SIGNAL with Mio. | optional (`events` feature),UNIX only |
172 | `winapi` | Used for low-level windows system calls which ANSI codes can't replace | windows only |
173 | `futures-core` | For async stream of events | only with `event-stream` feature flag |
174 | `serde` | ***ser***ializing and ***de***serializing of events | only with `serde` feature flag |
175 | `derive_more` | Adds `is_*` helper functions for event types | optional (`derive-more` feature), included by default |
176 | `base64` | Encoding clipboard data for OSC52 sequences in crossterm::clipboard | only with `osc52` feature flag |
177
178 ### Other Resources
179
180 - [API documentation](https://docs.rs/crossterm/)
181 - [Deprecated examples repository](https://github.com/crossterm-rs/examples)
182
183 ## Used By
184
185 - [Broot](https://dystroy.org/broot/)
186 - [Cursive](https://github.com/gyscos/Cursive)
187 - [Ratatui](https://github.com/ratatui/ratatui)
188 - [Rust-sloth](https://github.com/ecumene/rust-sloth)
189 - [Rusty-rain](https://github.com/cowboy8625/rusty-rain)
190
191 ## Contributing
192
193 We highly appreciate when anyone contributes to this crate. Before you do, please,
194 read the [Contributing](docs/CONTRIBUTING.md) guidelines.
195
196 ## Authors
197
198 * **Timon Post** - *Project Owner & creator*
199
200 ## License
201
202 This project, `crossterm` and all its sub-crates: `crossterm_screen`, `crossterm_cursor`, `crossterm_style`,
203 `crossterm_input`, `crossterm_terminal`, `crossterm_winapi`, `crossterm_utils` are licensed under the MIT
204 License - see the [LICENSE](https://github.com/crossterm-rs/crossterm/blob/master/LICENSE) file for details.
205
206 [s1]: https://img.shields.io/crates/v/crossterm.svg
207 [l1]: https://crates.io/crates/crossterm
208
209 [s2]: https://img.shields.io/badge/license-MIT-blue.svg
210 [l2]: ./LICENSE
211
212 [s3]: https://docs.rs/crossterm/badge.svg
213 [l3]: https://docs.rs/crossterm/
214
215 [s3]: https://docs.rs/crossterm/badge.svg
216 [l3]: https://docs.rs/crossterm/
217
218 [s5]: https://img.shields.io/discord/560857607196377088.svg?logo=discord
219 [l5]: https://discord.gg/K4nyTDB
220
221 [s6]: https://tokei.rs/b1/github/crossterm-rs/crossterm?category=code
222 [s7]: https://travis-ci.org/crossterm-rs/crossterm.svg?branch=master