{"id":13438678,"url":"https://github.com/redox-os/termion","last_synced_at":"2025-05-14T04:08:19.670Z","repository":{"id":39617488,"uuid":"53257295","full_name":"redox-os/termion","owner":"redox-os","description":"Mirror of https://gitlab.redox-os.org/redox-os/termion","archived":false,"fork":false,"pushed_at":"2025-04-04T06:17:30.000Z","size":4651,"stargazers_count":2134,"open_issues_count":27,"forks_count":115,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-04-11T02:51:23.044Z","etag":null,"topics":["rust","terminal","tty","tui"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/redox-os.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-03-06T13:54:02.000Z","updated_at":"2025-04-08T17:29:50.000Z","dependencies_parsed_at":"2024-02-07T22:46:46.368Z","dependency_job_id":"f5b16c1b-c5a1-420b-8277-52c0e006f80d","html_url":"https://github.com/redox-os/termion","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redox-os%2Ftermion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redox-os%2Ftermion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redox-os%2Ftermion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redox-os%2Ftermion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redox-os","download_url":"https://codeload.github.com/redox-os/termion/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254069690,"owners_count":22009558,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rust","terminal","tty","tui"],"created_at":"2024-07-31T03:01:07.487Z","updated_at":"2025-05-14T04:08:14.654Z","avatar_url":"https://github.com/redox-os.png","language":"Rust","funding_links":[],"categories":["Libraries","Rust","库 Libraries","库","HarmonyOS","Rust 🦀"],"sub_categories":["Command-line","命令行 Command-line","命令行","Windows Manager"],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg alt=\"Termion logo\" src=\"https://rawgit.com/redox-os/termion/master/logo.svg\" /\u003e\n\u003c/p\u003e\n\n[![Build Status](https://travis-ci.org/redox-os/termion.svg?branch=master)](https://travis-ci.org/redox-os/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/redox-os/termion/tree/master/examples) | [Changelog](https://github.com/redox-os/termion/tree/master/CHANGELOG.md) | [Tutorial](http://ticki.github.io/blog/making-terminal-applications-in-rust-with-termion/)\n|----|----|----|----|----\n\n\n**Termion** is a pure Rust, bindless library for low-level handling, manipulating\nand reading information about terminals. This provides a full-featured\nalternative to Termbox.\n\nTermion aims to be simple and yet expressive. It is bindless, meaning that it\nis not a front-end to some other library (e.g., ncurses or termbox), but a\nstandalone library directly talking to the TTY.\n\nTermion is quite convenient, due to its complete coverage of essential TTY\nfeatures, providing one consistent API. Termion is rather low-level containing\nonly abstraction aligned with what actually happens behind the scenes. For\nsomething more high-level, refer to inquirer-rs, which uses Termion as backend.\n\nTermion generates escapes and API calls for the user. This makes it a whole lot\ncleaner to use escapes.\n\nSupports Redox, Mac OS X, BSD, and Linux (or, in general, ANSI terminals).\n\n## A note on stability\n\nThis crate is stable.\n\n## Cargo.toml\n\n```toml\n[dependencies]\ntermion = \"*\"\n```\n\n## 3.0.0 to 4.0.0 guide\n\nA change is only necessary if you were matching on all variants of the `MouseEvent` enum without a wildcard.\nIn this case, you need to either handle the two new variants, `MouseLeft` and `MouseRight`, or add a wildcard.\n\n## 2.0.0 to 3.0.0 guide\n\nChanges are only required if you were using `IntoRawMode` on generic terminals `W: Write`. Now, terminal\nis also required to implement [`AsFd` trait][AsFd-trait]. So replacing generic bounds with `W: Write + AsFd`\nshould be sufficient.\n\n[AsFd-trait]: https://doc.rust-lang.org/std/os/fd/trait.AsFd.html\n\n## 1.0.0 to 2.0.0 guide\n\n| 1.0.0                          | 2.0.0\n|--------------------------------|---------------------------\n| `AlternativeScreen::from(x)`   | `x.into_alternative_screen()`\n\n## 0.1.0 to 1.0.0 guide\n\nThis sample table gives an idea of how to go about converting to the new major\nversion of Termion.\n\n| 0.1.0                          | 1.0.0\n|--------------------------------|---------------------------\n| `use termion::IntoRawMode`     | `use termion::raw::IntoRawMode`\n| `use termion::TermRead`        | `use termion::input::TermRead`\n| `stdout.color(color::Red);`    | `write!(stdout, \"{}\", color::Fg(color::Red));`\n| `stdout.color_bg(color::Red);` | `write!(stdout, \"{}\", color::Bg(color::Red));`\n| `stdout.goto(x, y);`           | `write!(stdout, \"{}\", cursor::Goto(x, y));`\n| `color::rgb(r, g, b);`         | `color::Rgb(r, g, b)` (truecolor)\n| `x.with_mouse()`               | `MouseTerminal::from(x)`\n\n## Features\n\n- Raw mode.\n- TrueColor.\n- 256-color mode.\n- Cursor movement.\n- Text formatting.\n- Console size.\n- TTY-only stream.\n- Control sequences.\n- Termios control.\n- Password input.\n- Redox support.\n- Safe `isatty` wrapper.\n- Panic-free error handling.\n- Special keys events (modifiers, special keys, etc.).\n- Allocation-free.\n- Asynchronous key events.\n- Mouse input.\n- Carefully tested.\n- Detailed documentation on every item.\n\nand much more.\n\n## Examples\n\n### Style and colors.\n\n```rust\nextern crate termion;\n\nuse termion::{color, style};\n\nuse std::io;\n\nfn main() {\n    println!(\"{}Red\", color::Fg(color::Red));\n    println!(\"{}Blue\", color::Fg(color::Blue));\n    println!(\"{}Blue'n'Bold{}\", style::Bold, style::Reset);\n    println!(\"{}Just plain italic\", style::Italic);\n}\n```\n\n### Moving the cursor\n\n```rust\nextern crate termion;\n\nfn main() {\n    print!(\"{}{}Stuff\", termion::clear::All, termion::cursor::Goto(1, 1));\n}\n\n```\n\n### Mouse\n\n```rust\nextern crate termion;\n\nuse termion::event::{Key, Event, MouseEvent};\nuse termion::input::{TermRead, MouseTerminal};\nuse termion::raw::IntoRawMode;\nuse std::io::{Write, stdout, stdin};\n\nfn main() {\n    let stdin = stdin();\n    let mut stdout = MouseTerminal::from(stdout().into_raw_mode().unwrap());\n\n    write!(stdout, \"{}{}q to exit. Click, click, click!\", termion::clear::All, termion::cursor::Goto(1, 1)).unwrap();\n    stdout.flush().unwrap();\n\n    for c in stdin.events() {\n        let evt = c.unwrap();\n        match evt {\n            Event::Key(Key::Char('q')) =\u003e break,\n            Event::Mouse(me) =\u003e {\n                match me {\n                    MouseEvent::Press(_, x, y) =\u003e {\n                        write!(stdout, \"{}x\", termion::cursor::Goto(x, y)).unwrap();\n                    },\n                    _ =\u003e (),\n                }\n            }\n            _ =\u003e {}\n        }\n        stdout.flush().unwrap();\n    }\n}\n```\n\n### Read a password\n\n```rust\nextern crate termion;\n\nuse termion::input::TermRead;\nuse std::io::{Write, stdout, stdin};\n\nfn main() {\n    let stdout = stdout();\n    let mut stdout = stdout.lock();\n    let stdin = stdin();\n    let mut stdin = stdin.lock();\n\n    stdout.write_all(b\"password: \").unwrap();\n    stdout.flush().unwrap();\n\n    let pass = stdin.read_passwd(\u0026mut stdout);\n\n    if let Ok(Some(pass)) = pass {\n        stdout.write_all(pass.as_bytes()).unwrap();\n        stdout.write_all(b\"\\n\").unwrap();\n    } else {\n        stdout.write_all(b\"Error\\n\").unwrap();\n    }\n}\n```\n\n## Usage\n\nSee `examples/`, and the documentation, which can be rendered using `cargo doc`.\n\nFor 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.\n\n\u003cimg src=\"image.png\" width=\"200\"\u003e\n\n## License\n\nMIT/X11.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredox-os%2Ftermion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredox-os%2Ftermion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredox-os%2Ftermion/lists"}