2 <img alt="Termion logo" src="https://rawgit.com/ticki/termion/master/logo.svg" />
5 [![Build Status](https://travis-ci.org/ticki/termion.svg?branch=master)](https://travis-ci.org/ticki/termion) [![Latest Version](https://img.shields.io/crates/v/termion.svg)](https://crates.io/crates/termion) | [Documentation](https://docs.rs/termion) | [Examples](https://github.com/Ticki/termion/tree/master/examples) | [Changelog](https://github.com/Ticki/termion/tree/master/CHANGELOG.md) | [Tutorial](http://ticki.github.io/blog/making-terminal-applications-in-rust-with-termion/)
6 |----|----|----|----|----
9 **Termion** is a pure Rust, bindless library for low-level handling, manipulating
10 and reading information about terminals. This provides a full-featured
11 alternative to Termbox.
13 Termion aims to be simple and yet expressive. It is bindless, meaning that it
14 is not a front-end to some other library (e.g., ncurses or termbox), but a
15 standalone library directly talking to the TTY.
17 Termion is quite convenient, due to its complete coverage of essential TTY
18 features, providing one consistent API. Termion is rather low-level containing
19 only abstraction aligned with what actually happens behind the scenes. For
20 something more high-level, refer to inquirer-rs, which uses Termion as backend.
22 Termion generates escapes and API calls for the user. This makes it a whole lot
23 cleaner to use escapes.
25 Supports Redox, Mac OS X, BSD, and Linux (or, in general, ANSI terminals).
27 ## A note on stability
38 ## 0.1.0 to 1.0.0 guide
40 This sample table gives an idea of how to go about converting to the new major
44 |--------------------------------|---------------------------
45 | `use termion::IntoRawMode` | `use termion::raw::IntoRawMode`
46 | `use termion::TermRead` | `use termion::input::TermRead`
47 | `stdout.color(color::Red);` | `write!(stdout, "{}", color::Fg(color::Red));`
48 | `stdout.color_bg(color::Red);` | `write!(stdout, "{}", color::Bg(color::Red));`
49 | `stdout.goto(x, y);` | `write!(stdout, "{}", cursor::Goto(x, y));`
50 | `color::rgb(r, g, b);` | `color::Rgb(r, g, b)` (truecolor)
51 | `x.with_mouse()` | `MouseTerminal::from(x)`
66 - Safe `isatty` wrapper.
67 - Panic-free error handling.
68 - Special keys events (modifiers, special keys, etc.).
70 - Asynchronous key events.
73 - Detailed documentation on every item.
84 use termion::{color, style};
89 println!("{}Red", color::Fg(color::Red));
90 println!("{}Blue", color::Fg(color::Blue));
91 println!("{}Blue'n'Bold{}", style::Bold, style::Reset);
92 println!("{}Just plain italic", style::Italic);
102 print!("{}{}Stuff", termion::clear::All, termion::cursor::Goto(1, 1));
110 extern crate termion;
112 use termion::event::{Key, Event, MouseEvent};
113 use termion::input::{TermRead, MouseTerminal};
114 use termion::raw::IntoRawMode;
115 use std::io::{Write, stdout, stdin};
119 let mut stdout = MouseTerminal::from(stdout().into_raw_mode().unwrap());
121 write!(stdout, "{}{}q to exit. Click, click, click!", termion::clear::All, termion::cursor::Goto(1, 1)).unwrap();
122 stdout.flush().unwrap();
124 for c in stdin.events() {
125 let evt = c.unwrap();
127 Event::Key(Key::Char('q')) => break,
128 Event::Mouse(me) => {
130 MouseEvent::Press(_, x, y) => {
131 write!(stdout, "{}x", termion::cursor::Goto(x, y)).unwrap();
138 stdout.flush().unwrap();
146 extern crate termion;
148 use termion::input::TermRead;
149 use std::io::{Write, stdout, stdin};
152 let stdout = stdout();
153 let mut stdout = stdout.lock();
155 let mut stdin = stdin.lock();
157 stdout.write_all(b"password: ").unwrap();
158 stdout.flush().unwrap();
160 let pass = stdin.read_passwd(&mut stdout);
162 if let Ok(Some(pass)) = pass {
163 stdout.write_all(pass.as_bytes()).unwrap();
164 stdout.write_all(b"\n").unwrap();
166 stdout.write_all(b"Error\n").unwrap();
173 See `examples/`, and the documentation, which can be rendered using `cargo doc`.
175 For a more complete example, see [a minesweeper implementation](https://github.com/redox-os/games-for-redox/blob/master/src/minesweeper/main.rs), that I made for Redox using termion.
177 <img src="image.png" width="200">