1 | //! A terminal related ANSI escape sequences. |
2 | |
3 | sequence!( |
4 | /// Resizes the text area to the given width and height in characters. |
5 | /// |
6 | /// # Examples |
7 | /// |
8 | /// ```no_run |
9 | /// use std::io::{stdout, Write}; |
10 | /// use anes::ResizeTextArea; |
11 | /// |
12 | /// let mut stdout = stdout(); |
13 | /// // Resize the terminal to 80x25 |
14 | /// write!(stdout, "{}", ResizeTextArea(80, 25)); |
15 | /// ``` |
16 | struct ResizeTextArea(u16, u16) => |
17 | |this, f| write!(f, csi!("8;{};{}t" ), this.1, this.0) |
18 | ); |
19 | |
20 | sequence!( |
21 | /// Tells the terminal to start reporting mouse events. |
22 | /// |
23 | /// Mouse events are not reported by default. |
24 | struct EnableMouseEvents => concat!( |
25 | csi!("?1000h" ), |
26 | csi!("?1002h" ), |
27 | csi!("?1015h" ), |
28 | csi!("?1006h" ) |
29 | ) |
30 | ); |
31 | |
32 | sequence!( |
33 | /// Tells the terminal to stop reporting mouse events. |
34 | struct DisableMouseEvents => concat!( |
35 | csi!("?1006l" ), |
36 | csi!("?1015l" ), |
37 | csi!("?1002l" ), |
38 | csi!("?1000l" ) |
39 | ) |
40 | ); |
41 | |
42 | #[cfg (test)] |
43 | test_sequences!( |
44 | resize_text_area( |
45 | ResizeTextArea(80, 25) => " \x1B[8;25;80t" , |
46 | ResizeTextArea(1, 1) => " \x1B[8;1;1t" , |
47 | ), |
48 | enable_mouse_events( |
49 | EnableMouseEvents => " \x1B[?1000h \x1B[?1002h \x1B[?1015h \x1B[?1006h" , |
50 | ), |
51 | disable_mouse_events( |
52 | DisableMouseEvents => " \x1B[?1006l \x1B[?1015l \x1B[?1002l \x1B[?1000l" , |
53 | ) |
54 | ); |
55 | |