#escaping #terminal #ansi #cursor #ansi-colors #color

deprecated terminal-escapes

[DEPRECATED in favor of termion] Terminal escape sequence support for client applications

3 releases

0.1.2 Jul 22, 2019
0.1.1 Jul 21, 2019
0.1.0 Jul 20, 2019

#13 in #escape

MIT/Apache

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

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.

No runtime deps