| 1 | [![Stable Status][actions-stable-badge]][actions-link] |
| 2 | [![Beta Status][actions-beta-badge]][actions-link] |
| 3 | [![Nightly Status][actions-nightly-badge]][actions-link] |
| 4 | [![crates.io][crates-badge]][crates-link] |
| 5 | [![docs.rs][docs-badge]][docs-link] |
| 6 | [![MIT][mit-license-badge]][mit-license-link] |
| 7 | [![Apache 2.0][apache-license-badge]][apache-license-link] |
| 8 | ![LOC][loc-badge] |
| 9 | |
| 10 | # ANSI Escape Sequences provider & parser |
| 11 | |
| 12 | A Rust library which provides an ANSI escape sequences (or codes, whatever you like more) |
| 13 | and a parser allowing you to parse data from the STDIN (or `/dev/tty`) in the raw mode. |
| 14 | |
| 15 | ## Sequences provider |
| 16 | |
| 17 | ### Terminal support |
| 18 | |
| 19 | Not all ANSI escape sequences are supported by all terminals. You can use the |
| 20 | [interactive-test](https://github.com/zrzka/anes-rs/tree/master/interactive-test) to test them. |
| 21 | Checkout the repository and then: |
| 22 | |
| 23 | ```bash |
| 24 | $ cd anes-rs |
| 25 | $ cargo run --bin interactive-test |
| 26 | ``` |
| 27 | |
| 28 | ### Examples |
| 29 | |
| 30 | <details> |
| 31 | <summary> |
| 32 | Click to show Cargo.toml. |
| 33 | </summary> |
| 34 | |
| 35 | ```toml |
| 36 | [dependencies] |
| 37 | anes = "0.1" |
| 38 | ``` |
| 39 | |
| 40 | </details> |
| 41 | <p></p> |
| 42 | |
| 43 | |
| 44 | An example how to retrieve the ANSI escape sequence as a `String`: |
| 45 | |
| 46 | ```rust |
| 47 | use anes::SaveCursorPosition; |
| 48 | |
| 49 | fn main() { |
| 50 | let string = format!("{}", SaveCursorPosition); |
| 51 | assert_eq!(&string, "\x1B7"); |
| 52 | } |
| 53 | ``` |
| 54 | |
| 55 | An example how to use the ANSI escape sequence: |
| 56 | |
| 57 | ```rust |
| 58 | use std::io::{Result, Write}; |
| 59 | |
| 60 | use anes::execute; |
| 61 | |
| 62 | fn main() -> Result<()> { |
| 63 | let mut stdout = std::io::stdout(); |
| 64 | execute!( |
| 65 | &mut stdout, |
| 66 | anes::SaveCursorPosition, |
| 67 | anes::MoveCursorTo(10, 10), |
| 68 | anes::RestoreCursorPosition |
| 69 | )?; |
| 70 | Ok(()) |
| 71 | } |
| 72 | ``` |
| 73 | |
| 74 | ## Sequences parser |
| 75 | |
| 76 | You have to enable `parser` feature in order to use the parser. It's disabled by default. |
| 77 | |
| 78 | ### Examples |
| 79 | |
| 80 | <details> |
| 81 | <summary> |
| 82 | Click to show Cargo.toml. |
| 83 | </summary> |
| 84 | |
| 85 | ```toml |
| 86 | [dependencies] |
| 87 | anes = { version = "0.1", features = ["parser"] } |
| 88 | ``` |
| 89 | |
| 90 | </details> |
| 91 | <p></p> |
| 92 | |
| 93 | An example how to parse cursor position: |
| 94 | |
| 95 | ```rust |
| 96 | use anes::parser::{Parser, Sequence}; |
| 97 | |
| 98 | let mut parser = Parser::default(); |
| 99 | parser.advance(b"\x1B[20;10R", false); |
| 100 | |
| 101 | assert_eq!(Some(Sequence::CursorPosition(10, 20)), parser.next()); |
| 102 | assert!(parser.next().is_none()); |
| 103 | ``` |
| 104 | |
| 105 | ## License |
| 106 | |
| 107 | The ANES crate is dual-licensed under [Apache 2.0][apache-license-link] and |
| 108 | [MIT][mit-license-link] terms. |
| 109 | |
| 110 | Copyrights in the ANES project are retained by their contributors. No |
| 111 | copyright assignment is required to contribute to the ANES project. |
| 112 | |
| 113 | [actions-stable-badge]: https://github.com/zrzka/anes-rs/workflows/stable/badge.svg |
| 114 | [actions-beta-badge]: https://github.com/zrzka/anes-rs/workflows/beta/badge.svg |
| 115 | [actions-nightly-badge]: https://github.com/zrzka/anes-rs/workflows/nightly/badge.svg |
| 116 | [actions-link]: https://github.com/zrzka/anes-rs/actions |
| 117 | |
| 118 | [crates-badge]: https://img.shields.io/crates/v/anes.svg |
| 119 | [crates-link]: https://crates.io/crates/anes |
| 120 | |
| 121 | [docs-badge]: https://docs.rs/anes/badge.svg |
| 122 | [docs-link]: https://docs.rs/anes |
| 123 | |
| 124 | [mit-license-badge]: https://img.shields.io/badge/license-MIT-blue.svg |
| 125 | [mit-license-link]: ./LICENSE-MIT |
| 126 | [apache-license-badge]: https://img.shields.io/badge/license-Apache2-blue.svg |
| 127 | [apache-license-link]: /LICENSE-APACHE |
| 128 | |
| 129 | [loc-badge]: https://tokei.rs/b1/github/zrzka/anes-rs?category=code |