3 releases
0.1.2 | Jul 22, 2019 |
---|---|
0.1.1 | Jul 21, 2019 |
0.1.0 | Jul 20, 2019 |
#5 in #escapes
19KB
348 lines
Terminal escapes
Utilities to control a ANSI-escapes compliant terminal device from a client application.
extern crate terminal_escapes;
use terminal_escapes::{
Sequence::*,
Attribute::*,
Color
};
fn main() {
println!(
"{}Hello {}World!{}",
SetAttributes(&[Foreground(Color::Red)]),
SetAttributes(&[Foreground(Color::Blue), Bright]),
SetAttributes(&[Default]),
);
}
For now the supported escape sequences are rather limited, and the library is not extensively tested. I'll come back soon to this project to have a more exhaustive implementation of the protocols. In the meantime, you are welcome to participate.
Non-interactive sequences
If you only plan to use this crate to just format the output with colors,
then you can just use the Sequence
enum to put escape sequences in the output
stream.
print!("{}", Sequence::SetAttributes(Background(Color::Green)));
Interaction with the terminal
Escapes sequences can also be used to interact with the terminal just like
a regular client-server protocol.
In that case the setup, with the Device
struct, is a but more complicated
since it will need to access the program input stream.
Roadmap
Here are some elements I want to add in this crate in the future:
- Alternate screen buffer support.
- Non-buffered input.
- Asynchronous event handling for keyboard/mouse/resize/etc. events.
- And more.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.