1 /// An example how to create custom ANSI sequences.
2 use anes::{csi, esc, sequence};
3 
static_unit_struct()4 fn static_unit_struct() {
5     sequence!(
6         /// Documentation string is also supported.
7         struct Foo => csi!("foo")
8     );
9 
10     assert_eq!(&format!("{}", Foo), "\x1B[foo");
11 }
12 
dynamic_struct()13 fn dynamic_struct() {
14     sequence!(
15         /// Documentation string is also supported.
16         struct Foo(u16, u16) =>
17         |this, f| write!(f, esc!("{};{}"), this.0, this.1)
18     );
19 
20     assert_eq!(&format!("{}", Foo(5, 10)), "\x1B5;10");
21 }
22 
static_enum()23 fn static_enum() {
24     sequence!(
25         /// Documentation string is also supported.
26         enum Foo {
27             /// Documentation string is also supported.
28             Bar => esc!("bar"),
29             /// Documentation string is also supported.
30             Baz => csi!("baz"),
31         }
32     );
33 
34     assert_eq!(&format!("{}", Foo::Bar), "\x1Bbar");
35     assert_eq!(&format!("{}", Foo::Baz), "\x1B[baz");
36 }
37 
main()38 fn main() {
39     static_unit_struct();
40     dynamic_struct();
41     static_enum();
42 }
43