1use animaterm::prelude::*;
2use animaterm::utilities::message_box;
3use std::collections::HashMap;
4use std::time::Duration;
5
6fn main() {
7 let macros = Some(vec![
8 (Key::AltM, MacroSequence::empty()),
9 (
10 Key::T,
11 MacroSequence::from_text(
12 "This text was typed with a single key press!".to_string(),
13 Duration::from_millis(100),
14 false,
15 ),
16 ),
17 ]);
18 let mut mgr = Manager::new(true, None, None, None, None, macros);
19
20 let mut library = HashMap::with_capacity(2);
21 let cols = 10;
22 let rows = 5;
23 let start_frame = 0;
24 let glyph_1 = Glyph::new(
25 '\u{2580}',
26 Color::new_8bit(0, 0, 5),
27 Color::new_8bit(5, 5, 0),
28 false,
29 true,
30 false,
31 false,
32 false,
33 false,
34 false,
35 false,
36 false,
37 false,
38 );
39 let glyph_2 = Glyph::new(
40 '\u{258C}',
41 Color::new_truecolor(255, 255, 255),
42 Color::new_truecolor(255, 0, 0),
43 false,
44 true,
45 false,
46 false,
47 false,
48 false,
49 false,
50 false,
51 false,
52 false,
53 );
54
55 library.insert(start_frame, vec![glyph_1; rows * cols]);
56 library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
57 let gr = Graphic::new(cols, rows, start_frame, library, None);
58
59 let layer = 0;
60 let offset = (15, 5);
61 let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
62 let screen_size = mgr.screen_size();
63 let title = "Navigation help".to_string();
64 let text = "Press 0 to set current frame to 0\n Press 1 to set current frame to 1\n Press t to type text using macro\n Press AltM to define a macro\n\nPress q or Shift+q to quit\n".to_string();
65 let mbox = message_box(Some(title), text, Glyph::default(), 37, 7);
66 let mbid = mgr.add_graphic(mbox, 1, (1, screen_size.1 as isize - 10));
67 if let Some(mid) = mbid {
68 mgr.set_graphic(mid, 0, true);
69 }
70
71 let mut keep_running = true;
72 mgr.move_cursor(1, 1);
73 let mut macro_mode: u8 = 0;
74 let mut looped = false;
75 while keep_running {
76 let read_result = mgr.read_key();
77 if read_result.is_none() {
78 continue;
79 }
80 let key = read_result.unwrap();
81 if let Some(ch) = map_key_to_char(&key) {
82 if macro_mode == 0 {
83 print!("{}", ch);
84 }
85 }
86 match key {
87 Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
88 Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
89 Key::AltM => match macro_mode {
90 0 => {
91 println!("Press trigger key (or AltM again to toggle macro looping)");
94 macro_mode = 1;
95 }
96 1 => {
97 looped = !looped;
98 println!("Macro looping: {}", looped);
99 }
100 2 => {
101 println!("Macro is defined!");
102 macro_mode = 0;
103 looped = false;
104 }
105 _ => {
106 println!("This should not happen");
107 }
108 },
109 Key::Q | Key::ShiftQ => {
110 keep_running = false;
111 }
112 other => {
113 if macro_mode == 1 {
114 println!("Macro trigger: {}", other);
115 println!("Not type macro sequence, followed by AltM");
116 macro_mode = 2;
117 } else if macro_mode == 2 {
118 println!("Macro sequence add: {}", other)
119 } else {
120 continue;
121 }
122 }
123 }
124 }
125
126 mgr.terminate();
127}