animaterm

Struct Manager

source
pub struct Manager { /* private fields */ }
Expand description

This object is responsible for orchestrating behavior of all screens and graphical elements defined. It also allows for reading user input as char.

Implementations§

source§

impl Manager

source

pub fn new( capture_keyboard: bool, cols: Option<usize>, rows: Option<usize>, glyph: Option<Glyph>, screen_refresh_timeout: Option<Duration>, macros: Option<Vec<(Key, MacroSequence)>>, ) -> Self

Use this method to create a new instance of Manager. One can decide should capturing user input from the keyboard be enabled. macros is used to allow user defining key macros only when capturing keyboard: First element in macros Vec defines a Key which is used to toggle Macro recording e.g. macros: Some(vec![(Key::CtrlM,vec![])]) - pressing CtrlM will toggle Macro recording mode. Following vector elements can be used to insert pre-defined macros in a form: (triggering_key, (looped, Vec<(key_n, delay_n)>)). When user enables macro recording mode it consists of three phases: 0. user enters Macro recording mode by pressing Key::CtrlM; (Optional) if user presses CtrlM again this newly defined macro will be defined as a looping macro - once all keys from it’s sequence have been sent to the user, it starts over again.

  1. pressing first key combination defines triggering key;

  2. pressing second and further key combinations records key, and time duration between current key and following one;

  3. user finishes Macro recording mode by pressing CtrlM;

    To start or stop any macro user has to press it’s triggering key, Starting a new macro automatically stops previous running macro, if any.

Examples found in repository?
examples/example_3.rs (line 6)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let gr = Graphic::new(cols, rows, start_frame, library, None);

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Use arrows to move graphic around \nPress q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 37, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(graphic_id, start_frame, true);
    mgr.set_graphic(mbid, 0, true);

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Left => mgr.move_graphic(graphic_id, layer, (-1, 0)),
                Key::Right => mgr.move_graphic(graphic_id, layer, (1, 0)),
                Key::Up => mgr.move_graphic(graphic_id, layer, (0, -1)),
                Key::Down => mgr.move_graphic(graphic_id, layer, (0, 1)),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
More examples
Hide additional examples
examples/example_4.rs (line 5)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text =
        "Press 0 to select display 0\n Press 1 to select display 1\n Press q or Shift+q to quit\n"
            .to_string();
    let keep_existing = true;
    let first_display_id = 0;
    let mbox = message_box(Some(title.clone()), text.clone(), Glyph::default(), 32, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);
    let empty = Glyph::new(
        ' ',
        Color::green(),
        Color::black(),
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let full = Glyph::new(
        'X',
        Color::green(),
        Color::black(),
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let gid = mgr
        .add_graphic(progress_bar(screen_size.0, empty, full, None), 0, (1, 1))
        .unwrap();
    mgr.start_animation(gid, 0);
    let second_display_id = mgr.new_display(keep_existing);
    // let result = mgr.read_result();
    // if let Ok(AnimOk::DisplayStored(disp_id)) = result {
    //     first_display_id = disp_id;
    // }
    let mbox = message_box(Some(title), text, Glyph::default(), 32, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.restore_display(first_display_id, true),
                Key::One => mgr.restore_display(second_display_id, true),
                Key::Two => mgr.restore_display(2, true),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
examples/example_1.rs (line 18)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
fn main() {
    let macros = Some(vec![
        (Key::AltM, MacroSequence::empty()),
        (
            Key::T,
            MacroSequence::from_text(
                "This text was typed with a single key press!".to_string(),
                Duration::from_millis(100),
                false,
            ),
        ),
    ]);
    let mut mgr = Manager::new(true, None, None, None, None, macros);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let gr = Graphic::new(cols, rows, start_frame, library, None);

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    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();
    let mbox = message_box(Some(title), text, Glyph::default(), 37, 7);
    let mbid = mgr.add_graphic(mbox, 1, (1, screen_size.1 as isize - 10));
    if let Some(mid) = mbid {
        mgr.set_graphic(mid, 0, true);
    }

    let mut keep_running = true;
    mgr.move_cursor(1, 1);
    let mut macro_mode: u8 = 0;
    let mut looped = false;
    while keep_running {
        let read_result = mgr.read_key();
        if read_result.is_none() {
            continue;
        }
        let key = read_result.unwrap();
        if let Some(ch) = map_key_to_char(&key) {
            if macro_mode == 0 {
                print!("{}", ch);
            }
        }
        match key {
            Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
            Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
            Key::AltM => match macro_mode {
                0 => {
                    // let (max_x, may_y)=mgr.screen_size();
                    // mgr.clear_area(0, (0,1),(max_x,4) );
                    println!("Press trigger key (or AltM again to toggle macro looping)");
                    macro_mode = 1;
                }
                1 => {
                    looped = !looped;
                    println!("Macro looping: {}", looped);
                }
                2 => {
                    println!("Macro is defined!");
                    macro_mode = 0;
                    looped = false;
                }
                _ => {
                    println!("This should not happen");
                }
            },
            Key::Q | Key::ShiftQ => {
                keep_running = false;
            }
            other => {
                if macro_mode == 1 {
                    println!("Macro trigger: {}", other);
                    println!("Not type macro sequence, followed by AltM");
                    macro_mode = 2;
                } else if macro_mode == 2 {
                    println!("Macro sequence add: {}", other)
                } else {
                    continue;
                }
            }
        }
    }

    mgr.terminate();
}
examples/example_2.rs (line 6)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let ordering = vec![
        (start_frame, Timestamp::new(0, 500)),
        (start_frame + 1, Timestamp::new(0, 500)),
    ];
    let running = false;
    let looping = true;
    let start_time = Timestamp::now();
    let animation = Animation::new(running, looping, ordering, start_time);
    let mut animations = HashMap::new();
    let anim_id = 0;
    animations.insert(anim_id, animation);
    let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
    let fast_ordering = vec![
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
    ];
    let mut fast_anim_id = anim_id;
    if let Some(id) = gr.add_animation(Animation::new(running, looping, fast_ordering, start_time))
    {
        fast_anim_id = id;
    };

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Press 0 to set current frame to 0\n Press 1 to set current frame to 1\n Press a|Shift+a|Ctrl+a start anim \n Press s or Shift+s stop animation\n\n Press q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 80, 17);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 8))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let var_ordering = vec![
        (start_frame, Timestamp::new(0, 400)),
        (start_frame + 1, Timestamp::new(0, 400)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 100)),
        (start_frame + 1, Timestamp::new(0, 100)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
    ];
    // let mut all_results_read = false;
    // while !all_results_read {
    //     let result = mgr.read_result();
    //     match result {
    //         Ok(AnimOk::AllResultsRead) => all_results_read = true,
    //         _ => continue,
    //     }
    // }
    mgr.add_animation(
        graphic_id,
        Animation::new(false, true, var_ordering, Timestamp::now()),
    );
    let mut var_anim_id = 0;

    if let Ok(AnimOk::AnimationAdded(anim_id)) = mgr.read_result() {
        var_anim_id = anim_id;
    }

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
                Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
                Key::A => mgr.start_animation(graphic_id, anim_id),
                Key::ShiftA => mgr.start_animation(graphic_id, fast_anim_id),
                Key::P => mgr.pause_animation(graphic_id),
                Key::CtrlP => mgr.pause_animation(graphic_id),
                Key::ShiftP => mgr.pause_animation_on_frame(graphic_id, start_frame),
                Key::CtrlA => mgr.start_animation(graphic_id, var_anim_id),
                Key::S | Key::ShiftS => mgr.stop_animation(graphic_id),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
examples/example_5.rs (line 24)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
fn main() {
    let args = parse_arguments();
    let cols = args.cols;
    let rows = args.rows;
    verify_cols_and_rows(cols, rows);
    let mut g = Glyph::default();
    g.set_background(Color::green());
    g.set_char(char::from_u32(9626).unwrap());
    g.set_bright(true);

    let mut mgr = Manager::new(true, cols, rows, Some(g), None, None);
    let (cols, rows) = mgr.screen_size();

    let title = "Navigation help".to_string();
    let text = "CtrlPgUp,CtrlPgDn, -------------------------------------
AltPgUp,AltPgDn, ---------------------------------------
PgUp,PgDn, ---------------------------------------------
U,D, ---------------------------------------------------
CtrlU,CtrlD -------------------------------------------- 
AltU,AltD ----------------------------------------------
AltUp | AltK -------------------------------------------
CtrlUp | CtrlK -----------------------------------------
Up | K -------------------------------------------------
AltDown | AltJ -----------------------------------------
CtrlDown -----------------------------------------------
Down | J -----------------------------------------------
AltLeft | AltH -----------------------------------------
CtrlLeft | Backspace -----------------------------------
Left | H -----------------------------------------------
AltRight | AltL ----------------------------------------
CtrlRight | CtrlL --------------------------------------
Right | L - all above move graphics around the screen --
----------- and up/down layers. ------------------------
Tab - show a message box -------------------------------
Enter - type some text and hit Enter again -------------
        "
    .to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 60, 23);
    let mbid = mgr.add_graphic(mbox, 4, (1, 10)).unwrap();
    mgr.set_graphic(mbid, 0, true);
    let (gr, pid) = build_graphic(130, 10);
    let gr_layer = 1;
    let gid;
    let result = mgr.add_graphic(gr, gr_layer, (3, 15));
    if let Some(id) = result {
        gid = id;
    } else {
        eprintln!("Did not receive first graphic id");
        exit(2);
    }
    mgr.set_graphic(gid, pid, true);

    let pbid;
    let mut pb_layer = 3;
    let result = mgr.add_graphic(
        build_progress_bar(cols - 4),
        pb_layer,
        (2, (rows - 2) as isize),
    );
    if let Some(id) = result {
        pbid = id;
    } else {
        eprintln!("Did not receive progress bar graphic id");
        exit(2);
    }
    mgr.set_graphic(pbid, 0, true);
    mgr.start_animation(pbid, 0);
    let mut mbox_created = false;
    let mut mbox_id = 100;
    let mut mbox_layer = 2;
    if Path::new("index.txg").exists() {
        if let Some(id) =
            mgr.add_graphic(Graphic::from_file("index.txg").unwrap(), mbox_layer, (1, 0))
        {
            mgr.move_graphic(id, 2, (-1, 0));
            mbox_id = id;
            mbox_layer = 4;
        }
    } else {
        eprintln!("\x1b[97;41;5mERR\x1b[m Unable to load index.txg. Run this example from within top examples directory!");
        eprintln!("\x1b[97;41;5mERR\x1b[m Or copy *.txf and index.txg from there to current dir.");
        exit(1);
    }

    loop {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::AltUnicode(uni) => match (uni[2], uni[4]) {
                    (53, 53) => {
                        //CtrlPgUp
                        mgr.move_graphic(1, 4, (0, 0));
                    }
                    (54, 53) => {
                        //CtrlPgDn
                        mgr.move_graphic(1, 1, (0, 0));
                    }
                    (53, 51) => {
                        //AltPgUp
                        mgr.move_graphic(2, 5, (0, 0));
                    }
                    (54, 51) => {
                        //AltPgDn
                        mgr.move_graphic(2, 2, (0, 0));
                    }
                    _ => {}
                },
                Key::PgUp | Key::U => {
                    mgr.move_graphic(0, 3, (0, 0));
                }
                Key::PgDn | Key::D => {
                    mgr.move_graphic(0, 0, (0, 0));
                }
                Key::CtrlU => {
                    pb_layer = 4;
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::CtrlD => {
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::AltU => {
                    mbox_layer = 5;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltD => {
                    mbox_layer = 2;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltUp | Key::AltK => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, -1));
                }
                Key::CtrlUp | Key::CtrlK => {
                    mgr.move_graphic(pbid, pb_layer, (0, -1));
                }
                Key::Up | Key::K => {
                    mgr.stop_animation(gid);
                    mgr.move_graphic(gid, 1, (0, -1));
                    mgr.set_graphic(gid, 1, true);
                }
                Key::AltDown | Key::AltJ => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 1));
                }
                Key::CtrlDown => {
                    mgr.move_graphic(pbid, pb_layer, (0, 1));
                }
                Key::Down | Key::J => {
                    mgr.pause_animation_on_frame(pbid, 100);
                    mgr.move_graphic(gid, 1, (0, 1));
                    mgr.set_graphic(gid, pid, true);
                }
                Key::AltLeft | Key::AltH => {
                    mgr.move_graphic(mbox_id, mbox_layer, (-1, 0));
                }
                Key::CtrlLeft | Key::Backspace => {
                    mgr.move_graphic(pbid, pb_layer, (-1, 0));
                }
                Key::Left | Key::H => {
                    mgr.move_graphic(gid, 1, (-1, 0));
                    mgr.start_animation(gid, 0);
                    mgr.start_animation(pbid, 0);
                }
                Key::AltRight | Key::AltL => {
                    mgr.move_graphic(mbox_id, mbox_layer, (1, 0));
                }
                Key::CtrlRight | Key::CtrlL => {
                    mgr.move_graphic(pbid, pb_layer, (1, 0));
                }
                Key::Right | Key::L => {
                    mgr.move_graphic(gid, 1, (1, 0));
                }
                Key::Tab => {
                    mbox_layer += 1;
                    if !mbox_created {
                        if let  Some(mbid) = mgr.add_graphic(
                            build_mbox(60, 20, "La ku ka ra cza ga wi ga ba ga da da da ja nie".to_string(),
                            "lastBuildDate: Tue, 12 Apr 2022 07:52:44 GMT
* generator: Oddmuse
* copyright: This work is licensed to you under version 2 of the GNU General Public License. Alternatively, you may choose to receive this work under
 any other license that grants the right to use, copy, modify, and distribute the work, as long as that license imposes the restriction that derivative
 works have to grant the same rights and impose the same restriction. For example, you may choose to receive this work under the GNU Free
 Documentation License, the CreativeCommons ShareAlike License, the XEmacs manual license, or similar licenses.
* license: https://creativecommons.org/licenses/sa/1.0/
* license: https://www.gnu.org/copyleft/fdl.html
* license: https://www.gnu.org/copyleft/gpl.html".to_string()                        ),
                        mbox_layer,
                        (0, 0),
                    ){
                        mgr.set_graphic(mbid, 0, true);
                            mbox_created = true;
                            mbox_id = mbid;
                        }
                    }
                }
                Key::CtrlA => {
                    mgr.start_animation(gid, 0);
                }
                Key::CtrlB => {
                    mgr.stop_animation(gid);
                }
                Key::Insert => {
                    mgr.set_graphic(gid, 2, false);
                }
                Key::Delete => {}
                Key::Home => {
                    mgr.set_glyph(gid, Glyph::default(), 1, 1);
                    mgr.move_graphic(gid, 1, (0, 0));
                    mgr.empty_frame(gid);
                }
                Key::Escape | Key::Q | Key::CtrlQ => {
                    break;
                }
                Key::Enter => {
                    if !mbox_created {
                        mbox_layer += 1;
                        if let Some(tid) = mgr.add_graphic(
                            build_mbox(
                                40,
                                1,
                                "Please enter title and hit Enter".to_string(),
                                String::new(),
                            ),
                            mbox_layer,
                            (cols as isize / 2 - 20, rows as isize / 2),
                        ) {
                            mgr.set_graphic(tid, 0, true);
                            let line = mgr.read_line();
                            if let Some(mbid) = mgr.add_graphic(
                                build_mbox(
                                    60,
                                    20,
                                    line,
                                    "Hit Enter to type content in.".to_string(),
                                ),
                                mbox_layer,
                                (0, 0),
                            ) {
                                mgr.delete_graphic(tid);
                                mbox_id = mbid;
                                mgr.set_graphic(mbid, 0, true);
                                mbox_created = true;
                            }
                        }
                    } else {
                        let mut x = 1;
                        let mut y = 1;
                        mbox_created = false;
                        let mut rev = Glyph::default();
                        rev.set_reverse(true);
                        for i in 1..31 {
                            mgr.set_glyph(mbox_id, rev, i, 1);
                        }
                        loop {
                            if let Some(c) = mgr.read_char() {
                                if c == '\t' {
                                    break;
                                }
                                if c as u8 == 8 || c as u8 == 127 {
                                    x -= 1;
                                    if x == 0 {
                                        if y > 1 {
                                            y -= 1;
                                            x = 58;
                                        } else {
                                            x = 1;
                                        }
                                    }
                                    mgr.set_glyph(mbox_id, Glyph::default(), x, y);
                                    continue;
                                }
                                if c == '\n' {
                                    break;
                                }

                                mgr.set_glyph(mbox_id, Glyph::default_with_char(c), x, y);
                                x += 1;
                                if x > 58 {
                                    x = 1;
                                    y += 1;
                                }
                            }
                        }
                    }
                }
                _ => {
                    println!("You pressed: {:?}", key);
                }
            }
        }
    }
    mgr.terminate();
}
source

pub fn get_key_receiver(&mut self) -> Option<Receiver<u8>>

In case one has his own logic for serving raw user input from the keyboard, both for specific case or for all cases.

source

pub fn set_key_receiver( &mut self, receiver: Receiver<u8>, ) -> Option<Receiver<u8>>

Use this method to restore or provide your own key receiver for Manager to take responsibility for interpreting raw user input.

source

pub fn set_key_receive_timeout(&mut self, t: Duration)

Modify how long should Manager wait for bytestream coming from keyboard. In case timeout is too short it might not get entire bytestream for interpretation and provide corrupted output. In case timeout is too long it might feel unresponsive for the user.

source

pub fn get_message_sender(&mut self) -> Sender<Message>

Use return value from this method to send Messages from your own codebase.

source

pub fn read_key(&mut self) -> Option<Key>

Use this method to get a Key value of what user pressed on his keyboard.

Examples found in repository?
examples/example_3.rs (line 62)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let gr = Graphic::new(cols, rows, start_frame, library, None);

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Use arrows to move graphic around \nPress q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 37, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(graphic_id, start_frame, true);
    mgr.set_graphic(mbid, 0, true);

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Left => mgr.move_graphic(graphic_id, layer, (-1, 0)),
                Key::Right => mgr.move_graphic(graphic_id, layer, (1, 0)),
                Key::Up => mgr.move_graphic(graphic_id, layer, (0, -1)),
                Key::Down => mgr.move_graphic(graphic_id, layer, (0, 1)),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
More examples
Hide additional examples
examples/example_4.rs (line 66)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text =
        "Press 0 to select display 0\n Press 1 to select display 1\n Press q or Shift+q to quit\n"
            .to_string();
    let keep_existing = true;
    let first_display_id = 0;
    let mbox = message_box(Some(title.clone()), text.clone(), Glyph::default(), 32, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);
    let empty = Glyph::new(
        ' ',
        Color::green(),
        Color::black(),
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let full = Glyph::new(
        'X',
        Color::green(),
        Color::black(),
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let gid = mgr
        .add_graphic(progress_bar(screen_size.0, empty, full, None), 0, (1, 1))
        .unwrap();
    mgr.start_animation(gid, 0);
    let second_display_id = mgr.new_display(keep_existing);
    // let result = mgr.read_result();
    // if let Ok(AnimOk::DisplayStored(disp_id)) = result {
    //     first_display_id = disp_id;
    // }
    let mbox = message_box(Some(title), text, Glyph::default(), 32, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.restore_display(first_display_id, true),
                Key::One => mgr.restore_display(second_display_id, true),
                Key::Two => mgr.restore_display(2, true),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
examples/example_1.rs (line 76)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
fn main() {
    let macros = Some(vec![
        (Key::AltM, MacroSequence::empty()),
        (
            Key::T,
            MacroSequence::from_text(
                "This text was typed with a single key press!".to_string(),
                Duration::from_millis(100),
                false,
            ),
        ),
    ]);
    let mut mgr = Manager::new(true, None, None, None, None, macros);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let gr = Graphic::new(cols, rows, start_frame, library, None);

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    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();
    let mbox = message_box(Some(title), text, Glyph::default(), 37, 7);
    let mbid = mgr.add_graphic(mbox, 1, (1, screen_size.1 as isize - 10));
    if let Some(mid) = mbid {
        mgr.set_graphic(mid, 0, true);
    }

    let mut keep_running = true;
    mgr.move_cursor(1, 1);
    let mut macro_mode: u8 = 0;
    let mut looped = false;
    while keep_running {
        let read_result = mgr.read_key();
        if read_result.is_none() {
            continue;
        }
        let key = read_result.unwrap();
        if let Some(ch) = map_key_to_char(&key) {
            if macro_mode == 0 {
                print!("{}", ch);
            }
        }
        match key {
            Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
            Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
            Key::AltM => match macro_mode {
                0 => {
                    // let (max_x, may_y)=mgr.screen_size();
                    // mgr.clear_area(0, (0,1),(max_x,4) );
                    println!("Press trigger key (or AltM again to toggle macro looping)");
                    macro_mode = 1;
                }
                1 => {
                    looped = !looped;
                    println!("Macro looping: {}", looped);
                }
                2 => {
                    println!("Macro is defined!");
                    macro_mode = 0;
                    looped = false;
                }
                _ => {
                    println!("This should not happen");
                }
            },
            Key::Q | Key::ShiftQ => {
                keep_running = false;
            }
            other => {
                if macro_mode == 1 {
                    println!("Macro trigger: {}", other);
                    println!("Not type macro sequence, followed by AltM");
                    macro_mode = 2;
                } else if macro_mode == 2 {
                    println!("Macro sequence add: {}", other)
                } else {
                    continue;
                }
            }
        }
    }

    mgr.terminate();
}
examples/example_2.rs (line 113)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let ordering = vec![
        (start_frame, Timestamp::new(0, 500)),
        (start_frame + 1, Timestamp::new(0, 500)),
    ];
    let running = false;
    let looping = true;
    let start_time = Timestamp::now();
    let animation = Animation::new(running, looping, ordering, start_time);
    let mut animations = HashMap::new();
    let anim_id = 0;
    animations.insert(anim_id, animation);
    let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
    let fast_ordering = vec![
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
    ];
    let mut fast_anim_id = anim_id;
    if let Some(id) = gr.add_animation(Animation::new(running, looping, fast_ordering, start_time))
    {
        fast_anim_id = id;
    };

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Press 0 to set current frame to 0\n Press 1 to set current frame to 1\n Press a|Shift+a|Ctrl+a start anim \n Press s or Shift+s stop animation\n\n Press q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 80, 17);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 8))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let var_ordering = vec![
        (start_frame, Timestamp::new(0, 400)),
        (start_frame + 1, Timestamp::new(0, 400)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 100)),
        (start_frame + 1, Timestamp::new(0, 100)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
    ];
    // let mut all_results_read = false;
    // while !all_results_read {
    //     let result = mgr.read_result();
    //     match result {
    //         Ok(AnimOk::AllResultsRead) => all_results_read = true,
    //         _ => continue,
    //     }
    // }
    mgr.add_animation(
        graphic_id,
        Animation::new(false, true, var_ordering, Timestamp::now()),
    );
    let mut var_anim_id = 0;

    if let Ok(AnimOk::AnimationAdded(anim_id)) = mgr.read_result() {
        var_anim_id = anim_id;
    }

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
                Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
                Key::A => mgr.start_animation(graphic_id, anim_id),
                Key::ShiftA => mgr.start_animation(graphic_id, fast_anim_id),
                Key::P => mgr.pause_animation(graphic_id),
                Key::CtrlP => mgr.pause_animation(graphic_id),
                Key::ShiftP => mgr.pause_animation_on_frame(graphic_id, start_frame),
                Key::CtrlA => mgr.start_animation(graphic_id, var_anim_id),
                Key::S | Key::ShiftS => mgr.stop_animation(graphic_id),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
examples/example_5.rs (line 99)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
fn main() {
    let args = parse_arguments();
    let cols = args.cols;
    let rows = args.rows;
    verify_cols_and_rows(cols, rows);
    let mut g = Glyph::default();
    g.set_background(Color::green());
    g.set_char(char::from_u32(9626).unwrap());
    g.set_bright(true);

    let mut mgr = Manager::new(true, cols, rows, Some(g), None, None);
    let (cols, rows) = mgr.screen_size();

    let title = "Navigation help".to_string();
    let text = "CtrlPgUp,CtrlPgDn, -------------------------------------
AltPgUp,AltPgDn, ---------------------------------------
PgUp,PgDn, ---------------------------------------------
U,D, ---------------------------------------------------
CtrlU,CtrlD -------------------------------------------- 
AltU,AltD ----------------------------------------------
AltUp | AltK -------------------------------------------
CtrlUp | CtrlK -----------------------------------------
Up | K -------------------------------------------------
AltDown | AltJ -----------------------------------------
CtrlDown -----------------------------------------------
Down | J -----------------------------------------------
AltLeft | AltH -----------------------------------------
CtrlLeft | Backspace -----------------------------------
Left | H -----------------------------------------------
AltRight | AltL ----------------------------------------
CtrlRight | CtrlL --------------------------------------
Right | L - all above move graphics around the screen --
----------- and up/down layers. ------------------------
Tab - show a message box -------------------------------
Enter - type some text and hit Enter again -------------
        "
    .to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 60, 23);
    let mbid = mgr.add_graphic(mbox, 4, (1, 10)).unwrap();
    mgr.set_graphic(mbid, 0, true);
    let (gr, pid) = build_graphic(130, 10);
    let gr_layer = 1;
    let gid;
    let result = mgr.add_graphic(gr, gr_layer, (3, 15));
    if let Some(id) = result {
        gid = id;
    } else {
        eprintln!("Did not receive first graphic id");
        exit(2);
    }
    mgr.set_graphic(gid, pid, true);

    let pbid;
    let mut pb_layer = 3;
    let result = mgr.add_graphic(
        build_progress_bar(cols - 4),
        pb_layer,
        (2, (rows - 2) as isize),
    );
    if let Some(id) = result {
        pbid = id;
    } else {
        eprintln!("Did not receive progress bar graphic id");
        exit(2);
    }
    mgr.set_graphic(pbid, 0, true);
    mgr.start_animation(pbid, 0);
    let mut mbox_created = false;
    let mut mbox_id = 100;
    let mut mbox_layer = 2;
    if Path::new("index.txg").exists() {
        if let Some(id) =
            mgr.add_graphic(Graphic::from_file("index.txg").unwrap(), mbox_layer, (1, 0))
        {
            mgr.move_graphic(id, 2, (-1, 0));
            mbox_id = id;
            mbox_layer = 4;
        }
    } else {
        eprintln!("\x1b[97;41;5mERR\x1b[m Unable to load index.txg. Run this example from within top examples directory!");
        eprintln!("\x1b[97;41;5mERR\x1b[m Or copy *.txf and index.txg from there to current dir.");
        exit(1);
    }

    loop {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::AltUnicode(uni) => match (uni[2], uni[4]) {
                    (53, 53) => {
                        //CtrlPgUp
                        mgr.move_graphic(1, 4, (0, 0));
                    }
                    (54, 53) => {
                        //CtrlPgDn
                        mgr.move_graphic(1, 1, (0, 0));
                    }
                    (53, 51) => {
                        //AltPgUp
                        mgr.move_graphic(2, 5, (0, 0));
                    }
                    (54, 51) => {
                        //AltPgDn
                        mgr.move_graphic(2, 2, (0, 0));
                    }
                    _ => {}
                },
                Key::PgUp | Key::U => {
                    mgr.move_graphic(0, 3, (0, 0));
                }
                Key::PgDn | Key::D => {
                    mgr.move_graphic(0, 0, (0, 0));
                }
                Key::CtrlU => {
                    pb_layer = 4;
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::CtrlD => {
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::AltU => {
                    mbox_layer = 5;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltD => {
                    mbox_layer = 2;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltUp | Key::AltK => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, -1));
                }
                Key::CtrlUp | Key::CtrlK => {
                    mgr.move_graphic(pbid, pb_layer, (0, -1));
                }
                Key::Up | Key::K => {
                    mgr.stop_animation(gid);
                    mgr.move_graphic(gid, 1, (0, -1));
                    mgr.set_graphic(gid, 1, true);
                }
                Key::AltDown | Key::AltJ => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 1));
                }
                Key::CtrlDown => {
                    mgr.move_graphic(pbid, pb_layer, (0, 1));
                }
                Key::Down | Key::J => {
                    mgr.pause_animation_on_frame(pbid, 100);
                    mgr.move_graphic(gid, 1, (0, 1));
                    mgr.set_graphic(gid, pid, true);
                }
                Key::AltLeft | Key::AltH => {
                    mgr.move_graphic(mbox_id, mbox_layer, (-1, 0));
                }
                Key::CtrlLeft | Key::Backspace => {
                    mgr.move_graphic(pbid, pb_layer, (-1, 0));
                }
                Key::Left | Key::H => {
                    mgr.move_graphic(gid, 1, (-1, 0));
                    mgr.start_animation(gid, 0);
                    mgr.start_animation(pbid, 0);
                }
                Key::AltRight | Key::AltL => {
                    mgr.move_graphic(mbox_id, mbox_layer, (1, 0));
                }
                Key::CtrlRight | Key::CtrlL => {
                    mgr.move_graphic(pbid, pb_layer, (1, 0));
                }
                Key::Right | Key::L => {
                    mgr.move_graphic(gid, 1, (1, 0));
                }
                Key::Tab => {
                    mbox_layer += 1;
                    if !mbox_created {
                        if let  Some(mbid) = mgr.add_graphic(
                            build_mbox(60, 20, "La ku ka ra cza ga wi ga ba ga da da da ja nie".to_string(),
                            "lastBuildDate: Tue, 12 Apr 2022 07:52:44 GMT
* generator: Oddmuse
* copyright: This work is licensed to you under version 2 of the GNU General Public License. Alternatively, you may choose to receive this work under
 any other license that grants the right to use, copy, modify, and distribute the work, as long as that license imposes the restriction that derivative
 works have to grant the same rights and impose the same restriction. For example, you may choose to receive this work under the GNU Free
 Documentation License, the CreativeCommons ShareAlike License, the XEmacs manual license, or similar licenses.
* license: https://creativecommons.org/licenses/sa/1.0/
* license: https://www.gnu.org/copyleft/fdl.html
* license: https://www.gnu.org/copyleft/gpl.html".to_string()                        ),
                        mbox_layer,
                        (0, 0),
                    ){
                        mgr.set_graphic(mbid, 0, true);
                            mbox_created = true;
                            mbox_id = mbid;
                        }
                    }
                }
                Key::CtrlA => {
                    mgr.start_animation(gid, 0);
                }
                Key::CtrlB => {
                    mgr.stop_animation(gid);
                }
                Key::Insert => {
                    mgr.set_graphic(gid, 2, false);
                }
                Key::Delete => {}
                Key::Home => {
                    mgr.set_glyph(gid, Glyph::default(), 1, 1);
                    mgr.move_graphic(gid, 1, (0, 0));
                    mgr.empty_frame(gid);
                }
                Key::Escape | Key::Q | Key::CtrlQ => {
                    break;
                }
                Key::Enter => {
                    if !mbox_created {
                        mbox_layer += 1;
                        if let Some(tid) = mgr.add_graphic(
                            build_mbox(
                                40,
                                1,
                                "Please enter title and hit Enter".to_string(),
                                String::new(),
                            ),
                            mbox_layer,
                            (cols as isize / 2 - 20, rows as isize / 2),
                        ) {
                            mgr.set_graphic(tid, 0, true);
                            let line = mgr.read_line();
                            if let Some(mbid) = mgr.add_graphic(
                                build_mbox(
                                    60,
                                    20,
                                    line,
                                    "Hit Enter to type content in.".to_string(),
                                ),
                                mbox_layer,
                                (0, 0),
                            ) {
                                mgr.delete_graphic(tid);
                                mbox_id = mbid;
                                mgr.set_graphic(mbid, 0, true);
                                mbox_created = true;
                            }
                        }
                    } else {
                        let mut x = 1;
                        let mut y = 1;
                        mbox_created = false;
                        let mut rev = Glyph::default();
                        rev.set_reverse(true);
                        for i in 1..31 {
                            mgr.set_glyph(mbox_id, rev, i, 1);
                        }
                        loop {
                            if let Some(c) = mgr.read_char() {
                                if c == '\t' {
                                    break;
                                }
                                if c as u8 == 8 || c as u8 == 127 {
                                    x -= 1;
                                    if x == 0 {
                                        if y > 1 {
                                            y -= 1;
                                            x = 58;
                                        } else {
                                            x = 1;
                                        }
                                    }
                                    mgr.set_glyph(mbox_id, Glyph::default(), x, y);
                                    continue;
                                }
                                if c == '\n' {
                                    break;
                                }

                                mgr.set_glyph(mbox_id, Glyph::default_with_char(c), x, y);
                                x += 1;
                                if x > 58 {
                                    x = 1;
                                    y += 1;
                                }
                            }
                        }
                    }
                }
                _ => {
                    println!("You pressed: {:?}", key);
                }
            }
        }
    }
    mgr.terminate();
}
source

pub fn read_line(&mut self) -> String

Use this method to get a String of what user has entered up to Enter key.

Examples found in repository?
examples/example_5.rs (line 238)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
fn main() {
    let args = parse_arguments();
    let cols = args.cols;
    let rows = args.rows;
    verify_cols_and_rows(cols, rows);
    let mut g = Glyph::default();
    g.set_background(Color::green());
    g.set_char(char::from_u32(9626).unwrap());
    g.set_bright(true);

    let mut mgr = Manager::new(true, cols, rows, Some(g), None, None);
    let (cols, rows) = mgr.screen_size();

    let title = "Navigation help".to_string();
    let text = "CtrlPgUp,CtrlPgDn, -------------------------------------
AltPgUp,AltPgDn, ---------------------------------------
PgUp,PgDn, ---------------------------------------------
U,D, ---------------------------------------------------
CtrlU,CtrlD -------------------------------------------- 
AltU,AltD ----------------------------------------------
AltUp | AltK -------------------------------------------
CtrlUp | CtrlK -----------------------------------------
Up | K -------------------------------------------------
AltDown | AltJ -----------------------------------------
CtrlDown -----------------------------------------------
Down | J -----------------------------------------------
AltLeft | AltH -----------------------------------------
CtrlLeft | Backspace -----------------------------------
Left | H -----------------------------------------------
AltRight | AltL ----------------------------------------
CtrlRight | CtrlL --------------------------------------
Right | L - all above move graphics around the screen --
----------- and up/down layers. ------------------------
Tab - show a message box -------------------------------
Enter - type some text and hit Enter again -------------
        "
    .to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 60, 23);
    let mbid = mgr.add_graphic(mbox, 4, (1, 10)).unwrap();
    mgr.set_graphic(mbid, 0, true);
    let (gr, pid) = build_graphic(130, 10);
    let gr_layer = 1;
    let gid;
    let result = mgr.add_graphic(gr, gr_layer, (3, 15));
    if let Some(id) = result {
        gid = id;
    } else {
        eprintln!("Did not receive first graphic id");
        exit(2);
    }
    mgr.set_graphic(gid, pid, true);

    let pbid;
    let mut pb_layer = 3;
    let result = mgr.add_graphic(
        build_progress_bar(cols - 4),
        pb_layer,
        (2, (rows - 2) as isize),
    );
    if let Some(id) = result {
        pbid = id;
    } else {
        eprintln!("Did not receive progress bar graphic id");
        exit(2);
    }
    mgr.set_graphic(pbid, 0, true);
    mgr.start_animation(pbid, 0);
    let mut mbox_created = false;
    let mut mbox_id = 100;
    let mut mbox_layer = 2;
    if Path::new("index.txg").exists() {
        if let Some(id) =
            mgr.add_graphic(Graphic::from_file("index.txg").unwrap(), mbox_layer, (1, 0))
        {
            mgr.move_graphic(id, 2, (-1, 0));
            mbox_id = id;
            mbox_layer = 4;
        }
    } else {
        eprintln!("\x1b[97;41;5mERR\x1b[m Unable to load index.txg. Run this example from within top examples directory!");
        eprintln!("\x1b[97;41;5mERR\x1b[m Or copy *.txf and index.txg from there to current dir.");
        exit(1);
    }

    loop {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::AltUnicode(uni) => match (uni[2], uni[4]) {
                    (53, 53) => {
                        //CtrlPgUp
                        mgr.move_graphic(1, 4, (0, 0));
                    }
                    (54, 53) => {
                        //CtrlPgDn
                        mgr.move_graphic(1, 1, (0, 0));
                    }
                    (53, 51) => {
                        //AltPgUp
                        mgr.move_graphic(2, 5, (0, 0));
                    }
                    (54, 51) => {
                        //AltPgDn
                        mgr.move_graphic(2, 2, (0, 0));
                    }
                    _ => {}
                },
                Key::PgUp | Key::U => {
                    mgr.move_graphic(0, 3, (0, 0));
                }
                Key::PgDn | Key::D => {
                    mgr.move_graphic(0, 0, (0, 0));
                }
                Key::CtrlU => {
                    pb_layer = 4;
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::CtrlD => {
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::AltU => {
                    mbox_layer = 5;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltD => {
                    mbox_layer = 2;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltUp | Key::AltK => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, -1));
                }
                Key::CtrlUp | Key::CtrlK => {
                    mgr.move_graphic(pbid, pb_layer, (0, -1));
                }
                Key::Up | Key::K => {
                    mgr.stop_animation(gid);
                    mgr.move_graphic(gid, 1, (0, -1));
                    mgr.set_graphic(gid, 1, true);
                }
                Key::AltDown | Key::AltJ => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 1));
                }
                Key::CtrlDown => {
                    mgr.move_graphic(pbid, pb_layer, (0, 1));
                }
                Key::Down | Key::J => {
                    mgr.pause_animation_on_frame(pbid, 100);
                    mgr.move_graphic(gid, 1, (0, 1));
                    mgr.set_graphic(gid, pid, true);
                }
                Key::AltLeft | Key::AltH => {
                    mgr.move_graphic(mbox_id, mbox_layer, (-1, 0));
                }
                Key::CtrlLeft | Key::Backspace => {
                    mgr.move_graphic(pbid, pb_layer, (-1, 0));
                }
                Key::Left | Key::H => {
                    mgr.move_graphic(gid, 1, (-1, 0));
                    mgr.start_animation(gid, 0);
                    mgr.start_animation(pbid, 0);
                }
                Key::AltRight | Key::AltL => {
                    mgr.move_graphic(mbox_id, mbox_layer, (1, 0));
                }
                Key::CtrlRight | Key::CtrlL => {
                    mgr.move_graphic(pbid, pb_layer, (1, 0));
                }
                Key::Right | Key::L => {
                    mgr.move_graphic(gid, 1, (1, 0));
                }
                Key::Tab => {
                    mbox_layer += 1;
                    if !mbox_created {
                        if let  Some(mbid) = mgr.add_graphic(
                            build_mbox(60, 20, "La ku ka ra cza ga wi ga ba ga da da da ja nie".to_string(),
                            "lastBuildDate: Tue, 12 Apr 2022 07:52:44 GMT
* generator: Oddmuse
* copyright: This work is licensed to you under version 2 of the GNU General Public License. Alternatively, you may choose to receive this work under
 any other license that grants the right to use, copy, modify, and distribute the work, as long as that license imposes the restriction that derivative
 works have to grant the same rights and impose the same restriction. For example, you may choose to receive this work under the GNU Free
 Documentation License, the CreativeCommons ShareAlike License, the XEmacs manual license, or similar licenses.
* license: https://creativecommons.org/licenses/sa/1.0/
* license: https://www.gnu.org/copyleft/fdl.html
* license: https://www.gnu.org/copyleft/gpl.html".to_string()                        ),
                        mbox_layer,
                        (0, 0),
                    ){
                        mgr.set_graphic(mbid, 0, true);
                            mbox_created = true;
                            mbox_id = mbid;
                        }
                    }
                }
                Key::CtrlA => {
                    mgr.start_animation(gid, 0);
                }
                Key::CtrlB => {
                    mgr.stop_animation(gid);
                }
                Key::Insert => {
                    mgr.set_graphic(gid, 2, false);
                }
                Key::Delete => {}
                Key::Home => {
                    mgr.set_glyph(gid, Glyph::default(), 1, 1);
                    mgr.move_graphic(gid, 1, (0, 0));
                    mgr.empty_frame(gid);
                }
                Key::Escape | Key::Q | Key::CtrlQ => {
                    break;
                }
                Key::Enter => {
                    if !mbox_created {
                        mbox_layer += 1;
                        if let Some(tid) = mgr.add_graphic(
                            build_mbox(
                                40,
                                1,
                                "Please enter title and hit Enter".to_string(),
                                String::new(),
                            ),
                            mbox_layer,
                            (cols as isize / 2 - 20, rows as isize / 2),
                        ) {
                            mgr.set_graphic(tid, 0, true);
                            let line = mgr.read_line();
                            if let Some(mbid) = mgr.add_graphic(
                                build_mbox(
                                    60,
                                    20,
                                    line,
                                    "Hit Enter to type content in.".to_string(),
                                ),
                                mbox_layer,
                                (0, 0),
                            ) {
                                mgr.delete_graphic(tid);
                                mbox_id = mbid;
                                mgr.set_graphic(mbid, 0, true);
                                mbox_created = true;
                            }
                        }
                    } else {
                        let mut x = 1;
                        let mut y = 1;
                        mbox_created = false;
                        let mut rev = Glyph::default();
                        rev.set_reverse(true);
                        for i in 1..31 {
                            mgr.set_glyph(mbox_id, rev, i, 1);
                        }
                        loop {
                            if let Some(c) = mgr.read_char() {
                                if c == '\t' {
                                    break;
                                }
                                if c as u8 == 8 || c as u8 == 127 {
                                    x -= 1;
                                    if x == 0 {
                                        if y > 1 {
                                            y -= 1;
                                            x = 58;
                                        } else {
                                            x = 1;
                                        }
                                    }
                                    mgr.set_glyph(mbox_id, Glyph::default(), x, y);
                                    continue;
                                }
                                if c == '\n' {
                                    break;
                                }

                                mgr.set_glyph(mbox_id, Glyph::default_with_char(c), x, y);
                                x += 1;
                                if x > 58 {
                                    x = 1;
                                    y += 1;
                                }
                            }
                        }
                    }
                }
                _ => {
                    println!("You pressed: {:?}", key);
                }
            }
        }
    }
    mgr.terminate();
}
source

pub fn read_char(&mut self) -> Option<char>

Use this method to get a char of what user has entered on his keyboard.

Examples found in repository?
examples/example_5.rs (line 265)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
fn main() {
    let args = parse_arguments();
    let cols = args.cols;
    let rows = args.rows;
    verify_cols_and_rows(cols, rows);
    let mut g = Glyph::default();
    g.set_background(Color::green());
    g.set_char(char::from_u32(9626).unwrap());
    g.set_bright(true);

    let mut mgr = Manager::new(true, cols, rows, Some(g), None, None);
    let (cols, rows) = mgr.screen_size();

    let title = "Navigation help".to_string();
    let text = "CtrlPgUp,CtrlPgDn, -------------------------------------
AltPgUp,AltPgDn, ---------------------------------------
PgUp,PgDn, ---------------------------------------------
U,D, ---------------------------------------------------
CtrlU,CtrlD -------------------------------------------- 
AltU,AltD ----------------------------------------------
AltUp | AltK -------------------------------------------
CtrlUp | CtrlK -----------------------------------------
Up | K -------------------------------------------------
AltDown | AltJ -----------------------------------------
CtrlDown -----------------------------------------------
Down | J -----------------------------------------------
AltLeft | AltH -----------------------------------------
CtrlLeft | Backspace -----------------------------------
Left | H -----------------------------------------------
AltRight | AltL ----------------------------------------
CtrlRight | CtrlL --------------------------------------
Right | L - all above move graphics around the screen --
----------- and up/down layers. ------------------------
Tab - show a message box -------------------------------
Enter - type some text and hit Enter again -------------
        "
    .to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 60, 23);
    let mbid = mgr.add_graphic(mbox, 4, (1, 10)).unwrap();
    mgr.set_graphic(mbid, 0, true);
    let (gr, pid) = build_graphic(130, 10);
    let gr_layer = 1;
    let gid;
    let result = mgr.add_graphic(gr, gr_layer, (3, 15));
    if let Some(id) = result {
        gid = id;
    } else {
        eprintln!("Did not receive first graphic id");
        exit(2);
    }
    mgr.set_graphic(gid, pid, true);

    let pbid;
    let mut pb_layer = 3;
    let result = mgr.add_graphic(
        build_progress_bar(cols - 4),
        pb_layer,
        (2, (rows - 2) as isize),
    );
    if let Some(id) = result {
        pbid = id;
    } else {
        eprintln!("Did not receive progress bar graphic id");
        exit(2);
    }
    mgr.set_graphic(pbid, 0, true);
    mgr.start_animation(pbid, 0);
    let mut mbox_created = false;
    let mut mbox_id = 100;
    let mut mbox_layer = 2;
    if Path::new("index.txg").exists() {
        if let Some(id) =
            mgr.add_graphic(Graphic::from_file("index.txg").unwrap(), mbox_layer, (1, 0))
        {
            mgr.move_graphic(id, 2, (-1, 0));
            mbox_id = id;
            mbox_layer = 4;
        }
    } else {
        eprintln!("\x1b[97;41;5mERR\x1b[m Unable to load index.txg. Run this example from within top examples directory!");
        eprintln!("\x1b[97;41;5mERR\x1b[m Or copy *.txf and index.txg from there to current dir.");
        exit(1);
    }

    loop {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::AltUnicode(uni) => match (uni[2], uni[4]) {
                    (53, 53) => {
                        //CtrlPgUp
                        mgr.move_graphic(1, 4, (0, 0));
                    }
                    (54, 53) => {
                        //CtrlPgDn
                        mgr.move_graphic(1, 1, (0, 0));
                    }
                    (53, 51) => {
                        //AltPgUp
                        mgr.move_graphic(2, 5, (0, 0));
                    }
                    (54, 51) => {
                        //AltPgDn
                        mgr.move_graphic(2, 2, (0, 0));
                    }
                    _ => {}
                },
                Key::PgUp | Key::U => {
                    mgr.move_graphic(0, 3, (0, 0));
                }
                Key::PgDn | Key::D => {
                    mgr.move_graphic(0, 0, (0, 0));
                }
                Key::CtrlU => {
                    pb_layer = 4;
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::CtrlD => {
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::AltU => {
                    mbox_layer = 5;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltD => {
                    mbox_layer = 2;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltUp | Key::AltK => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, -1));
                }
                Key::CtrlUp | Key::CtrlK => {
                    mgr.move_graphic(pbid, pb_layer, (0, -1));
                }
                Key::Up | Key::K => {
                    mgr.stop_animation(gid);
                    mgr.move_graphic(gid, 1, (0, -1));
                    mgr.set_graphic(gid, 1, true);
                }
                Key::AltDown | Key::AltJ => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 1));
                }
                Key::CtrlDown => {
                    mgr.move_graphic(pbid, pb_layer, (0, 1));
                }
                Key::Down | Key::J => {
                    mgr.pause_animation_on_frame(pbid, 100);
                    mgr.move_graphic(gid, 1, (0, 1));
                    mgr.set_graphic(gid, pid, true);
                }
                Key::AltLeft | Key::AltH => {
                    mgr.move_graphic(mbox_id, mbox_layer, (-1, 0));
                }
                Key::CtrlLeft | Key::Backspace => {
                    mgr.move_graphic(pbid, pb_layer, (-1, 0));
                }
                Key::Left | Key::H => {
                    mgr.move_graphic(gid, 1, (-1, 0));
                    mgr.start_animation(gid, 0);
                    mgr.start_animation(pbid, 0);
                }
                Key::AltRight | Key::AltL => {
                    mgr.move_graphic(mbox_id, mbox_layer, (1, 0));
                }
                Key::CtrlRight | Key::CtrlL => {
                    mgr.move_graphic(pbid, pb_layer, (1, 0));
                }
                Key::Right | Key::L => {
                    mgr.move_graphic(gid, 1, (1, 0));
                }
                Key::Tab => {
                    mbox_layer += 1;
                    if !mbox_created {
                        if let  Some(mbid) = mgr.add_graphic(
                            build_mbox(60, 20, "La ku ka ra cza ga wi ga ba ga da da da ja nie".to_string(),
                            "lastBuildDate: Tue, 12 Apr 2022 07:52:44 GMT
* generator: Oddmuse
* copyright: This work is licensed to you under version 2 of the GNU General Public License. Alternatively, you may choose to receive this work under
 any other license that grants the right to use, copy, modify, and distribute the work, as long as that license imposes the restriction that derivative
 works have to grant the same rights and impose the same restriction. For example, you may choose to receive this work under the GNU Free
 Documentation License, the CreativeCommons ShareAlike License, the XEmacs manual license, or similar licenses.
* license: https://creativecommons.org/licenses/sa/1.0/
* license: https://www.gnu.org/copyleft/fdl.html
* license: https://www.gnu.org/copyleft/gpl.html".to_string()                        ),
                        mbox_layer,
                        (0, 0),
                    ){
                        mgr.set_graphic(mbid, 0, true);
                            mbox_created = true;
                            mbox_id = mbid;
                        }
                    }
                }
                Key::CtrlA => {
                    mgr.start_animation(gid, 0);
                }
                Key::CtrlB => {
                    mgr.stop_animation(gid);
                }
                Key::Insert => {
                    mgr.set_graphic(gid, 2, false);
                }
                Key::Delete => {}
                Key::Home => {
                    mgr.set_glyph(gid, Glyph::default(), 1, 1);
                    mgr.move_graphic(gid, 1, (0, 0));
                    mgr.empty_frame(gid);
                }
                Key::Escape | Key::Q | Key::CtrlQ => {
                    break;
                }
                Key::Enter => {
                    if !mbox_created {
                        mbox_layer += 1;
                        if let Some(tid) = mgr.add_graphic(
                            build_mbox(
                                40,
                                1,
                                "Please enter title and hit Enter".to_string(),
                                String::new(),
                            ),
                            mbox_layer,
                            (cols as isize / 2 - 20, rows as isize / 2),
                        ) {
                            mgr.set_graphic(tid, 0, true);
                            let line = mgr.read_line();
                            if let Some(mbid) = mgr.add_graphic(
                                build_mbox(
                                    60,
                                    20,
                                    line,
                                    "Hit Enter to type content in.".to_string(),
                                ),
                                mbox_layer,
                                (0, 0),
                            ) {
                                mgr.delete_graphic(tid);
                                mbox_id = mbid;
                                mgr.set_graphic(mbid, 0, true);
                                mbox_created = true;
                            }
                        }
                    } else {
                        let mut x = 1;
                        let mut y = 1;
                        mbox_created = false;
                        let mut rev = Glyph::default();
                        rev.set_reverse(true);
                        for i in 1..31 {
                            mgr.set_glyph(mbox_id, rev, i, 1);
                        }
                        loop {
                            if let Some(c) = mgr.read_char() {
                                if c == '\t' {
                                    break;
                                }
                                if c as u8 == 8 || c as u8 == 127 {
                                    x -= 1;
                                    if x == 0 {
                                        if y > 1 {
                                            y -= 1;
                                            x = 58;
                                        } else {
                                            x = 1;
                                        }
                                    }
                                    mgr.set_glyph(mbox_id, Glyph::default(), x, y);
                                    continue;
                                }
                                if c == '\n' {
                                    break;
                                }

                                mgr.set_glyph(mbox_id, Glyph::default_with_char(c), x, y);
                                x += 1;
                                if x > 58 {
                                    x = 1;
                                    y += 1;
                                }
                            }
                        }
                    }
                }
                _ => {
                    println!("You pressed: {:?}", key);
                }
            }
        }
    }
    mgr.terminate();
}
source

pub fn set_result_iter( &mut self, receiver: IntoIter<Result<AnimOk, AnimError>>, ) -> Option<IntoIter<Result<AnimOk, AnimError>>>

Use this method in case you want Manager to take back servicing results on his actions.

source

pub fn read_result(&mut self) -> Result<AnimOk, AnimError>

Use this method to get next available result of Manager’s action.

Examples found in repository?
examples/example_2.rs (line 107)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let ordering = vec![
        (start_frame, Timestamp::new(0, 500)),
        (start_frame + 1, Timestamp::new(0, 500)),
    ];
    let running = false;
    let looping = true;
    let start_time = Timestamp::now();
    let animation = Animation::new(running, looping, ordering, start_time);
    let mut animations = HashMap::new();
    let anim_id = 0;
    animations.insert(anim_id, animation);
    let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
    let fast_ordering = vec![
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
    ];
    let mut fast_anim_id = anim_id;
    if let Some(id) = gr.add_animation(Animation::new(running, looping, fast_ordering, start_time))
    {
        fast_anim_id = id;
    };

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Press 0 to set current frame to 0\n Press 1 to set current frame to 1\n Press a|Shift+a|Ctrl+a start anim \n Press s or Shift+s stop animation\n\n Press q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 80, 17);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 8))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let var_ordering = vec![
        (start_frame, Timestamp::new(0, 400)),
        (start_frame + 1, Timestamp::new(0, 400)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 100)),
        (start_frame + 1, Timestamp::new(0, 100)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
    ];
    // let mut all_results_read = false;
    // while !all_results_read {
    //     let result = mgr.read_result();
    //     match result {
    //         Ok(AnimOk::AllResultsRead) => all_results_read = true,
    //         _ => continue,
    //     }
    // }
    mgr.add_animation(
        graphic_id,
        Animation::new(false, true, var_ordering, Timestamp::now()),
    );
    let mut var_anim_id = 0;

    if let Ok(AnimOk::AnimationAdded(anim_id)) = mgr.read_result() {
        var_anim_id = anim_id;
    }

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
                Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
                Key::A => mgr.start_animation(graphic_id, anim_id),
                Key::ShiftA => mgr.start_animation(graphic_id, fast_anim_id),
                Key::P => mgr.pause_animation(graphic_id),
                Key::CtrlP => mgr.pause_animation(graphic_id),
                Key::ShiftP => mgr.pause_animation_on_frame(graphic_id, start_frame),
                Key::CtrlA => mgr.start_animation(graphic_id, var_anim_id),
                Key::S | Key::ShiftS => mgr.stop_animation(graphic_id),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
source

pub fn screen_size(&self) -> (usize, usize)

Returns width & height of current screen.

Examples found in repository?
examples/example_3.rs (line 50)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let gr = Graphic::new(cols, rows, start_frame, library, None);

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Use arrows to move graphic around \nPress q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 37, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(graphic_id, start_frame, true);
    mgr.set_graphic(mbid, 0, true);

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Left => mgr.move_graphic(graphic_id, layer, (-1, 0)),
                Key::Right => mgr.move_graphic(graphic_id, layer, (1, 0)),
                Key::Up => mgr.move_graphic(graphic_id, layer, (0, -1)),
                Key::Down => mgr.move_graphic(graphic_id, layer, (0, 1)),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
More examples
Hide additional examples
examples/example_4.rs (line 7)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text =
        "Press 0 to select display 0\n Press 1 to select display 1\n Press q or Shift+q to quit\n"
            .to_string();
    let keep_existing = true;
    let first_display_id = 0;
    let mbox = message_box(Some(title.clone()), text.clone(), Glyph::default(), 32, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);
    let empty = Glyph::new(
        ' ',
        Color::green(),
        Color::black(),
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let full = Glyph::new(
        'X',
        Color::green(),
        Color::black(),
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let gid = mgr
        .add_graphic(progress_bar(screen_size.0, empty, full, None), 0, (1, 1))
        .unwrap();
    mgr.start_animation(gid, 0);
    let second_display_id = mgr.new_display(keep_existing);
    // let result = mgr.read_result();
    // if let Ok(AnimOk::DisplayStored(disp_id)) = result {
    //     first_display_id = disp_id;
    // }
    let mbox = message_box(Some(title), text, Glyph::default(), 32, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.restore_display(first_display_id, true),
                Key::One => mgr.restore_display(second_display_id, true),
                Key::Two => mgr.restore_display(2, true),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
examples/example_1.rs (line 62)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
fn main() {
    let macros = Some(vec![
        (Key::AltM, MacroSequence::empty()),
        (
            Key::T,
            MacroSequence::from_text(
                "This text was typed with a single key press!".to_string(),
                Duration::from_millis(100),
                false,
            ),
        ),
    ]);
    let mut mgr = Manager::new(true, None, None, None, None, macros);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let gr = Graphic::new(cols, rows, start_frame, library, None);

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    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();
    let mbox = message_box(Some(title), text, Glyph::default(), 37, 7);
    let mbid = mgr.add_graphic(mbox, 1, (1, screen_size.1 as isize - 10));
    if let Some(mid) = mbid {
        mgr.set_graphic(mid, 0, true);
    }

    let mut keep_running = true;
    mgr.move_cursor(1, 1);
    let mut macro_mode: u8 = 0;
    let mut looped = false;
    while keep_running {
        let read_result = mgr.read_key();
        if read_result.is_none() {
            continue;
        }
        let key = read_result.unwrap();
        if let Some(ch) = map_key_to_char(&key) {
            if macro_mode == 0 {
                print!("{}", ch);
            }
        }
        match key {
            Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
            Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
            Key::AltM => match macro_mode {
                0 => {
                    // let (max_x, may_y)=mgr.screen_size();
                    // mgr.clear_area(0, (0,1),(max_x,4) );
                    println!("Press trigger key (or AltM again to toggle macro looping)");
                    macro_mode = 1;
                }
                1 => {
                    looped = !looped;
                    println!("Macro looping: {}", looped);
                }
                2 => {
                    println!("Macro is defined!");
                    macro_mode = 0;
                    looped = false;
                }
                _ => {
                    println!("This should not happen");
                }
            },
            Key::Q | Key::ShiftQ => {
                keep_running = false;
            }
            other => {
                if macro_mode == 1 {
                    println!("Macro trigger: {}", other);
                    println!("Not type macro sequence, followed by AltM");
                    macro_mode = 2;
                } else if macro_mode == 2 {
                    println!("Macro sequence add: {}", other)
                } else {
                    continue;
                }
            }
        }
    }

    mgr.terminate();
}
examples/example_2.rs (line 70)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let ordering = vec![
        (start_frame, Timestamp::new(0, 500)),
        (start_frame + 1, Timestamp::new(0, 500)),
    ];
    let running = false;
    let looping = true;
    let start_time = Timestamp::now();
    let animation = Animation::new(running, looping, ordering, start_time);
    let mut animations = HashMap::new();
    let anim_id = 0;
    animations.insert(anim_id, animation);
    let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
    let fast_ordering = vec![
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
    ];
    let mut fast_anim_id = anim_id;
    if let Some(id) = gr.add_animation(Animation::new(running, looping, fast_ordering, start_time))
    {
        fast_anim_id = id;
    };

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Press 0 to set current frame to 0\n Press 1 to set current frame to 1\n Press a|Shift+a|Ctrl+a start anim \n Press s or Shift+s stop animation\n\n Press q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 80, 17);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 8))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let var_ordering = vec![
        (start_frame, Timestamp::new(0, 400)),
        (start_frame + 1, Timestamp::new(0, 400)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 100)),
        (start_frame + 1, Timestamp::new(0, 100)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
    ];
    // let mut all_results_read = false;
    // while !all_results_read {
    //     let result = mgr.read_result();
    //     match result {
    //         Ok(AnimOk::AllResultsRead) => all_results_read = true,
    //         _ => continue,
    //     }
    // }
    mgr.add_animation(
        graphic_id,
        Animation::new(false, true, var_ordering, Timestamp::now()),
    );
    let mut var_anim_id = 0;

    if let Ok(AnimOk::AnimationAdded(anim_id)) = mgr.read_result() {
        var_anim_id = anim_id;
    }

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
                Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
                Key::A => mgr.start_animation(graphic_id, anim_id),
                Key::ShiftA => mgr.start_animation(graphic_id, fast_anim_id),
                Key::P => mgr.pause_animation(graphic_id),
                Key::CtrlP => mgr.pause_animation(graphic_id),
                Key::ShiftP => mgr.pause_animation_on_frame(graphic_id, start_frame),
                Key::CtrlA => mgr.start_animation(graphic_id, var_anim_id),
                Key::S | Key::ShiftS => mgr.stop_animation(graphic_id),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
examples/example_5.rs (line 25)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
fn main() {
    let args = parse_arguments();
    let cols = args.cols;
    let rows = args.rows;
    verify_cols_and_rows(cols, rows);
    let mut g = Glyph::default();
    g.set_background(Color::green());
    g.set_char(char::from_u32(9626).unwrap());
    g.set_bright(true);

    let mut mgr = Manager::new(true, cols, rows, Some(g), None, None);
    let (cols, rows) = mgr.screen_size();

    let title = "Navigation help".to_string();
    let text = "CtrlPgUp,CtrlPgDn, -------------------------------------
AltPgUp,AltPgDn, ---------------------------------------
PgUp,PgDn, ---------------------------------------------
U,D, ---------------------------------------------------
CtrlU,CtrlD -------------------------------------------- 
AltU,AltD ----------------------------------------------
AltUp | AltK -------------------------------------------
CtrlUp | CtrlK -----------------------------------------
Up | K -------------------------------------------------
AltDown | AltJ -----------------------------------------
CtrlDown -----------------------------------------------
Down | J -----------------------------------------------
AltLeft | AltH -----------------------------------------
CtrlLeft | Backspace -----------------------------------
Left | H -----------------------------------------------
AltRight | AltL ----------------------------------------
CtrlRight | CtrlL --------------------------------------
Right | L - all above move graphics around the screen --
----------- and up/down layers. ------------------------
Tab - show a message box -------------------------------
Enter - type some text and hit Enter again -------------
        "
    .to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 60, 23);
    let mbid = mgr.add_graphic(mbox, 4, (1, 10)).unwrap();
    mgr.set_graphic(mbid, 0, true);
    let (gr, pid) = build_graphic(130, 10);
    let gr_layer = 1;
    let gid;
    let result = mgr.add_graphic(gr, gr_layer, (3, 15));
    if let Some(id) = result {
        gid = id;
    } else {
        eprintln!("Did not receive first graphic id");
        exit(2);
    }
    mgr.set_graphic(gid, pid, true);

    let pbid;
    let mut pb_layer = 3;
    let result = mgr.add_graphic(
        build_progress_bar(cols - 4),
        pb_layer,
        (2, (rows - 2) as isize),
    );
    if let Some(id) = result {
        pbid = id;
    } else {
        eprintln!("Did not receive progress bar graphic id");
        exit(2);
    }
    mgr.set_graphic(pbid, 0, true);
    mgr.start_animation(pbid, 0);
    let mut mbox_created = false;
    let mut mbox_id = 100;
    let mut mbox_layer = 2;
    if Path::new("index.txg").exists() {
        if let Some(id) =
            mgr.add_graphic(Graphic::from_file("index.txg").unwrap(), mbox_layer, (1, 0))
        {
            mgr.move_graphic(id, 2, (-1, 0));
            mbox_id = id;
            mbox_layer = 4;
        }
    } else {
        eprintln!("\x1b[97;41;5mERR\x1b[m Unable to load index.txg. Run this example from within top examples directory!");
        eprintln!("\x1b[97;41;5mERR\x1b[m Or copy *.txf and index.txg from there to current dir.");
        exit(1);
    }

    loop {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::AltUnicode(uni) => match (uni[2], uni[4]) {
                    (53, 53) => {
                        //CtrlPgUp
                        mgr.move_graphic(1, 4, (0, 0));
                    }
                    (54, 53) => {
                        //CtrlPgDn
                        mgr.move_graphic(1, 1, (0, 0));
                    }
                    (53, 51) => {
                        //AltPgUp
                        mgr.move_graphic(2, 5, (0, 0));
                    }
                    (54, 51) => {
                        //AltPgDn
                        mgr.move_graphic(2, 2, (0, 0));
                    }
                    _ => {}
                },
                Key::PgUp | Key::U => {
                    mgr.move_graphic(0, 3, (0, 0));
                }
                Key::PgDn | Key::D => {
                    mgr.move_graphic(0, 0, (0, 0));
                }
                Key::CtrlU => {
                    pb_layer = 4;
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::CtrlD => {
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::AltU => {
                    mbox_layer = 5;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltD => {
                    mbox_layer = 2;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltUp | Key::AltK => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, -1));
                }
                Key::CtrlUp | Key::CtrlK => {
                    mgr.move_graphic(pbid, pb_layer, (0, -1));
                }
                Key::Up | Key::K => {
                    mgr.stop_animation(gid);
                    mgr.move_graphic(gid, 1, (0, -1));
                    mgr.set_graphic(gid, 1, true);
                }
                Key::AltDown | Key::AltJ => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 1));
                }
                Key::CtrlDown => {
                    mgr.move_graphic(pbid, pb_layer, (0, 1));
                }
                Key::Down | Key::J => {
                    mgr.pause_animation_on_frame(pbid, 100);
                    mgr.move_graphic(gid, 1, (0, 1));
                    mgr.set_graphic(gid, pid, true);
                }
                Key::AltLeft | Key::AltH => {
                    mgr.move_graphic(mbox_id, mbox_layer, (-1, 0));
                }
                Key::CtrlLeft | Key::Backspace => {
                    mgr.move_graphic(pbid, pb_layer, (-1, 0));
                }
                Key::Left | Key::H => {
                    mgr.move_graphic(gid, 1, (-1, 0));
                    mgr.start_animation(gid, 0);
                    mgr.start_animation(pbid, 0);
                }
                Key::AltRight | Key::AltL => {
                    mgr.move_graphic(mbox_id, mbox_layer, (1, 0));
                }
                Key::CtrlRight | Key::CtrlL => {
                    mgr.move_graphic(pbid, pb_layer, (1, 0));
                }
                Key::Right | Key::L => {
                    mgr.move_graphic(gid, 1, (1, 0));
                }
                Key::Tab => {
                    mbox_layer += 1;
                    if !mbox_created {
                        if let  Some(mbid) = mgr.add_graphic(
                            build_mbox(60, 20, "La ku ka ra cza ga wi ga ba ga da da da ja nie".to_string(),
                            "lastBuildDate: Tue, 12 Apr 2022 07:52:44 GMT
* generator: Oddmuse
* copyright: This work is licensed to you under version 2 of the GNU General Public License. Alternatively, you may choose to receive this work under
 any other license that grants the right to use, copy, modify, and distribute the work, as long as that license imposes the restriction that derivative
 works have to grant the same rights and impose the same restriction. For example, you may choose to receive this work under the GNU Free
 Documentation License, the CreativeCommons ShareAlike License, the XEmacs manual license, or similar licenses.
* license: https://creativecommons.org/licenses/sa/1.0/
* license: https://www.gnu.org/copyleft/fdl.html
* license: https://www.gnu.org/copyleft/gpl.html".to_string()                        ),
                        mbox_layer,
                        (0, 0),
                    ){
                        mgr.set_graphic(mbid, 0, true);
                            mbox_created = true;
                            mbox_id = mbid;
                        }
                    }
                }
                Key::CtrlA => {
                    mgr.start_animation(gid, 0);
                }
                Key::CtrlB => {
                    mgr.stop_animation(gid);
                }
                Key::Insert => {
                    mgr.set_graphic(gid, 2, false);
                }
                Key::Delete => {}
                Key::Home => {
                    mgr.set_glyph(gid, Glyph::default(), 1, 1);
                    mgr.move_graphic(gid, 1, (0, 0));
                    mgr.empty_frame(gid);
                }
                Key::Escape | Key::Q | Key::CtrlQ => {
                    break;
                }
                Key::Enter => {
                    if !mbox_created {
                        mbox_layer += 1;
                        if let Some(tid) = mgr.add_graphic(
                            build_mbox(
                                40,
                                1,
                                "Please enter title and hit Enter".to_string(),
                                String::new(),
                            ),
                            mbox_layer,
                            (cols as isize / 2 - 20, rows as isize / 2),
                        ) {
                            mgr.set_graphic(tid, 0, true);
                            let line = mgr.read_line();
                            if let Some(mbid) = mgr.add_graphic(
                                build_mbox(
                                    60,
                                    20,
                                    line,
                                    "Hit Enter to type content in.".to_string(),
                                ),
                                mbox_layer,
                                (0, 0),
                            ) {
                                mgr.delete_graphic(tid);
                                mbox_id = mbid;
                                mgr.set_graphic(mbid, 0, true);
                                mbox_created = true;
                            }
                        }
                    } else {
                        let mut x = 1;
                        let mut y = 1;
                        mbox_created = false;
                        let mut rev = Glyph::default();
                        rev.set_reverse(true);
                        for i in 1..31 {
                            mgr.set_glyph(mbox_id, rev, i, 1);
                        }
                        loop {
                            if let Some(c) = mgr.read_char() {
                                if c == '\t' {
                                    break;
                                }
                                if c as u8 == 8 || c as u8 == 127 {
                                    x -= 1;
                                    if x == 0 {
                                        if y > 1 {
                                            y -= 1;
                                            x = 58;
                                        } else {
                                            x = 1;
                                        }
                                    }
                                    mgr.set_glyph(mbox_id, Glyph::default(), x, y);
                                    continue;
                                }
                                if c == '\n' {
                                    break;
                                }

                                mgr.set_glyph(mbox_id, Glyph::default_with_char(c), x, y);
                                x += 1;
                                if x > 58 {
                                    x = 1;
                                    y += 1;
                                }
                            }
                        }
                    }
                }
                _ => {
                    println!("You pressed: {:?}", key);
                }
            }
        }
    }
    mgr.terminate();
}
source

pub fn add_animation(&mut self, graphic_id: usize, anim: Animation)

Adds a new Animation for a Graphic. Make sure Graphic has all frames required by the Animation defined.

Examples found in repository?
examples/example_2.rs (lines 101-104)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let ordering = vec![
        (start_frame, Timestamp::new(0, 500)),
        (start_frame + 1, Timestamp::new(0, 500)),
    ];
    let running = false;
    let looping = true;
    let start_time = Timestamp::now();
    let animation = Animation::new(running, looping, ordering, start_time);
    let mut animations = HashMap::new();
    let anim_id = 0;
    animations.insert(anim_id, animation);
    let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
    let fast_ordering = vec![
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
    ];
    let mut fast_anim_id = anim_id;
    if let Some(id) = gr.add_animation(Animation::new(running, looping, fast_ordering, start_time))
    {
        fast_anim_id = id;
    };

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Press 0 to set current frame to 0\n Press 1 to set current frame to 1\n Press a|Shift+a|Ctrl+a start anim \n Press s or Shift+s stop animation\n\n Press q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 80, 17);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 8))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let var_ordering = vec![
        (start_frame, Timestamp::new(0, 400)),
        (start_frame + 1, Timestamp::new(0, 400)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 100)),
        (start_frame + 1, Timestamp::new(0, 100)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
    ];
    // let mut all_results_read = false;
    // while !all_results_read {
    //     let result = mgr.read_result();
    //     match result {
    //         Ok(AnimOk::AllResultsRead) => all_results_read = true,
    //         _ => continue,
    //     }
    // }
    mgr.add_animation(
        graphic_id,
        Animation::new(false, true, var_ordering, Timestamp::now()),
    );
    let mut var_anim_id = 0;

    if let Ok(AnimOk::AnimationAdded(anim_id)) = mgr.read_result() {
        var_anim_id = anim_id;
    }

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
                Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
                Key::A => mgr.start_animation(graphic_id, anim_id),
                Key::ShiftA => mgr.start_animation(graphic_id, fast_anim_id),
                Key::P => mgr.pause_animation(graphic_id),
                Key::CtrlP => mgr.pause_animation(graphic_id),
                Key::ShiftP => mgr.pause_animation_on_frame(graphic_id, start_frame),
                Key::CtrlA => mgr.start_animation(graphic_id, var_anim_id),
                Key::S | Key::ShiftS => mgr.stop_animation(graphic_id),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
source

pub fn start_animation(&self, graph_id: usize, anim_id: usize)

Start an animation for a graphic.

Examples found in repository?
examples/example_4.rs (line 52)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text =
        "Press 0 to select display 0\n Press 1 to select display 1\n Press q or Shift+q to quit\n"
            .to_string();
    let keep_existing = true;
    let first_display_id = 0;
    let mbox = message_box(Some(title.clone()), text.clone(), Glyph::default(), 32, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);
    let empty = Glyph::new(
        ' ',
        Color::green(),
        Color::black(),
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let full = Glyph::new(
        'X',
        Color::green(),
        Color::black(),
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let gid = mgr
        .add_graphic(progress_bar(screen_size.0, empty, full, None), 0, (1, 1))
        .unwrap();
    mgr.start_animation(gid, 0);
    let second_display_id = mgr.new_display(keep_existing);
    // let result = mgr.read_result();
    // if let Ok(AnimOk::DisplayStored(disp_id)) = result {
    //     first_display_id = disp_id;
    // }
    let mbox = message_box(Some(title), text, Glyph::default(), 32, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.restore_display(first_display_id, true),
                Key::One => mgr.restore_display(second_display_id, true),
                Key::Two => mgr.restore_display(2, true),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
More examples
Hide additional examples
examples/example_2.rs (line 117)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let ordering = vec![
        (start_frame, Timestamp::new(0, 500)),
        (start_frame + 1, Timestamp::new(0, 500)),
    ];
    let running = false;
    let looping = true;
    let start_time = Timestamp::now();
    let animation = Animation::new(running, looping, ordering, start_time);
    let mut animations = HashMap::new();
    let anim_id = 0;
    animations.insert(anim_id, animation);
    let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
    let fast_ordering = vec![
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
    ];
    let mut fast_anim_id = anim_id;
    if let Some(id) = gr.add_animation(Animation::new(running, looping, fast_ordering, start_time))
    {
        fast_anim_id = id;
    };

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Press 0 to set current frame to 0\n Press 1 to set current frame to 1\n Press a|Shift+a|Ctrl+a start anim \n Press s or Shift+s stop animation\n\n Press q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 80, 17);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 8))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let var_ordering = vec![
        (start_frame, Timestamp::new(0, 400)),
        (start_frame + 1, Timestamp::new(0, 400)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 100)),
        (start_frame + 1, Timestamp::new(0, 100)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
    ];
    // let mut all_results_read = false;
    // while !all_results_read {
    //     let result = mgr.read_result();
    //     match result {
    //         Ok(AnimOk::AllResultsRead) => all_results_read = true,
    //         _ => continue,
    //     }
    // }
    mgr.add_animation(
        graphic_id,
        Animation::new(false, true, var_ordering, Timestamp::now()),
    );
    let mut var_anim_id = 0;

    if let Ok(AnimOk::AnimationAdded(anim_id)) = mgr.read_result() {
        var_anim_id = anim_id;
    }

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
                Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
                Key::A => mgr.start_animation(graphic_id, anim_id),
                Key::ShiftA => mgr.start_animation(graphic_id, fast_anim_id),
                Key::P => mgr.pause_animation(graphic_id),
                Key::CtrlP => mgr.pause_animation(graphic_id),
                Key::ShiftP => mgr.pause_animation_on_frame(graphic_id, start_frame),
                Key::CtrlA => mgr.start_animation(graphic_id, var_anim_id),
                Key::S | Key::ShiftS => mgr.stop_animation(graphic_id),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
examples/example_5.rs (line 80)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
fn main() {
    let args = parse_arguments();
    let cols = args.cols;
    let rows = args.rows;
    verify_cols_and_rows(cols, rows);
    let mut g = Glyph::default();
    g.set_background(Color::green());
    g.set_char(char::from_u32(9626).unwrap());
    g.set_bright(true);

    let mut mgr = Manager::new(true, cols, rows, Some(g), None, None);
    let (cols, rows) = mgr.screen_size();

    let title = "Navigation help".to_string();
    let text = "CtrlPgUp,CtrlPgDn, -------------------------------------
AltPgUp,AltPgDn, ---------------------------------------
PgUp,PgDn, ---------------------------------------------
U,D, ---------------------------------------------------
CtrlU,CtrlD -------------------------------------------- 
AltU,AltD ----------------------------------------------
AltUp | AltK -------------------------------------------
CtrlUp | CtrlK -----------------------------------------
Up | K -------------------------------------------------
AltDown | AltJ -----------------------------------------
CtrlDown -----------------------------------------------
Down | J -----------------------------------------------
AltLeft | AltH -----------------------------------------
CtrlLeft | Backspace -----------------------------------
Left | H -----------------------------------------------
AltRight | AltL ----------------------------------------
CtrlRight | CtrlL --------------------------------------
Right | L - all above move graphics around the screen --
----------- and up/down layers. ------------------------
Tab - show a message box -------------------------------
Enter - type some text and hit Enter again -------------
        "
    .to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 60, 23);
    let mbid = mgr.add_graphic(mbox, 4, (1, 10)).unwrap();
    mgr.set_graphic(mbid, 0, true);
    let (gr, pid) = build_graphic(130, 10);
    let gr_layer = 1;
    let gid;
    let result = mgr.add_graphic(gr, gr_layer, (3, 15));
    if let Some(id) = result {
        gid = id;
    } else {
        eprintln!("Did not receive first graphic id");
        exit(2);
    }
    mgr.set_graphic(gid, pid, true);

    let pbid;
    let mut pb_layer = 3;
    let result = mgr.add_graphic(
        build_progress_bar(cols - 4),
        pb_layer,
        (2, (rows - 2) as isize),
    );
    if let Some(id) = result {
        pbid = id;
    } else {
        eprintln!("Did not receive progress bar graphic id");
        exit(2);
    }
    mgr.set_graphic(pbid, 0, true);
    mgr.start_animation(pbid, 0);
    let mut mbox_created = false;
    let mut mbox_id = 100;
    let mut mbox_layer = 2;
    if Path::new("index.txg").exists() {
        if let Some(id) =
            mgr.add_graphic(Graphic::from_file("index.txg").unwrap(), mbox_layer, (1, 0))
        {
            mgr.move_graphic(id, 2, (-1, 0));
            mbox_id = id;
            mbox_layer = 4;
        }
    } else {
        eprintln!("\x1b[97;41;5mERR\x1b[m Unable to load index.txg. Run this example from within top examples directory!");
        eprintln!("\x1b[97;41;5mERR\x1b[m Or copy *.txf and index.txg from there to current dir.");
        exit(1);
    }

    loop {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::AltUnicode(uni) => match (uni[2], uni[4]) {
                    (53, 53) => {
                        //CtrlPgUp
                        mgr.move_graphic(1, 4, (0, 0));
                    }
                    (54, 53) => {
                        //CtrlPgDn
                        mgr.move_graphic(1, 1, (0, 0));
                    }
                    (53, 51) => {
                        //AltPgUp
                        mgr.move_graphic(2, 5, (0, 0));
                    }
                    (54, 51) => {
                        //AltPgDn
                        mgr.move_graphic(2, 2, (0, 0));
                    }
                    _ => {}
                },
                Key::PgUp | Key::U => {
                    mgr.move_graphic(0, 3, (0, 0));
                }
                Key::PgDn | Key::D => {
                    mgr.move_graphic(0, 0, (0, 0));
                }
                Key::CtrlU => {
                    pb_layer = 4;
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::CtrlD => {
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::AltU => {
                    mbox_layer = 5;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltD => {
                    mbox_layer = 2;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltUp | Key::AltK => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, -1));
                }
                Key::CtrlUp | Key::CtrlK => {
                    mgr.move_graphic(pbid, pb_layer, (0, -1));
                }
                Key::Up | Key::K => {
                    mgr.stop_animation(gid);
                    mgr.move_graphic(gid, 1, (0, -1));
                    mgr.set_graphic(gid, 1, true);
                }
                Key::AltDown | Key::AltJ => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 1));
                }
                Key::CtrlDown => {
                    mgr.move_graphic(pbid, pb_layer, (0, 1));
                }
                Key::Down | Key::J => {
                    mgr.pause_animation_on_frame(pbid, 100);
                    mgr.move_graphic(gid, 1, (0, 1));
                    mgr.set_graphic(gid, pid, true);
                }
                Key::AltLeft | Key::AltH => {
                    mgr.move_graphic(mbox_id, mbox_layer, (-1, 0));
                }
                Key::CtrlLeft | Key::Backspace => {
                    mgr.move_graphic(pbid, pb_layer, (-1, 0));
                }
                Key::Left | Key::H => {
                    mgr.move_graphic(gid, 1, (-1, 0));
                    mgr.start_animation(gid, 0);
                    mgr.start_animation(pbid, 0);
                }
                Key::AltRight | Key::AltL => {
                    mgr.move_graphic(mbox_id, mbox_layer, (1, 0));
                }
                Key::CtrlRight | Key::CtrlL => {
                    mgr.move_graphic(pbid, pb_layer, (1, 0));
                }
                Key::Right | Key::L => {
                    mgr.move_graphic(gid, 1, (1, 0));
                }
                Key::Tab => {
                    mbox_layer += 1;
                    if !mbox_created {
                        if let  Some(mbid) = mgr.add_graphic(
                            build_mbox(60, 20, "La ku ka ra cza ga wi ga ba ga da da da ja nie".to_string(),
                            "lastBuildDate: Tue, 12 Apr 2022 07:52:44 GMT
* generator: Oddmuse
* copyright: This work is licensed to you under version 2 of the GNU General Public License. Alternatively, you may choose to receive this work under
 any other license that grants the right to use, copy, modify, and distribute the work, as long as that license imposes the restriction that derivative
 works have to grant the same rights and impose the same restriction. For example, you may choose to receive this work under the GNU Free
 Documentation License, the CreativeCommons ShareAlike License, the XEmacs manual license, or similar licenses.
* license: https://creativecommons.org/licenses/sa/1.0/
* license: https://www.gnu.org/copyleft/fdl.html
* license: https://www.gnu.org/copyleft/gpl.html".to_string()                        ),
                        mbox_layer,
                        (0, 0),
                    ){
                        mgr.set_graphic(mbid, 0, true);
                            mbox_created = true;
                            mbox_id = mbid;
                        }
                    }
                }
                Key::CtrlA => {
                    mgr.start_animation(gid, 0);
                }
                Key::CtrlB => {
                    mgr.stop_animation(gid);
                }
                Key::Insert => {
                    mgr.set_graphic(gid, 2, false);
                }
                Key::Delete => {}
                Key::Home => {
                    mgr.set_glyph(gid, Glyph::default(), 1, 1);
                    mgr.move_graphic(gid, 1, (0, 0));
                    mgr.empty_frame(gid);
                }
                Key::Escape | Key::Q | Key::CtrlQ => {
                    break;
                }
                Key::Enter => {
                    if !mbox_created {
                        mbox_layer += 1;
                        if let Some(tid) = mgr.add_graphic(
                            build_mbox(
                                40,
                                1,
                                "Please enter title and hit Enter".to_string(),
                                String::new(),
                            ),
                            mbox_layer,
                            (cols as isize / 2 - 20, rows as isize / 2),
                        ) {
                            mgr.set_graphic(tid, 0, true);
                            let line = mgr.read_line();
                            if let Some(mbid) = mgr.add_graphic(
                                build_mbox(
                                    60,
                                    20,
                                    line,
                                    "Hit Enter to type content in.".to_string(),
                                ),
                                mbox_layer,
                                (0, 0),
                            ) {
                                mgr.delete_graphic(tid);
                                mbox_id = mbid;
                                mgr.set_graphic(mbid, 0, true);
                                mbox_created = true;
                            }
                        }
                    } else {
                        let mut x = 1;
                        let mut y = 1;
                        mbox_created = false;
                        let mut rev = Glyph::default();
                        rev.set_reverse(true);
                        for i in 1..31 {
                            mgr.set_glyph(mbox_id, rev, i, 1);
                        }
                        loop {
                            if let Some(c) = mgr.read_char() {
                                if c == '\t' {
                                    break;
                                }
                                if c as u8 == 8 || c as u8 == 127 {
                                    x -= 1;
                                    if x == 0 {
                                        if y > 1 {
                                            y -= 1;
                                            x = 58;
                                        } else {
                                            x = 1;
                                        }
                                    }
                                    mgr.set_glyph(mbox_id, Glyph::default(), x, y);
                                    continue;
                                }
                                if c == '\n' {
                                    break;
                                }

                                mgr.set_glyph(mbox_id, Glyph::default_with_char(c), x, y);
                                x += 1;
                                if x > 58 {
                                    x = 1;
                                    y += 1;
                                }
                            }
                        }
                    }
                }
                _ => {
                    println!("You pressed: {:?}", key);
                }
            }
        }
    }
    mgr.terminate();
}
source

pub fn enqueue_animation( &self, graph_id: usize, anim_id: usize, when: Timestamp, )

Start another animation for given graphic after current one ends.

source

pub fn pause_animation(&self, graphic_id: usize)

Pause a running animation from given graphic.

Examples found in repository?
examples/example_2.rs (line 119)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let ordering = vec![
        (start_frame, Timestamp::new(0, 500)),
        (start_frame + 1, Timestamp::new(0, 500)),
    ];
    let running = false;
    let looping = true;
    let start_time = Timestamp::now();
    let animation = Animation::new(running, looping, ordering, start_time);
    let mut animations = HashMap::new();
    let anim_id = 0;
    animations.insert(anim_id, animation);
    let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
    let fast_ordering = vec![
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
    ];
    let mut fast_anim_id = anim_id;
    if let Some(id) = gr.add_animation(Animation::new(running, looping, fast_ordering, start_time))
    {
        fast_anim_id = id;
    };

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Press 0 to set current frame to 0\n Press 1 to set current frame to 1\n Press a|Shift+a|Ctrl+a start anim \n Press s or Shift+s stop animation\n\n Press q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 80, 17);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 8))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let var_ordering = vec![
        (start_frame, Timestamp::new(0, 400)),
        (start_frame + 1, Timestamp::new(0, 400)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 100)),
        (start_frame + 1, Timestamp::new(0, 100)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
    ];
    // let mut all_results_read = false;
    // while !all_results_read {
    //     let result = mgr.read_result();
    //     match result {
    //         Ok(AnimOk::AllResultsRead) => all_results_read = true,
    //         _ => continue,
    //     }
    // }
    mgr.add_animation(
        graphic_id,
        Animation::new(false, true, var_ordering, Timestamp::now()),
    );
    let mut var_anim_id = 0;

    if let Ok(AnimOk::AnimationAdded(anim_id)) = mgr.read_result() {
        var_anim_id = anim_id;
    }

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
                Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
                Key::A => mgr.start_animation(graphic_id, anim_id),
                Key::ShiftA => mgr.start_animation(graphic_id, fast_anim_id),
                Key::P => mgr.pause_animation(graphic_id),
                Key::CtrlP => mgr.pause_animation(graphic_id),
                Key::ShiftP => mgr.pause_animation_on_frame(graphic_id, start_frame),
                Key::CtrlA => mgr.start_animation(graphic_id, var_anim_id),
                Key::S | Key::ShiftS => mgr.stop_animation(graphic_id),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
source

pub fn pause_animation_on_frame(&self, graphic_id: usize, frame_id: usize)

Pause a running animation from given graphic when given frame is being displayed.

Examples found in repository?
examples/example_2.rs (line 121)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let ordering = vec![
        (start_frame, Timestamp::new(0, 500)),
        (start_frame + 1, Timestamp::new(0, 500)),
    ];
    let running = false;
    let looping = true;
    let start_time = Timestamp::now();
    let animation = Animation::new(running, looping, ordering, start_time);
    let mut animations = HashMap::new();
    let anim_id = 0;
    animations.insert(anim_id, animation);
    let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
    let fast_ordering = vec![
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
    ];
    let mut fast_anim_id = anim_id;
    if let Some(id) = gr.add_animation(Animation::new(running, looping, fast_ordering, start_time))
    {
        fast_anim_id = id;
    };

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Press 0 to set current frame to 0\n Press 1 to set current frame to 1\n Press a|Shift+a|Ctrl+a start anim \n Press s or Shift+s stop animation\n\n Press q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 80, 17);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 8))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let var_ordering = vec![
        (start_frame, Timestamp::new(0, 400)),
        (start_frame + 1, Timestamp::new(0, 400)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 100)),
        (start_frame + 1, Timestamp::new(0, 100)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
    ];
    // let mut all_results_read = false;
    // while !all_results_read {
    //     let result = mgr.read_result();
    //     match result {
    //         Ok(AnimOk::AllResultsRead) => all_results_read = true,
    //         _ => continue,
    //     }
    // }
    mgr.add_animation(
        graphic_id,
        Animation::new(false, true, var_ordering, Timestamp::now()),
    );
    let mut var_anim_id = 0;

    if let Ok(AnimOk::AnimationAdded(anim_id)) = mgr.read_result() {
        var_anim_id = anim_id;
    }

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
                Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
                Key::A => mgr.start_animation(graphic_id, anim_id),
                Key::ShiftA => mgr.start_animation(graphic_id, fast_anim_id),
                Key::P => mgr.pause_animation(graphic_id),
                Key::CtrlP => mgr.pause_animation(graphic_id),
                Key::ShiftP => mgr.pause_animation_on_frame(graphic_id, start_frame),
                Key::CtrlA => mgr.start_animation(graphic_id, var_anim_id),
                Key::S | Key::ShiftS => mgr.stop_animation(graphic_id),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
More examples
Hide additional examples
examples/example_5.rs (line 159)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
fn main() {
    let args = parse_arguments();
    let cols = args.cols;
    let rows = args.rows;
    verify_cols_and_rows(cols, rows);
    let mut g = Glyph::default();
    g.set_background(Color::green());
    g.set_char(char::from_u32(9626).unwrap());
    g.set_bright(true);

    let mut mgr = Manager::new(true, cols, rows, Some(g), None, None);
    let (cols, rows) = mgr.screen_size();

    let title = "Navigation help".to_string();
    let text = "CtrlPgUp,CtrlPgDn, -------------------------------------
AltPgUp,AltPgDn, ---------------------------------------
PgUp,PgDn, ---------------------------------------------
U,D, ---------------------------------------------------
CtrlU,CtrlD -------------------------------------------- 
AltU,AltD ----------------------------------------------
AltUp | AltK -------------------------------------------
CtrlUp | CtrlK -----------------------------------------
Up | K -------------------------------------------------
AltDown | AltJ -----------------------------------------
CtrlDown -----------------------------------------------
Down | J -----------------------------------------------
AltLeft | AltH -----------------------------------------
CtrlLeft | Backspace -----------------------------------
Left | H -----------------------------------------------
AltRight | AltL ----------------------------------------
CtrlRight | CtrlL --------------------------------------
Right | L - all above move graphics around the screen --
----------- and up/down layers. ------------------------
Tab - show a message box -------------------------------
Enter - type some text and hit Enter again -------------
        "
    .to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 60, 23);
    let mbid = mgr.add_graphic(mbox, 4, (1, 10)).unwrap();
    mgr.set_graphic(mbid, 0, true);
    let (gr, pid) = build_graphic(130, 10);
    let gr_layer = 1;
    let gid;
    let result = mgr.add_graphic(gr, gr_layer, (3, 15));
    if let Some(id) = result {
        gid = id;
    } else {
        eprintln!("Did not receive first graphic id");
        exit(2);
    }
    mgr.set_graphic(gid, pid, true);

    let pbid;
    let mut pb_layer = 3;
    let result = mgr.add_graphic(
        build_progress_bar(cols - 4),
        pb_layer,
        (2, (rows - 2) as isize),
    );
    if let Some(id) = result {
        pbid = id;
    } else {
        eprintln!("Did not receive progress bar graphic id");
        exit(2);
    }
    mgr.set_graphic(pbid, 0, true);
    mgr.start_animation(pbid, 0);
    let mut mbox_created = false;
    let mut mbox_id = 100;
    let mut mbox_layer = 2;
    if Path::new("index.txg").exists() {
        if let Some(id) =
            mgr.add_graphic(Graphic::from_file("index.txg").unwrap(), mbox_layer, (1, 0))
        {
            mgr.move_graphic(id, 2, (-1, 0));
            mbox_id = id;
            mbox_layer = 4;
        }
    } else {
        eprintln!("\x1b[97;41;5mERR\x1b[m Unable to load index.txg. Run this example from within top examples directory!");
        eprintln!("\x1b[97;41;5mERR\x1b[m Or copy *.txf and index.txg from there to current dir.");
        exit(1);
    }

    loop {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::AltUnicode(uni) => match (uni[2], uni[4]) {
                    (53, 53) => {
                        //CtrlPgUp
                        mgr.move_graphic(1, 4, (0, 0));
                    }
                    (54, 53) => {
                        //CtrlPgDn
                        mgr.move_graphic(1, 1, (0, 0));
                    }
                    (53, 51) => {
                        //AltPgUp
                        mgr.move_graphic(2, 5, (0, 0));
                    }
                    (54, 51) => {
                        //AltPgDn
                        mgr.move_graphic(2, 2, (0, 0));
                    }
                    _ => {}
                },
                Key::PgUp | Key::U => {
                    mgr.move_graphic(0, 3, (0, 0));
                }
                Key::PgDn | Key::D => {
                    mgr.move_graphic(0, 0, (0, 0));
                }
                Key::CtrlU => {
                    pb_layer = 4;
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::CtrlD => {
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::AltU => {
                    mbox_layer = 5;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltD => {
                    mbox_layer = 2;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltUp | Key::AltK => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, -1));
                }
                Key::CtrlUp | Key::CtrlK => {
                    mgr.move_graphic(pbid, pb_layer, (0, -1));
                }
                Key::Up | Key::K => {
                    mgr.stop_animation(gid);
                    mgr.move_graphic(gid, 1, (0, -1));
                    mgr.set_graphic(gid, 1, true);
                }
                Key::AltDown | Key::AltJ => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 1));
                }
                Key::CtrlDown => {
                    mgr.move_graphic(pbid, pb_layer, (0, 1));
                }
                Key::Down | Key::J => {
                    mgr.pause_animation_on_frame(pbid, 100);
                    mgr.move_graphic(gid, 1, (0, 1));
                    mgr.set_graphic(gid, pid, true);
                }
                Key::AltLeft | Key::AltH => {
                    mgr.move_graphic(mbox_id, mbox_layer, (-1, 0));
                }
                Key::CtrlLeft | Key::Backspace => {
                    mgr.move_graphic(pbid, pb_layer, (-1, 0));
                }
                Key::Left | Key::H => {
                    mgr.move_graphic(gid, 1, (-1, 0));
                    mgr.start_animation(gid, 0);
                    mgr.start_animation(pbid, 0);
                }
                Key::AltRight | Key::AltL => {
                    mgr.move_graphic(mbox_id, mbox_layer, (1, 0));
                }
                Key::CtrlRight | Key::CtrlL => {
                    mgr.move_graphic(pbid, pb_layer, (1, 0));
                }
                Key::Right | Key::L => {
                    mgr.move_graphic(gid, 1, (1, 0));
                }
                Key::Tab => {
                    mbox_layer += 1;
                    if !mbox_created {
                        if let  Some(mbid) = mgr.add_graphic(
                            build_mbox(60, 20, "La ku ka ra cza ga wi ga ba ga da da da ja nie".to_string(),
                            "lastBuildDate: Tue, 12 Apr 2022 07:52:44 GMT
* generator: Oddmuse
* copyright: This work is licensed to you under version 2 of the GNU General Public License. Alternatively, you may choose to receive this work under
 any other license that grants the right to use, copy, modify, and distribute the work, as long as that license imposes the restriction that derivative
 works have to grant the same rights and impose the same restriction. For example, you may choose to receive this work under the GNU Free
 Documentation License, the CreativeCommons ShareAlike License, the XEmacs manual license, or similar licenses.
* license: https://creativecommons.org/licenses/sa/1.0/
* license: https://www.gnu.org/copyleft/fdl.html
* license: https://www.gnu.org/copyleft/gpl.html".to_string()                        ),
                        mbox_layer,
                        (0, 0),
                    ){
                        mgr.set_graphic(mbid, 0, true);
                            mbox_created = true;
                            mbox_id = mbid;
                        }
                    }
                }
                Key::CtrlA => {
                    mgr.start_animation(gid, 0);
                }
                Key::CtrlB => {
                    mgr.stop_animation(gid);
                }
                Key::Insert => {
                    mgr.set_graphic(gid, 2, false);
                }
                Key::Delete => {}
                Key::Home => {
                    mgr.set_glyph(gid, Glyph::default(), 1, 1);
                    mgr.move_graphic(gid, 1, (0, 0));
                    mgr.empty_frame(gid);
                }
                Key::Escape | Key::Q | Key::CtrlQ => {
                    break;
                }
                Key::Enter => {
                    if !mbox_created {
                        mbox_layer += 1;
                        if let Some(tid) = mgr.add_graphic(
                            build_mbox(
                                40,
                                1,
                                "Please enter title and hit Enter".to_string(),
                                String::new(),
                            ),
                            mbox_layer,
                            (cols as isize / 2 - 20, rows as isize / 2),
                        ) {
                            mgr.set_graphic(tid, 0, true);
                            let line = mgr.read_line();
                            if let Some(mbid) = mgr.add_graphic(
                                build_mbox(
                                    60,
                                    20,
                                    line,
                                    "Hit Enter to type content in.".to_string(),
                                ),
                                mbox_layer,
                                (0, 0),
                            ) {
                                mgr.delete_graphic(tid);
                                mbox_id = mbid;
                                mgr.set_graphic(mbid, 0, true);
                                mbox_created = true;
                            }
                        }
                    } else {
                        let mut x = 1;
                        let mut y = 1;
                        mbox_created = false;
                        let mut rev = Glyph::default();
                        rev.set_reverse(true);
                        for i in 1..31 {
                            mgr.set_glyph(mbox_id, rev, i, 1);
                        }
                        loop {
                            if let Some(c) = mgr.read_char() {
                                if c == '\t' {
                                    break;
                                }
                                if c as u8 == 8 || c as u8 == 127 {
                                    x -= 1;
                                    if x == 0 {
                                        if y > 1 {
                                            y -= 1;
                                            x = 58;
                                        } else {
                                            x = 1;
                                        }
                                    }
                                    mgr.set_glyph(mbox_id, Glyph::default(), x, y);
                                    continue;
                                }
                                if c == '\n' {
                                    break;
                                }

                                mgr.set_glyph(mbox_id, Glyph::default_with_char(c), x, y);
                                x += 1;
                                if x > 58 {
                                    x = 1;
                                    y += 1;
                                }
                            }
                        }
                    }
                }
                _ => {
                    println!("You pressed: {:?}", key);
                }
            }
        }
    }
    mgr.terminate();
}
source

pub fn stop_animation(&self, graph_id: usize)

Stop animation for given graphic

Examples found in repository?
examples/example_2.rs (line 123)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let ordering = vec![
        (start_frame, Timestamp::new(0, 500)),
        (start_frame + 1, Timestamp::new(0, 500)),
    ];
    let running = false;
    let looping = true;
    let start_time = Timestamp::now();
    let animation = Animation::new(running, looping, ordering, start_time);
    let mut animations = HashMap::new();
    let anim_id = 0;
    animations.insert(anim_id, animation);
    let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
    let fast_ordering = vec![
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
    ];
    let mut fast_anim_id = anim_id;
    if let Some(id) = gr.add_animation(Animation::new(running, looping, fast_ordering, start_time))
    {
        fast_anim_id = id;
    };

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Press 0 to set current frame to 0\n Press 1 to set current frame to 1\n Press a|Shift+a|Ctrl+a start anim \n Press s or Shift+s stop animation\n\n Press q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 80, 17);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 8))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let var_ordering = vec![
        (start_frame, Timestamp::new(0, 400)),
        (start_frame + 1, Timestamp::new(0, 400)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 100)),
        (start_frame + 1, Timestamp::new(0, 100)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
    ];
    // let mut all_results_read = false;
    // while !all_results_read {
    //     let result = mgr.read_result();
    //     match result {
    //         Ok(AnimOk::AllResultsRead) => all_results_read = true,
    //         _ => continue,
    //     }
    // }
    mgr.add_animation(
        graphic_id,
        Animation::new(false, true, var_ordering, Timestamp::now()),
    );
    let mut var_anim_id = 0;

    if let Ok(AnimOk::AnimationAdded(anim_id)) = mgr.read_result() {
        var_anim_id = anim_id;
    }

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
                Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
                Key::A => mgr.start_animation(graphic_id, anim_id),
                Key::ShiftA => mgr.start_animation(graphic_id, fast_anim_id),
                Key::P => mgr.pause_animation(graphic_id),
                Key::CtrlP => mgr.pause_animation(graphic_id),
                Key::ShiftP => mgr.pause_animation_on_frame(graphic_id, start_frame),
                Key::CtrlA => mgr.start_animation(graphic_id, var_anim_id),
                Key::S | Key::ShiftS => mgr.stop_animation(graphic_id),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
More examples
Hide additional examples
examples/example_5.rs (line 148)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
fn main() {
    let args = parse_arguments();
    let cols = args.cols;
    let rows = args.rows;
    verify_cols_and_rows(cols, rows);
    let mut g = Glyph::default();
    g.set_background(Color::green());
    g.set_char(char::from_u32(9626).unwrap());
    g.set_bright(true);

    let mut mgr = Manager::new(true, cols, rows, Some(g), None, None);
    let (cols, rows) = mgr.screen_size();

    let title = "Navigation help".to_string();
    let text = "CtrlPgUp,CtrlPgDn, -------------------------------------
AltPgUp,AltPgDn, ---------------------------------------
PgUp,PgDn, ---------------------------------------------
U,D, ---------------------------------------------------
CtrlU,CtrlD -------------------------------------------- 
AltU,AltD ----------------------------------------------
AltUp | AltK -------------------------------------------
CtrlUp | CtrlK -----------------------------------------
Up | K -------------------------------------------------
AltDown | AltJ -----------------------------------------
CtrlDown -----------------------------------------------
Down | J -----------------------------------------------
AltLeft | AltH -----------------------------------------
CtrlLeft | Backspace -----------------------------------
Left | H -----------------------------------------------
AltRight | AltL ----------------------------------------
CtrlRight | CtrlL --------------------------------------
Right | L - all above move graphics around the screen --
----------- and up/down layers. ------------------------
Tab - show a message box -------------------------------
Enter - type some text and hit Enter again -------------
        "
    .to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 60, 23);
    let mbid = mgr.add_graphic(mbox, 4, (1, 10)).unwrap();
    mgr.set_graphic(mbid, 0, true);
    let (gr, pid) = build_graphic(130, 10);
    let gr_layer = 1;
    let gid;
    let result = mgr.add_graphic(gr, gr_layer, (3, 15));
    if let Some(id) = result {
        gid = id;
    } else {
        eprintln!("Did not receive first graphic id");
        exit(2);
    }
    mgr.set_graphic(gid, pid, true);

    let pbid;
    let mut pb_layer = 3;
    let result = mgr.add_graphic(
        build_progress_bar(cols - 4),
        pb_layer,
        (2, (rows - 2) as isize),
    );
    if let Some(id) = result {
        pbid = id;
    } else {
        eprintln!("Did not receive progress bar graphic id");
        exit(2);
    }
    mgr.set_graphic(pbid, 0, true);
    mgr.start_animation(pbid, 0);
    let mut mbox_created = false;
    let mut mbox_id = 100;
    let mut mbox_layer = 2;
    if Path::new("index.txg").exists() {
        if let Some(id) =
            mgr.add_graphic(Graphic::from_file("index.txg").unwrap(), mbox_layer, (1, 0))
        {
            mgr.move_graphic(id, 2, (-1, 0));
            mbox_id = id;
            mbox_layer = 4;
        }
    } else {
        eprintln!("\x1b[97;41;5mERR\x1b[m Unable to load index.txg. Run this example from within top examples directory!");
        eprintln!("\x1b[97;41;5mERR\x1b[m Or copy *.txf and index.txg from there to current dir.");
        exit(1);
    }

    loop {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::AltUnicode(uni) => match (uni[2], uni[4]) {
                    (53, 53) => {
                        //CtrlPgUp
                        mgr.move_graphic(1, 4, (0, 0));
                    }
                    (54, 53) => {
                        //CtrlPgDn
                        mgr.move_graphic(1, 1, (0, 0));
                    }
                    (53, 51) => {
                        //AltPgUp
                        mgr.move_graphic(2, 5, (0, 0));
                    }
                    (54, 51) => {
                        //AltPgDn
                        mgr.move_graphic(2, 2, (0, 0));
                    }
                    _ => {}
                },
                Key::PgUp | Key::U => {
                    mgr.move_graphic(0, 3, (0, 0));
                }
                Key::PgDn | Key::D => {
                    mgr.move_graphic(0, 0, (0, 0));
                }
                Key::CtrlU => {
                    pb_layer = 4;
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::CtrlD => {
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::AltU => {
                    mbox_layer = 5;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltD => {
                    mbox_layer = 2;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltUp | Key::AltK => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, -1));
                }
                Key::CtrlUp | Key::CtrlK => {
                    mgr.move_graphic(pbid, pb_layer, (0, -1));
                }
                Key::Up | Key::K => {
                    mgr.stop_animation(gid);
                    mgr.move_graphic(gid, 1, (0, -1));
                    mgr.set_graphic(gid, 1, true);
                }
                Key::AltDown | Key::AltJ => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 1));
                }
                Key::CtrlDown => {
                    mgr.move_graphic(pbid, pb_layer, (0, 1));
                }
                Key::Down | Key::J => {
                    mgr.pause_animation_on_frame(pbid, 100);
                    mgr.move_graphic(gid, 1, (0, 1));
                    mgr.set_graphic(gid, pid, true);
                }
                Key::AltLeft | Key::AltH => {
                    mgr.move_graphic(mbox_id, mbox_layer, (-1, 0));
                }
                Key::CtrlLeft | Key::Backspace => {
                    mgr.move_graphic(pbid, pb_layer, (-1, 0));
                }
                Key::Left | Key::H => {
                    mgr.move_graphic(gid, 1, (-1, 0));
                    mgr.start_animation(gid, 0);
                    mgr.start_animation(pbid, 0);
                }
                Key::AltRight | Key::AltL => {
                    mgr.move_graphic(mbox_id, mbox_layer, (1, 0));
                }
                Key::CtrlRight | Key::CtrlL => {
                    mgr.move_graphic(pbid, pb_layer, (1, 0));
                }
                Key::Right | Key::L => {
                    mgr.move_graphic(gid, 1, (1, 0));
                }
                Key::Tab => {
                    mbox_layer += 1;
                    if !mbox_created {
                        if let  Some(mbid) = mgr.add_graphic(
                            build_mbox(60, 20, "La ku ka ra cza ga wi ga ba ga da da da ja nie".to_string(),
                            "lastBuildDate: Tue, 12 Apr 2022 07:52:44 GMT
* generator: Oddmuse
* copyright: This work is licensed to you under version 2 of the GNU General Public License. Alternatively, you may choose to receive this work under
 any other license that grants the right to use, copy, modify, and distribute the work, as long as that license imposes the restriction that derivative
 works have to grant the same rights and impose the same restriction. For example, you may choose to receive this work under the GNU Free
 Documentation License, the CreativeCommons ShareAlike License, the XEmacs manual license, or similar licenses.
* license: https://creativecommons.org/licenses/sa/1.0/
* license: https://www.gnu.org/copyleft/fdl.html
* license: https://www.gnu.org/copyleft/gpl.html".to_string()                        ),
                        mbox_layer,
                        (0, 0),
                    ){
                        mgr.set_graphic(mbid, 0, true);
                            mbox_created = true;
                            mbox_id = mbid;
                        }
                    }
                }
                Key::CtrlA => {
                    mgr.start_animation(gid, 0);
                }
                Key::CtrlB => {
                    mgr.stop_animation(gid);
                }
                Key::Insert => {
                    mgr.set_graphic(gid, 2, false);
                }
                Key::Delete => {}
                Key::Home => {
                    mgr.set_glyph(gid, Glyph::default(), 1, 1);
                    mgr.move_graphic(gid, 1, (0, 0));
                    mgr.empty_frame(gid);
                }
                Key::Escape | Key::Q | Key::CtrlQ => {
                    break;
                }
                Key::Enter => {
                    if !mbox_created {
                        mbox_layer += 1;
                        if let Some(tid) = mgr.add_graphic(
                            build_mbox(
                                40,
                                1,
                                "Please enter title and hit Enter".to_string(),
                                String::new(),
                            ),
                            mbox_layer,
                            (cols as isize / 2 - 20, rows as isize / 2),
                        ) {
                            mgr.set_graphic(tid, 0, true);
                            let line = mgr.read_line();
                            if let Some(mbid) = mgr.add_graphic(
                                build_mbox(
                                    60,
                                    20,
                                    line,
                                    "Hit Enter to type content in.".to_string(),
                                ),
                                mbox_layer,
                                (0, 0),
                            ) {
                                mgr.delete_graphic(tid);
                                mbox_id = mbid;
                                mgr.set_graphic(mbid, 0, true);
                                mbox_created = true;
                            }
                        }
                    } else {
                        let mut x = 1;
                        let mut y = 1;
                        mbox_created = false;
                        let mut rev = Glyph::default();
                        rev.set_reverse(true);
                        for i in 1..31 {
                            mgr.set_glyph(mbox_id, rev, i, 1);
                        }
                        loop {
                            if let Some(c) = mgr.read_char() {
                                if c == '\t' {
                                    break;
                                }
                                if c as u8 == 8 || c as u8 == 127 {
                                    x -= 1;
                                    if x == 0 {
                                        if y > 1 {
                                            y -= 1;
                                            x = 58;
                                        } else {
                                            x = 1;
                                        }
                                    }
                                    mgr.set_glyph(mbox_id, Glyph::default(), x, y);
                                    continue;
                                }
                                if c == '\n' {
                                    break;
                                }

                                mgr.set_glyph(mbox_id, Glyph::default_with_char(c), x, y);
                                x += 1;
                                if x > 58 {
                                    x = 1;
                                    y += 1;
                                }
                            }
                        }
                    }
                }
                _ => {
                    println!("You pressed: {:?}", key);
                }
            }
        }
    }
    mgr.terminate();
}
source

pub fn restart_animation( &self, graphic_id: usize, anim_id: usize, when: Timestamp, )

Restart animation for given graphic when the right time comes.

source

pub fn move_graphic( &self, graphic_id: usize, layer: usize, offset: (isize, isize), )

Move a graphic left or right on the screen, optionally changing which layer it is placed on.

Examples found in repository?
examples/example_3.rs (line 64)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let gr = Graphic::new(cols, rows, start_frame, library, None);

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Use arrows to move graphic around \nPress q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 37, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(graphic_id, start_frame, true);
    mgr.set_graphic(mbid, 0, true);

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Left => mgr.move_graphic(graphic_id, layer, (-1, 0)),
                Key::Right => mgr.move_graphic(graphic_id, layer, (1, 0)),
                Key::Up => mgr.move_graphic(graphic_id, layer, (0, -1)),
                Key::Down => mgr.move_graphic(graphic_id, layer, (0, 1)),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
More examples
Hide additional examples
examples/example_5.rs (line 88)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
fn main() {
    let args = parse_arguments();
    let cols = args.cols;
    let rows = args.rows;
    verify_cols_and_rows(cols, rows);
    let mut g = Glyph::default();
    g.set_background(Color::green());
    g.set_char(char::from_u32(9626).unwrap());
    g.set_bright(true);

    let mut mgr = Manager::new(true, cols, rows, Some(g), None, None);
    let (cols, rows) = mgr.screen_size();

    let title = "Navigation help".to_string();
    let text = "CtrlPgUp,CtrlPgDn, -------------------------------------
AltPgUp,AltPgDn, ---------------------------------------
PgUp,PgDn, ---------------------------------------------
U,D, ---------------------------------------------------
CtrlU,CtrlD -------------------------------------------- 
AltU,AltD ----------------------------------------------
AltUp | AltK -------------------------------------------
CtrlUp | CtrlK -----------------------------------------
Up | K -------------------------------------------------
AltDown | AltJ -----------------------------------------
CtrlDown -----------------------------------------------
Down | J -----------------------------------------------
AltLeft | AltH -----------------------------------------
CtrlLeft | Backspace -----------------------------------
Left | H -----------------------------------------------
AltRight | AltL ----------------------------------------
CtrlRight | CtrlL --------------------------------------
Right | L - all above move graphics around the screen --
----------- and up/down layers. ------------------------
Tab - show a message box -------------------------------
Enter - type some text and hit Enter again -------------
        "
    .to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 60, 23);
    let mbid = mgr.add_graphic(mbox, 4, (1, 10)).unwrap();
    mgr.set_graphic(mbid, 0, true);
    let (gr, pid) = build_graphic(130, 10);
    let gr_layer = 1;
    let gid;
    let result = mgr.add_graphic(gr, gr_layer, (3, 15));
    if let Some(id) = result {
        gid = id;
    } else {
        eprintln!("Did not receive first graphic id");
        exit(2);
    }
    mgr.set_graphic(gid, pid, true);

    let pbid;
    let mut pb_layer = 3;
    let result = mgr.add_graphic(
        build_progress_bar(cols - 4),
        pb_layer,
        (2, (rows - 2) as isize),
    );
    if let Some(id) = result {
        pbid = id;
    } else {
        eprintln!("Did not receive progress bar graphic id");
        exit(2);
    }
    mgr.set_graphic(pbid, 0, true);
    mgr.start_animation(pbid, 0);
    let mut mbox_created = false;
    let mut mbox_id = 100;
    let mut mbox_layer = 2;
    if Path::new("index.txg").exists() {
        if let Some(id) =
            mgr.add_graphic(Graphic::from_file("index.txg").unwrap(), mbox_layer, (1, 0))
        {
            mgr.move_graphic(id, 2, (-1, 0));
            mbox_id = id;
            mbox_layer = 4;
        }
    } else {
        eprintln!("\x1b[97;41;5mERR\x1b[m Unable to load index.txg. Run this example from within top examples directory!");
        eprintln!("\x1b[97;41;5mERR\x1b[m Or copy *.txf and index.txg from there to current dir.");
        exit(1);
    }

    loop {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::AltUnicode(uni) => match (uni[2], uni[4]) {
                    (53, 53) => {
                        //CtrlPgUp
                        mgr.move_graphic(1, 4, (0, 0));
                    }
                    (54, 53) => {
                        //CtrlPgDn
                        mgr.move_graphic(1, 1, (0, 0));
                    }
                    (53, 51) => {
                        //AltPgUp
                        mgr.move_graphic(2, 5, (0, 0));
                    }
                    (54, 51) => {
                        //AltPgDn
                        mgr.move_graphic(2, 2, (0, 0));
                    }
                    _ => {}
                },
                Key::PgUp | Key::U => {
                    mgr.move_graphic(0, 3, (0, 0));
                }
                Key::PgDn | Key::D => {
                    mgr.move_graphic(0, 0, (0, 0));
                }
                Key::CtrlU => {
                    pb_layer = 4;
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::CtrlD => {
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::AltU => {
                    mbox_layer = 5;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltD => {
                    mbox_layer = 2;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltUp | Key::AltK => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, -1));
                }
                Key::CtrlUp | Key::CtrlK => {
                    mgr.move_graphic(pbid, pb_layer, (0, -1));
                }
                Key::Up | Key::K => {
                    mgr.stop_animation(gid);
                    mgr.move_graphic(gid, 1, (0, -1));
                    mgr.set_graphic(gid, 1, true);
                }
                Key::AltDown | Key::AltJ => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 1));
                }
                Key::CtrlDown => {
                    mgr.move_graphic(pbid, pb_layer, (0, 1));
                }
                Key::Down | Key::J => {
                    mgr.pause_animation_on_frame(pbid, 100);
                    mgr.move_graphic(gid, 1, (0, 1));
                    mgr.set_graphic(gid, pid, true);
                }
                Key::AltLeft | Key::AltH => {
                    mgr.move_graphic(mbox_id, mbox_layer, (-1, 0));
                }
                Key::CtrlLeft | Key::Backspace => {
                    mgr.move_graphic(pbid, pb_layer, (-1, 0));
                }
                Key::Left | Key::H => {
                    mgr.move_graphic(gid, 1, (-1, 0));
                    mgr.start_animation(gid, 0);
                    mgr.start_animation(pbid, 0);
                }
                Key::AltRight | Key::AltL => {
                    mgr.move_graphic(mbox_id, mbox_layer, (1, 0));
                }
                Key::CtrlRight | Key::CtrlL => {
                    mgr.move_graphic(pbid, pb_layer, (1, 0));
                }
                Key::Right | Key::L => {
                    mgr.move_graphic(gid, 1, (1, 0));
                }
                Key::Tab => {
                    mbox_layer += 1;
                    if !mbox_created {
                        if let  Some(mbid) = mgr.add_graphic(
                            build_mbox(60, 20, "La ku ka ra cza ga wi ga ba ga da da da ja nie".to_string(),
                            "lastBuildDate: Tue, 12 Apr 2022 07:52:44 GMT
* generator: Oddmuse
* copyright: This work is licensed to you under version 2 of the GNU General Public License. Alternatively, you may choose to receive this work under
 any other license that grants the right to use, copy, modify, and distribute the work, as long as that license imposes the restriction that derivative
 works have to grant the same rights and impose the same restriction. For example, you may choose to receive this work under the GNU Free
 Documentation License, the CreativeCommons ShareAlike License, the XEmacs manual license, or similar licenses.
* license: https://creativecommons.org/licenses/sa/1.0/
* license: https://www.gnu.org/copyleft/fdl.html
* license: https://www.gnu.org/copyleft/gpl.html".to_string()                        ),
                        mbox_layer,
                        (0, 0),
                    ){
                        mgr.set_graphic(mbid, 0, true);
                            mbox_created = true;
                            mbox_id = mbid;
                        }
                    }
                }
                Key::CtrlA => {
                    mgr.start_animation(gid, 0);
                }
                Key::CtrlB => {
                    mgr.stop_animation(gid);
                }
                Key::Insert => {
                    mgr.set_graphic(gid, 2, false);
                }
                Key::Delete => {}
                Key::Home => {
                    mgr.set_glyph(gid, Glyph::default(), 1, 1);
                    mgr.move_graphic(gid, 1, (0, 0));
                    mgr.empty_frame(gid);
                }
                Key::Escape | Key::Q | Key::CtrlQ => {
                    break;
                }
                Key::Enter => {
                    if !mbox_created {
                        mbox_layer += 1;
                        if let Some(tid) = mgr.add_graphic(
                            build_mbox(
                                40,
                                1,
                                "Please enter title and hit Enter".to_string(),
                                String::new(),
                            ),
                            mbox_layer,
                            (cols as isize / 2 - 20, rows as isize / 2),
                        ) {
                            mgr.set_graphic(tid, 0, true);
                            let line = mgr.read_line();
                            if let Some(mbid) = mgr.add_graphic(
                                build_mbox(
                                    60,
                                    20,
                                    line,
                                    "Hit Enter to type content in.".to_string(),
                                ),
                                mbox_layer,
                                (0, 0),
                            ) {
                                mgr.delete_graphic(tid);
                                mbox_id = mbid;
                                mgr.set_graphic(mbid, 0, true);
                                mbox_created = true;
                            }
                        }
                    } else {
                        let mut x = 1;
                        let mut y = 1;
                        mbox_created = false;
                        let mut rev = Glyph::default();
                        rev.set_reverse(true);
                        for i in 1..31 {
                            mgr.set_glyph(mbox_id, rev, i, 1);
                        }
                        loop {
                            if let Some(c) = mgr.read_char() {
                                if c == '\t' {
                                    break;
                                }
                                if c as u8 == 8 || c as u8 == 127 {
                                    x -= 1;
                                    if x == 0 {
                                        if y > 1 {
                                            y -= 1;
                                            x = 58;
                                        } else {
                                            x = 1;
                                        }
                                    }
                                    mgr.set_glyph(mbox_id, Glyph::default(), x, y);
                                    continue;
                                }
                                if c == '\n' {
                                    break;
                                }

                                mgr.set_glyph(mbox_id, Glyph::default_with_char(c), x, y);
                                x += 1;
                                if x > 58 {
                                    x = 1;
                                    y += 1;
                                }
                            }
                        }
                    }
                }
                _ => {
                    println!("You pressed: {:?}", key);
                }
            }
        }
    }
    mgr.terminate();
}
source

pub fn clear_area( &self, layer: usize, start: (usize, usize), size: (usize, usize), )

Clear an area on selected layer

source

pub fn set_invisible(&self, gid: usize, invisible: bool)

Make a graphic invisible.

source

pub fn set_glyph(&self, gid: usize, glyph: Glyph, col: usize, row: usize)

Set glyph for given graphic in specified location to provided value.

Examples found in repository?
examples/example_5.rs (line 217)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
fn main() {
    let args = parse_arguments();
    let cols = args.cols;
    let rows = args.rows;
    verify_cols_and_rows(cols, rows);
    let mut g = Glyph::default();
    g.set_background(Color::green());
    g.set_char(char::from_u32(9626).unwrap());
    g.set_bright(true);

    let mut mgr = Manager::new(true, cols, rows, Some(g), None, None);
    let (cols, rows) = mgr.screen_size();

    let title = "Navigation help".to_string();
    let text = "CtrlPgUp,CtrlPgDn, -------------------------------------
AltPgUp,AltPgDn, ---------------------------------------
PgUp,PgDn, ---------------------------------------------
U,D, ---------------------------------------------------
CtrlU,CtrlD -------------------------------------------- 
AltU,AltD ----------------------------------------------
AltUp | AltK -------------------------------------------
CtrlUp | CtrlK -----------------------------------------
Up | K -------------------------------------------------
AltDown | AltJ -----------------------------------------
CtrlDown -----------------------------------------------
Down | J -----------------------------------------------
AltLeft | AltH -----------------------------------------
CtrlLeft | Backspace -----------------------------------
Left | H -----------------------------------------------
AltRight | AltL ----------------------------------------
CtrlRight | CtrlL --------------------------------------
Right | L - all above move graphics around the screen --
----------- and up/down layers. ------------------------
Tab - show a message box -------------------------------
Enter - type some text and hit Enter again -------------
        "
    .to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 60, 23);
    let mbid = mgr.add_graphic(mbox, 4, (1, 10)).unwrap();
    mgr.set_graphic(mbid, 0, true);
    let (gr, pid) = build_graphic(130, 10);
    let gr_layer = 1;
    let gid;
    let result = mgr.add_graphic(gr, gr_layer, (3, 15));
    if let Some(id) = result {
        gid = id;
    } else {
        eprintln!("Did not receive first graphic id");
        exit(2);
    }
    mgr.set_graphic(gid, pid, true);

    let pbid;
    let mut pb_layer = 3;
    let result = mgr.add_graphic(
        build_progress_bar(cols - 4),
        pb_layer,
        (2, (rows - 2) as isize),
    );
    if let Some(id) = result {
        pbid = id;
    } else {
        eprintln!("Did not receive progress bar graphic id");
        exit(2);
    }
    mgr.set_graphic(pbid, 0, true);
    mgr.start_animation(pbid, 0);
    let mut mbox_created = false;
    let mut mbox_id = 100;
    let mut mbox_layer = 2;
    if Path::new("index.txg").exists() {
        if let Some(id) =
            mgr.add_graphic(Graphic::from_file("index.txg").unwrap(), mbox_layer, (1, 0))
        {
            mgr.move_graphic(id, 2, (-1, 0));
            mbox_id = id;
            mbox_layer = 4;
        }
    } else {
        eprintln!("\x1b[97;41;5mERR\x1b[m Unable to load index.txg. Run this example from within top examples directory!");
        eprintln!("\x1b[97;41;5mERR\x1b[m Or copy *.txf and index.txg from there to current dir.");
        exit(1);
    }

    loop {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::AltUnicode(uni) => match (uni[2], uni[4]) {
                    (53, 53) => {
                        //CtrlPgUp
                        mgr.move_graphic(1, 4, (0, 0));
                    }
                    (54, 53) => {
                        //CtrlPgDn
                        mgr.move_graphic(1, 1, (0, 0));
                    }
                    (53, 51) => {
                        //AltPgUp
                        mgr.move_graphic(2, 5, (0, 0));
                    }
                    (54, 51) => {
                        //AltPgDn
                        mgr.move_graphic(2, 2, (0, 0));
                    }
                    _ => {}
                },
                Key::PgUp | Key::U => {
                    mgr.move_graphic(0, 3, (0, 0));
                }
                Key::PgDn | Key::D => {
                    mgr.move_graphic(0, 0, (0, 0));
                }
                Key::CtrlU => {
                    pb_layer = 4;
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::CtrlD => {
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::AltU => {
                    mbox_layer = 5;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltD => {
                    mbox_layer = 2;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltUp | Key::AltK => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, -1));
                }
                Key::CtrlUp | Key::CtrlK => {
                    mgr.move_graphic(pbid, pb_layer, (0, -1));
                }
                Key::Up | Key::K => {
                    mgr.stop_animation(gid);
                    mgr.move_graphic(gid, 1, (0, -1));
                    mgr.set_graphic(gid, 1, true);
                }
                Key::AltDown | Key::AltJ => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 1));
                }
                Key::CtrlDown => {
                    mgr.move_graphic(pbid, pb_layer, (0, 1));
                }
                Key::Down | Key::J => {
                    mgr.pause_animation_on_frame(pbid, 100);
                    mgr.move_graphic(gid, 1, (0, 1));
                    mgr.set_graphic(gid, pid, true);
                }
                Key::AltLeft | Key::AltH => {
                    mgr.move_graphic(mbox_id, mbox_layer, (-1, 0));
                }
                Key::CtrlLeft | Key::Backspace => {
                    mgr.move_graphic(pbid, pb_layer, (-1, 0));
                }
                Key::Left | Key::H => {
                    mgr.move_graphic(gid, 1, (-1, 0));
                    mgr.start_animation(gid, 0);
                    mgr.start_animation(pbid, 0);
                }
                Key::AltRight | Key::AltL => {
                    mgr.move_graphic(mbox_id, mbox_layer, (1, 0));
                }
                Key::CtrlRight | Key::CtrlL => {
                    mgr.move_graphic(pbid, pb_layer, (1, 0));
                }
                Key::Right | Key::L => {
                    mgr.move_graphic(gid, 1, (1, 0));
                }
                Key::Tab => {
                    mbox_layer += 1;
                    if !mbox_created {
                        if let  Some(mbid) = mgr.add_graphic(
                            build_mbox(60, 20, "La ku ka ra cza ga wi ga ba ga da da da ja nie".to_string(),
                            "lastBuildDate: Tue, 12 Apr 2022 07:52:44 GMT
* generator: Oddmuse
* copyright: This work is licensed to you under version 2 of the GNU General Public License. Alternatively, you may choose to receive this work under
 any other license that grants the right to use, copy, modify, and distribute the work, as long as that license imposes the restriction that derivative
 works have to grant the same rights and impose the same restriction. For example, you may choose to receive this work under the GNU Free
 Documentation License, the CreativeCommons ShareAlike License, the XEmacs manual license, or similar licenses.
* license: https://creativecommons.org/licenses/sa/1.0/
* license: https://www.gnu.org/copyleft/fdl.html
* license: https://www.gnu.org/copyleft/gpl.html".to_string()                        ),
                        mbox_layer,
                        (0, 0),
                    ){
                        mgr.set_graphic(mbid, 0, true);
                            mbox_created = true;
                            mbox_id = mbid;
                        }
                    }
                }
                Key::CtrlA => {
                    mgr.start_animation(gid, 0);
                }
                Key::CtrlB => {
                    mgr.stop_animation(gid);
                }
                Key::Insert => {
                    mgr.set_graphic(gid, 2, false);
                }
                Key::Delete => {}
                Key::Home => {
                    mgr.set_glyph(gid, Glyph::default(), 1, 1);
                    mgr.move_graphic(gid, 1, (0, 0));
                    mgr.empty_frame(gid);
                }
                Key::Escape | Key::Q | Key::CtrlQ => {
                    break;
                }
                Key::Enter => {
                    if !mbox_created {
                        mbox_layer += 1;
                        if let Some(tid) = mgr.add_graphic(
                            build_mbox(
                                40,
                                1,
                                "Please enter title and hit Enter".to_string(),
                                String::new(),
                            ),
                            mbox_layer,
                            (cols as isize / 2 - 20, rows as isize / 2),
                        ) {
                            mgr.set_graphic(tid, 0, true);
                            let line = mgr.read_line();
                            if let Some(mbid) = mgr.add_graphic(
                                build_mbox(
                                    60,
                                    20,
                                    line,
                                    "Hit Enter to type content in.".to_string(),
                                ),
                                mbox_layer,
                                (0, 0),
                            ) {
                                mgr.delete_graphic(tid);
                                mbox_id = mbid;
                                mgr.set_graphic(mbid, 0, true);
                                mbox_created = true;
                            }
                        }
                    } else {
                        let mut x = 1;
                        let mut y = 1;
                        mbox_created = false;
                        let mut rev = Glyph::default();
                        rev.set_reverse(true);
                        for i in 1..31 {
                            mgr.set_glyph(mbox_id, rev, i, 1);
                        }
                        loop {
                            if let Some(c) = mgr.read_char() {
                                if c == '\t' {
                                    break;
                                }
                                if c as u8 == 8 || c as u8 == 127 {
                                    x -= 1;
                                    if x == 0 {
                                        if y > 1 {
                                            y -= 1;
                                            x = 58;
                                        } else {
                                            x = 1;
                                        }
                                    }
                                    mgr.set_glyph(mbox_id, Glyph::default(), x, y);
                                    continue;
                                }
                                if c == '\n' {
                                    break;
                                }

                                mgr.set_glyph(mbox_id, Glyph::default_with_char(c), x, y);
                                x += 1;
                                if x > 58 {
                                    x = 1;
                                    y += 1;
                                }
                            }
                        }
                    }
                }
                _ => {
                    println!("You pressed: {:?}", key);
                }
            }
        }
    }
    mgr.terminate();
}
source

pub fn get_glyph(&self, gid: usize, col: usize, row: usize)

Request Manager to produce what Glyph is currently set for given graphic in specified location. Use read_result to get that Glyph.

source

pub fn load_graphic_from_file<P>( &self, filename: P, ) -> Result<AnimOk, AnimError>
where P: AsRef<Path> + Debug,

Use this method to load a graphic from plain text file. Each line should define a frame or an animation like following: frame 0 frame_0.txf animation loop run 0:1000 1:1000 2:1000 3:1000 4:1000 5:1000 6:1000 7:1000 8:1000 9:1000 loop and run in animation definitions are optional. What follows are frame ids in order from left to right with their display duration in ms after colon. Frames are defined in separate files each. They consist of regular ASCII/UTF-8 characters with optional ANSII escape sequences that modify color, background or font style. You can preview a frame_file.txf calling from terminal: less -R frame_file.txf . You can use accompanying studio terminal application in order to define your own frames.

source

pub fn empty_frame(&self, gid: usize)

Add an empty frame to a graphic.

Examples found in repository?
examples/example_5.rs (line 219)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
fn main() {
    let args = parse_arguments();
    let cols = args.cols;
    let rows = args.rows;
    verify_cols_and_rows(cols, rows);
    let mut g = Glyph::default();
    g.set_background(Color::green());
    g.set_char(char::from_u32(9626).unwrap());
    g.set_bright(true);

    let mut mgr = Manager::new(true, cols, rows, Some(g), None, None);
    let (cols, rows) = mgr.screen_size();

    let title = "Navigation help".to_string();
    let text = "CtrlPgUp,CtrlPgDn, -------------------------------------
AltPgUp,AltPgDn, ---------------------------------------
PgUp,PgDn, ---------------------------------------------
U,D, ---------------------------------------------------
CtrlU,CtrlD -------------------------------------------- 
AltU,AltD ----------------------------------------------
AltUp | AltK -------------------------------------------
CtrlUp | CtrlK -----------------------------------------
Up | K -------------------------------------------------
AltDown | AltJ -----------------------------------------
CtrlDown -----------------------------------------------
Down | J -----------------------------------------------
AltLeft | AltH -----------------------------------------
CtrlLeft | Backspace -----------------------------------
Left | H -----------------------------------------------
AltRight | AltL ----------------------------------------
CtrlRight | CtrlL --------------------------------------
Right | L - all above move graphics around the screen --
----------- and up/down layers. ------------------------
Tab - show a message box -------------------------------
Enter - type some text and hit Enter again -------------
        "
    .to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 60, 23);
    let mbid = mgr.add_graphic(mbox, 4, (1, 10)).unwrap();
    mgr.set_graphic(mbid, 0, true);
    let (gr, pid) = build_graphic(130, 10);
    let gr_layer = 1;
    let gid;
    let result = mgr.add_graphic(gr, gr_layer, (3, 15));
    if let Some(id) = result {
        gid = id;
    } else {
        eprintln!("Did not receive first graphic id");
        exit(2);
    }
    mgr.set_graphic(gid, pid, true);

    let pbid;
    let mut pb_layer = 3;
    let result = mgr.add_graphic(
        build_progress_bar(cols - 4),
        pb_layer,
        (2, (rows - 2) as isize),
    );
    if let Some(id) = result {
        pbid = id;
    } else {
        eprintln!("Did not receive progress bar graphic id");
        exit(2);
    }
    mgr.set_graphic(pbid, 0, true);
    mgr.start_animation(pbid, 0);
    let mut mbox_created = false;
    let mut mbox_id = 100;
    let mut mbox_layer = 2;
    if Path::new("index.txg").exists() {
        if let Some(id) =
            mgr.add_graphic(Graphic::from_file("index.txg").unwrap(), mbox_layer, (1, 0))
        {
            mgr.move_graphic(id, 2, (-1, 0));
            mbox_id = id;
            mbox_layer = 4;
        }
    } else {
        eprintln!("\x1b[97;41;5mERR\x1b[m Unable to load index.txg. Run this example from within top examples directory!");
        eprintln!("\x1b[97;41;5mERR\x1b[m Or copy *.txf and index.txg from there to current dir.");
        exit(1);
    }

    loop {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::AltUnicode(uni) => match (uni[2], uni[4]) {
                    (53, 53) => {
                        //CtrlPgUp
                        mgr.move_graphic(1, 4, (0, 0));
                    }
                    (54, 53) => {
                        //CtrlPgDn
                        mgr.move_graphic(1, 1, (0, 0));
                    }
                    (53, 51) => {
                        //AltPgUp
                        mgr.move_graphic(2, 5, (0, 0));
                    }
                    (54, 51) => {
                        //AltPgDn
                        mgr.move_graphic(2, 2, (0, 0));
                    }
                    _ => {}
                },
                Key::PgUp | Key::U => {
                    mgr.move_graphic(0, 3, (0, 0));
                }
                Key::PgDn | Key::D => {
                    mgr.move_graphic(0, 0, (0, 0));
                }
                Key::CtrlU => {
                    pb_layer = 4;
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::CtrlD => {
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::AltU => {
                    mbox_layer = 5;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltD => {
                    mbox_layer = 2;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltUp | Key::AltK => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, -1));
                }
                Key::CtrlUp | Key::CtrlK => {
                    mgr.move_graphic(pbid, pb_layer, (0, -1));
                }
                Key::Up | Key::K => {
                    mgr.stop_animation(gid);
                    mgr.move_graphic(gid, 1, (0, -1));
                    mgr.set_graphic(gid, 1, true);
                }
                Key::AltDown | Key::AltJ => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 1));
                }
                Key::CtrlDown => {
                    mgr.move_graphic(pbid, pb_layer, (0, 1));
                }
                Key::Down | Key::J => {
                    mgr.pause_animation_on_frame(pbid, 100);
                    mgr.move_graphic(gid, 1, (0, 1));
                    mgr.set_graphic(gid, pid, true);
                }
                Key::AltLeft | Key::AltH => {
                    mgr.move_graphic(mbox_id, mbox_layer, (-1, 0));
                }
                Key::CtrlLeft | Key::Backspace => {
                    mgr.move_graphic(pbid, pb_layer, (-1, 0));
                }
                Key::Left | Key::H => {
                    mgr.move_graphic(gid, 1, (-1, 0));
                    mgr.start_animation(gid, 0);
                    mgr.start_animation(pbid, 0);
                }
                Key::AltRight | Key::AltL => {
                    mgr.move_graphic(mbox_id, mbox_layer, (1, 0));
                }
                Key::CtrlRight | Key::CtrlL => {
                    mgr.move_graphic(pbid, pb_layer, (1, 0));
                }
                Key::Right | Key::L => {
                    mgr.move_graphic(gid, 1, (1, 0));
                }
                Key::Tab => {
                    mbox_layer += 1;
                    if !mbox_created {
                        if let  Some(mbid) = mgr.add_graphic(
                            build_mbox(60, 20, "La ku ka ra cza ga wi ga ba ga da da da ja nie".to_string(),
                            "lastBuildDate: Tue, 12 Apr 2022 07:52:44 GMT
* generator: Oddmuse
* copyright: This work is licensed to you under version 2 of the GNU General Public License. Alternatively, you may choose to receive this work under
 any other license that grants the right to use, copy, modify, and distribute the work, as long as that license imposes the restriction that derivative
 works have to grant the same rights and impose the same restriction. For example, you may choose to receive this work under the GNU Free
 Documentation License, the CreativeCommons ShareAlike License, the XEmacs manual license, or similar licenses.
* license: https://creativecommons.org/licenses/sa/1.0/
* license: https://www.gnu.org/copyleft/fdl.html
* license: https://www.gnu.org/copyleft/gpl.html".to_string()                        ),
                        mbox_layer,
                        (0, 0),
                    ){
                        mgr.set_graphic(mbid, 0, true);
                            mbox_created = true;
                            mbox_id = mbid;
                        }
                    }
                }
                Key::CtrlA => {
                    mgr.start_animation(gid, 0);
                }
                Key::CtrlB => {
                    mgr.stop_animation(gid);
                }
                Key::Insert => {
                    mgr.set_graphic(gid, 2, false);
                }
                Key::Delete => {}
                Key::Home => {
                    mgr.set_glyph(gid, Glyph::default(), 1, 1);
                    mgr.move_graphic(gid, 1, (0, 0));
                    mgr.empty_frame(gid);
                }
                Key::Escape | Key::Q | Key::CtrlQ => {
                    break;
                }
                Key::Enter => {
                    if !mbox_created {
                        mbox_layer += 1;
                        if let Some(tid) = mgr.add_graphic(
                            build_mbox(
                                40,
                                1,
                                "Please enter title and hit Enter".to_string(),
                                String::new(),
                            ),
                            mbox_layer,
                            (cols as isize / 2 - 20, rows as isize / 2),
                        ) {
                            mgr.set_graphic(tid, 0, true);
                            let line = mgr.read_line();
                            if let Some(mbid) = mgr.add_graphic(
                                build_mbox(
                                    60,
                                    20,
                                    line,
                                    "Hit Enter to type content in.".to_string(),
                                ),
                                mbox_layer,
                                (0, 0),
                            ) {
                                mgr.delete_graphic(tid);
                                mbox_id = mbid;
                                mgr.set_graphic(mbid, 0, true);
                                mbox_created = true;
                            }
                        }
                    } else {
                        let mut x = 1;
                        let mut y = 1;
                        mbox_created = false;
                        let mut rev = Glyph::default();
                        rev.set_reverse(true);
                        for i in 1..31 {
                            mgr.set_glyph(mbox_id, rev, i, 1);
                        }
                        loop {
                            if let Some(c) = mgr.read_char() {
                                if c == '\t' {
                                    break;
                                }
                                if c as u8 == 8 || c as u8 == 127 {
                                    x -= 1;
                                    if x == 0 {
                                        if y > 1 {
                                            y -= 1;
                                            x = 58;
                                        } else {
                                            x = 1;
                                        }
                                    }
                                    mgr.set_glyph(mbox_id, Glyph::default(), x, y);
                                    continue;
                                }
                                if c == '\n' {
                                    break;
                                }

                                mgr.set_glyph(mbox_id, Glyph::default_with_char(c), x, y);
                                x += 1;
                                if x > 58 {
                                    x = 1;
                                    y += 1;
                                }
                            }
                        }
                    }
                }
                _ => {
                    println!("You pressed: {:?}", key);
                }
            }
        }
    }
    mgr.terminate();
}
source

pub fn clone_frame(&self, graphic_id: usize, frame_id: Option<usize>)

Add a cloned frame to a graphic.

source

pub fn move_cursor(&self, x: usize, y: usize)

Create a new clean display, optionally keeping current one.

Examples found in repository?
examples/example_1.rs (line 72)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
fn main() {
    let macros = Some(vec![
        (Key::AltM, MacroSequence::empty()),
        (
            Key::T,
            MacroSequence::from_text(
                "This text was typed with a single key press!".to_string(),
                Duration::from_millis(100),
                false,
            ),
        ),
    ]);
    let mut mgr = Manager::new(true, None, None, None, None, macros);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let gr = Graphic::new(cols, rows, start_frame, library, None);

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    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();
    let mbox = message_box(Some(title), text, Glyph::default(), 37, 7);
    let mbid = mgr.add_graphic(mbox, 1, (1, screen_size.1 as isize - 10));
    if let Some(mid) = mbid {
        mgr.set_graphic(mid, 0, true);
    }

    let mut keep_running = true;
    mgr.move_cursor(1, 1);
    let mut macro_mode: u8 = 0;
    let mut looped = false;
    while keep_running {
        let read_result = mgr.read_key();
        if read_result.is_none() {
            continue;
        }
        let key = read_result.unwrap();
        if let Some(ch) = map_key_to_char(&key) {
            if macro_mode == 0 {
                print!("{}", ch);
            }
        }
        match key {
            Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
            Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
            Key::AltM => match macro_mode {
                0 => {
                    // let (max_x, may_y)=mgr.screen_size();
                    // mgr.clear_area(0, (0,1),(max_x,4) );
                    println!("Press trigger key (or AltM again to toggle macro looping)");
                    macro_mode = 1;
                }
                1 => {
                    looped = !looped;
                    println!("Macro looping: {}", looped);
                }
                2 => {
                    println!("Macro is defined!");
                    macro_mode = 0;
                    looped = false;
                }
                _ => {
                    println!("This should not happen");
                }
            },
            Key::Q | Key::ShiftQ => {
                keep_running = false;
            }
            other => {
                if macro_mode == 1 {
                    println!("Macro trigger: {}", other);
                    println!("Not type macro sequence, followed by AltM");
                    macro_mode = 2;
                } else if macro_mode == 2 {
                    println!("Macro sequence add: {}", other)
                } else {
                    continue;
                }
            }
        }
    }

    mgr.terminate();
}
source

pub fn new_display(&mut self, keep_existing: bool) -> usize

Create a new clean display, optionally keeping current one.

Examples found in repository?
examples/example_4.rs (line 53)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text =
        "Press 0 to select display 0\n Press 1 to select display 1\n Press q or Shift+q to quit\n"
            .to_string();
    let keep_existing = true;
    let first_display_id = 0;
    let mbox = message_box(Some(title.clone()), text.clone(), Glyph::default(), 32, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);
    let empty = Glyph::new(
        ' ',
        Color::green(),
        Color::black(),
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let full = Glyph::new(
        'X',
        Color::green(),
        Color::black(),
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let gid = mgr
        .add_graphic(progress_bar(screen_size.0, empty, full, None), 0, (1, 1))
        .unwrap();
    mgr.start_animation(gid, 0);
    let second_display_id = mgr.new_display(keep_existing);
    // let result = mgr.read_result();
    // if let Ok(AnimOk::DisplayStored(disp_id)) = result {
    //     first_display_id = disp_id;
    // }
    let mbox = message_box(Some(title), text, Glyph::default(), 32, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.restore_display(first_display_id, true),
                Key::One => mgr.restore_display(second_display_id, true),
                Key::Two => mgr.restore_display(2, true),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
source

pub fn restore_display(&mut self, display_id: usize, keep_existing: bool)

Set display to a different one.

Examples found in repository?
examples/example_4.rs (line 68)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text =
        "Press 0 to select display 0\n Press 1 to select display 1\n Press q or Shift+q to quit\n"
            .to_string();
    let keep_existing = true;
    let first_display_id = 0;
    let mbox = message_box(Some(title.clone()), text.clone(), Glyph::default(), 32, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);
    let empty = Glyph::new(
        ' ',
        Color::green(),
        Color::black(),
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let full = Glyph::new(
        'X',
        Color::green(),
        Color::black(),
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let gid = mgr
        .add_graphic(progress_bar(screen_size.0, empty, full, None), 0, (1, 1))
        .unwrap();
    mgr.start_animation(gid, 0);
    let second_display_id = mgr.new_display(keep_existing);
    // let result = mgr.read_result();
    // if let Ok(AnimOk::DisplayStored(disp_id)) = result {
    //     first_display_id = disp_id;
    // }
    let mbox = message_box(Some(title), text, Glyph::default(), 32, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.restore_display(first_display_id, true),
                Key::One => mgr.restore_display(second_display_id, true),
                Key::Two => mgr.restore_display(2, true),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
source

pub fn add_graphic( &mut self, gr: Graphic, layer: usize, offset: (isize, isize), ) -> Option<usize>

Add a graphic to current display.

Examples found in repository?
examples/example_3.rs (line 49)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let gr = Graphic::new(cols, rows, start_frame, library, None);

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Use arrows to move graphic around \nPress q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 37, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(graphic_id, start_frame, true);
    mgr.set_graphic(mbid, 0, true);

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Left => mgr.move_graphic(graphic_id, layer, (-1, 0)),
                Key::Right => mgr.move_graphic(graphic_id, layer, (1, 0)),
                Key::Up => mgr.move_graphic(graphic_id, layer, (0, -1)),
                Key::Down => mgr.move_graphic(graphic_id, layer, (0, 1)),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
More examples
Hide additional examples
examples/example_4.rs (line 16)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text =
        "Press 0 to select display 0\n Press 1 to select display 1\n Press q or Shift+q to quit\n"
            .to_string();
    let keep_existing = true;
    let first_display_id = 0;
    let mbox = message_box(Some(title.clone()), text.clone(), Glyph::default(), 32, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);
    let empty = Glyph::new(
        ' ',
        Color::green(),
        Color::black(),
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let full = Glyph::new(
        'X',
        Color::green(),
        Color::black(),
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let gid = mgr
        .add_graphic(progress_bar(screen_size.0, empty, full, None), 0, (1, 1))
        .unwrap();
    mgr.start_animation(gid, 0);
    let second_display_id = mgr.new_display(keep_existing);
    // let result = mgr.read_result();
    // if let Ok(AnimOk::DisplayStored(disp_id)) = result {
    //     first_display_id = disp_id;
    // }
    let mbox = message_box(Some(title), text, Glyph::default(), 32, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.restore_display(first_display_id, true),
                Key::One => mgr.restore_display(second_display_id, true),
                Key::Two => mgr.restore_display(2, true),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
examples/example_1.rs (line 61)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
fn main() {
    let macros = Some(vec![
        (Key::AltM, MacroSequence::empty()),
        (
            Key::T,
            MacroSequence::from_text(
                "This text was typed with a single key press!".to_string(),
                Duration::from_millis(100),
                false,
            ),
        ),
    ]);
    let mut mgr = Manager::new(true, None, None, None, None, macros);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let gr = Graphic::new(cols, rows, start_frame, library, None);

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    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();
    let mbox = message_box(Some(title), text, Glyph::default(), 37, 7);
    let mbid = mgr.add_graphic(mbox, 1, (1, screen_size.1 as isize - 10));
    if let Some(mid) = mbid {
        mgr.set_graphic(mid, 0, true);
    }

    let mut keep_running = true;
    mgr.move_cursor(1, 1);
    let mut macro_mode: u8 = 0;
    let mut looped = false;
    while keep_running {
        let read_result = mgr.read_key();
        if read_result.is_none() {
            continue;
        }
        let key = read_result.unwrap();
        if let Some(ch) = map_key_to_char(&key) {
            if macro_mode == 0 {
                print!("{}", ch);
            }
        }
        match key {
            Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
            Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
            Key::AltM => match macro_mode {
                0 => {
                    // let (max_x, may_y)=mgr.screen_size();
                    // mgr.clear_area(0, (0,1),(max_x,4) );
                    println!("Press trigger key (or AltM again to toggle macro looping)");
                    macro_mode = 1;
                }
                1 => {
                    looped = !looped;
                    println!("Macro looping: {}", looped);
                }
                2 => {
                    println!("Macro is defined!");
                    macro_mode = 0;
                    looped = false;
                }
                _ => {
                    println!("This should not happen");
                }
            },
            Key::Q | Key::ShiftQ => {
                keep_running = false;
            }
            other => {
                if macro_mode == 1 {
                    println!("Macro trigger: {}", other);
                    println!("Not type macro sequence, followed by AltM");
                    macro_mode = 2;
                } else if macro_mode == 2 {
                    println!("Macro sequence add: {}", other)
                } else {
                    continue;
                }
            }
        }
    }

    mgr.terminate();
}
examples/example_2.rs (line 69)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let ordering = vec![
        (start_frame, Timestamp::new(0, 500)),
        (start_frame + 1, Timestamp::new(0, 500)),
    ];
    let running = false;
    let looping = true;
    let start_time = Timestamp::now();
    let animation = Animation::new(running, looping, ordering, start_time);
    let mut animations = HashMap::new();
    let anim_id = 0;
    animations.insert(anim_id, animation);
    let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
    let fast_ordering = vec![
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
    ];
    let mut fast_anim_id = anim_id;
    if let Some(id) = gr.add_animation(Animation::new(running, looping, fast_ordering, start_time))
    {
        fast_anim_id = id;
    };

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Press 0 to set current frame to 0\n Press 1 to set current frame to 1\n Press a|Shift+a|Ctrl+a start anim \n Press s or Shift+s stop animation\n\n Press q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 80, 17);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 8))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let var_ordering = vec![
        (start_frame, Timestamp::new(0, 400)),
        (start_frame + 1, Timestamp::new(0, 400)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 100)),
        (start_frame + 1, Timestamp::new(0, 100)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
    ];
    // let mut all_results_read = false;
    // while !all_results_read {
    //     let result = mgr.read_result();
    //     match result {
    //         Ok(AnimOk::AllResultsRead) => all_results_read = true,
    //         _ => continue,
    //     }
    // }
    mgr.add_animation(
        graphic_id,
        Animation::new(false, true, var_ordering, Timestamp::now()),
    );
    let mut var_anim_id = 0;

    if let Ok(AnimOk::AnimationAdded(anim_id)) = mgr.read_result() {
        var_anim_id = anim_id;
    }

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
                Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
                Key::A => mgr.start_animation(graphic_id, anim_id),
                Key::ShiftA => mgr.start_animation(graphic_id, fast_anim_id),
                Key::P => mgr.pause_animation(graphic_id),
                Key::CtrlP => mgr.pause_animation(graphic_id),
                Key::ShiftP => mgr.pause_animation_on_frame(graphic_id, start_frame),
                Key::CtrlA => mgr.start_animation(graphic_id, var_anim_id),
                Key::S | Key::ShiftS => mgr.stop_animation(graphic_id),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
examples/example_5.rs (line 52)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
fn main() {
    let args = parse_arguments();
    let cols = args.cols;
    let rows = args.rows;
    verify_cols_and_rows(cols, rows);
    let mut g = Glyph::default();
    g.set_background(Color::green());
    g.set_char(char::from_u32(9626).unwrap());
    g.set_bright(true);

    let mut mgr = Manager::new(true, cols, rows, Some(g), None, None);
    let (cols, rows) = mgr.screen_size();

    let title = "Navigation help".to_string();
    let text = "CtrlPgUp,CtrlPgDn, -------------------------------------
AltPgUp,AltPgDn, ---------------------------------------
PgUp,PgDn, ---------------------------------------------
U,D, ---------------------------------------------------
CtrlU,CtrlD -------------------------------------------- 
AltU,AltD ----------------------------------------------
AltUp | AltK -------------------------------------------
CtrlUp | CtrlK -----------------------------------------
Up | K -------------------------------------------------
AltDown | AltJ -----------------------------------------
CtrlDown -----------------------------------------------
Down | J -----------------------------------------------
AltLeft | AltH -----------------------------------------
CtrlLeft | Backspace -----------------------------------
Left | H -----------------------------------------------
AltRight | AltL ----------------------------------------
CtrlRight | CtrlL --------------------------------------
Right | L - all above move graphics around the screen --
----------- and up/down layers. ------------------------
Tab - show a message box -------------------------------
Enter - type some text and hit Enter again -------------
        "
    .to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 60, 23);
    let mbid = mgr.add_graphic(mbox, 4, (1, 10)).unwrap();
    mgr.set_graphic(mbid, 0, true);
    let (gr, pid) = build_graphic(130, 10);
    let gr_layer = 1;
    let gid;
    let result = mgr.add_graphic(gr, gr_layer, (3, 15));
    if let Some(id) = result {
        gid = id;
    } else {
        eprintln!("Did not receive first graphic id");
        exit(2);
    }
    mgr.set_graphic(gid, pid, true);

    let pbid;
    let mut pb_layer = 3;
    let result = mgr.add_graphic(
        build_progress_bar(cols - 4),
        pb_layer,
        (2, (rows - 2) as isize),
    );
    if let Some(id) = result {
        pbid = id;
    } else {
        eprintln!("Did not receive progress bar graphic id");
        exit(2);
    }
    mgr.set_graphic(pbid, 0, true);
    mgr.start_animation(pbid, 0);
    let mut mbox_created = false;
    let mut mbox_id = 100;
    let mut mbox_layer = 2;
    if Path::new("index.txg").exists() {
        if let Some(id) =
            mgr.add_graphic(Graphic::from_file("index.txg").unwrap(), mbox_layer, (1, 0))
        {
            mgr.move_graphic(id, 2, (-1, 0));
            mbox_id = id;
            mbox_layer = 4;
        }
    } else {
        eprintln!("\x1b[97;41;5mERR\x1b[m Unable to load index.txg. Run this example from within top examples directory!");
        eprintln!("\x1b[97;41;5mERR\x1b[m Or copy *.txf and index.txg from there to current dir.");
        exit(1);
    }

    loop {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::AltUnicode(uni) => match (uni[2], uni[4]) {
                    (53, 53) => {
                        //CtrlPgUp
                        mgr.move_graphic(1, 4, (0, 0));
                    }
                    (54, 53) => {
                        //CtrlPgDn
                        mgr.move_graphic(1, 1, (0, 0));
                    }
                    (53, 51) => {
                        //AltPgUp
                        mgr.move_graphic(2, 5, (0, 0));
                    }
                    (54, 51) => {
                        //AltPgDn
                        mgr.move_graphic(2, 2, (0, 0));
                    }
                    _ => {}
                },
                Key::PgUp | Key::U => {
                    mgr.move_graphic(0, 3, (0, 0));
                }
                Key::PgDn | Key::D => {
                    mgr.move_graphic(0, 0, (0, 0));
                }
                Key::CtrlU => {
                    pb_layer = 4;
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::CtrlD => {
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::AltU => {
                    mbox_layer = 5;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltD => {
                    mbox_layer = 2;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltUp | Key::AltK => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, -1));
                }
                Key::CtrlUp | Key::CtrlK => {
                    mgr.move_graphic(pbid, pb_layer, (0, -1));
                }
                Key::Up | Key::K => {
                    mgr.stop_animation(gid);
                    mgr.move_graphic(gid, 1, (0, -1));
                    mgr.set_graphic(gid, 1, true);
                }
                Key::AltDown | Key::AltJ => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 1));
                }
                Key::CtrlDown => {
                    mgr.move_graphic(pbid, pb_layer, (0, 1));
                }
                Key::Down | Key::J => {
                    mgr.pause_animation_on_frame(pbid, 100);
                    mgr.move_graphic(gid, 1, (0, 1));
                    mgr.set_graphic(gid, pid, true);
                }
                Key::AltLeft | Key::AltH => {
                    mgr.move_graphic(mbox_id, mbox_layer, (-1, 0));
                }
                Key::CtrlLeft | Key::Backspace => {
                    mgr.move_graphic(pbid, pb_layer, (-1, 0));
                }
                Key::Left | Key::H => {
                    mgr.move_graphic(gid, 1, (-1, 0));
                    mgr.start_animation(gid, 0);
                    mgr.start_animation(pbid, 0);
                }
                Key::AltRight | Key::AltL => {
                    mgr.move_graphic(mbox_id, mbox_layer, (1, 0));
                }
                Key::CtrlRight | Key::CtrlL => {
                    mgr.move_graphic(pbid, pb_layer, (1, 0));
                }
                Key::Right | Key::L => {
                    mgr.move_graphic(gid, 1, (1, 0));
                }
                Key::Tab => {
                    mbox_layer += 1;
                    if !mbox_created {
                        if let  Some(mbid) = mgr.add_graphic(
                            build_mbox(60, 20, "La ku ka ra cza ga wi ga ba ga da da da ja nie".to_string(),
                            "lastBuildDate: Tue, 12 Apr 2022 07:52:44 GMT
* generator: Oddmuse
* copyright: This work is licensed to you under version 2 of the GNU General Public License. Alternatively, you may choose to receive this work under
 any other license that grants the right to use, copy, modify, and distribute the work, as long as that license imposes the restriction that derivative
 works have to grant the same rights and impose the same restriction. For example, you may choose to receive this work under the GNU Free
 Documentation License, the CreativeCommons ShareAlike License, the XEmacs manual license, or similar licenses.
* license: https://creativecommons.org/licenses/sa/1.0/
* license: https://www.gnu.org/copyleft/fdl.html
* license: https://www.gnu.org/copyleft/gpl.html".to_string()                        ),
                        mbox_layer,
                        (0, 0),
                    ){
                        mgr.set_graphic(mbid, 0, true);
                            mbox_created = true;
                            mbox_id = mbid;
                        }
                    }
                }
                Key::CtrlA => {
                    mgr.start_animation(gid, 0);
                }
                Key::CtrlB => {
                    mgr.stop_animation(gid);
                }
                Key::Insert => {
                    mgr.set_graphic(gid, 2, false);
                }
                Key::Delete => {}
                Key::Home => {
                    mgr.set_glyph(gid, Glyph::default(), 1, 1);
                    mgr.move_graphic(gid, 1, (0, 0));
                    mgr.empty_frame(gid);
                }
                Key::Escape | Key::Q | Key::CtrlQ => {
                    break;
                }
                Key::Enter => {
                    if !mbox_created {
                        mbox_layer += 1;
                        if let Some(tid) = mgr.add_graphic(
                            build_mbox(
                                40,
                                1,
                                "Please enter title and hit Enter".to_string(),
                                String::new(),
                            ),
                            mbox_layer,
                            (cols as isize / 2 - 20, rows as isize / 2),
                        ) {
                            mgr.set_graphic(tid, 0, true);
                            let line = mgr.read_line();
                            if let Some(mbid) = mgr.add_graphic(
                                build_mbox(
                                    60,
                                    20,
                                    line,
                                    "Hit Enter to type content in.".to_string(),
                                ),
                                mbox_layer,
                                (0, 0),
                            ) {
                                mgr.delete_graphic(tid);
                                mbox_id = mbid;
                                mgr.set_graphic(mbid, 0, true);
                                mbox_created = true;
                            }
                        }
                    } else {
                        let mut x = 1;
                        let mut y = 1;
                        mbox_created = false;
                        let mut rev = Glyph::default();
                        rev.set_reverse(true);
                        for i in 1..31 {
                            mgr.set_glyph(mbox_id, rev, i, 1);
                        }
                        loop {
                            if let Some(c) = mgr.read_char() {
                                if c == '\t' {
                                    break;
                                }
                                if c as u8 == 8 || c as u8 == 127 {
                                    x -= 1;
                                    if x == 0 {
                                        if y > 1 {
                                            y -= 1;
                                            x = 58;
                                        } else {
                                            x = 1;
                                        }
                                    }
                                    mgr.set_glyph(mbox_id, Glyph::default(), x, y);
                                    continue;
                                }
                                if c == '\n' {
                                    break;
                                }

                                mgr.set_glyph(mbox_id, Glyph::default_with_char(c), x, y);
                                x += 1;
                                if x > 58 {
                                    x = 1;
                                    y += 1;
                                }
                            }
                        }
                    }
                }
                _ => {
                    println!("You pressed: {:?}", key);
                }
            }
        }
    }
    mgr.terminate();
}
source

pub fn set_graphic(&self, gid: usize, fid: usize, force: bool)

Set a graphic to display a particular frame.

Examples found in repository?
examples/example_3.rs (line 57)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let gr = Graphic::new(cols, rows, start_frame, library, None);

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Use arrows to move graphic around \nPress q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 37, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(graphic_id, start_frame, true);
    mgr.set_graphic(mbid, 0, true);

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Left => mgr.move_graphic(graphic_id, layer, (-1, 0)),
                Key::Right => mgr.move_graphic(graphic_id, layer, (1, 0)),
                Key::Up => mgr.move_graphic(graphic_id, layer, (0, -1)),
                Key::Down => mgr.move_graphic(graphic_id, layer, (0, 1)),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
More examples
Hide additional examples
examples/example_4.rs (line 18)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text =
        "Press 0 to select display 0\n Press 1 to select display 1\n Press q or Shift+q to quit\n"
            .to_string();
    let keep_existing = true;
    let first_display_id = 0;
    let mbox = message_box(Some(title.clone()), text.clone(), Glyph::default(), 32, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);
    let empty = Glyph::new(
        ' ',
        Color::green(),
        Color::black(),
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let full = Glyph::new(
        'X',
        Color::green(),
        Color::black(),
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let gid = mgr
        .add_graphic(progress_bar(screen_size.0, empty, full, None), 0, (1, 1))
        .unwrap();
    mgr.start_animation(gid, 0);
    let second_display_id = mgr.new_display(keep_existing);
    // let result = mgr.read_result();
    // if let Ok(AnimOk::DisplayStored(disp_id)) = result {
    //     first_display_id = disp_id;
    // }
    let mbox = message_box(Some(title), text, Glyph::default(), 32, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.restore_display(first_display_id, true),
                Key::One => mgr.restore_display(second_display_id, true),
                Key::Two => mgr.restore_display(2, true),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
examples/example_1.rs (line 68)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
fn main() {
    let macros = Some(vec![
        (Key::AltM, MacroSequence::empty()),
        (
            Key::T,
            MacroSequence::from_text(
                "This text was typed with a single key press!".to_string(),
                Duration::from_millis(100),
                false,
            ),
        ),
    ]);
    let mut mgr = Manager::new(true, None, None, None, None, macros);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let gr = Graphic::new(cols, rows, start_frame, library, None);

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    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();
    let mbox = message_box(Some(title), text, Glyph::default(), 37, 7);
    let mbid = mgr.add_graphic(mbox, 1, (1, screen_size.1 as isize - 10));
    if let Some(mid) = mbid {
        mgr.set_graphic(mid, 0, true);
    }

    let mut keep_running = true;
    mgr.move_cursor(1, 1);
    let mut macro_mode: u8 = 0;
    let mut looped = false;
    while keep_running {
        let read_result = mgr.read_key();
        if read_result.is_none() {
            continue;
        }
        let key = read_result.unwrap();
        if let Some(ch) = map_key_to_char(&key) {
            if macro_mode == 0 {
                print!("{}", ch);
            }
        }
        match key {
            Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
            Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
            Key::AltM => match macro_mode {
                0 => {
                    // let (max_x, may_y)=mgr.screen_size();
                    // mgr.clear_area(0, (0,1),(max_x,4) );
                    println!("Press trigger key (or AltM again to toggle macro looping)");
                    macro_mode = 1;
                }
                1 => {
                    looped = !looped;
                    println!("Macro looping: {}", looped);
                }
                2 => {
                    println!("Macro is defined!");
                    macro_mode = 0;
                    looped = false;
                }
                _ => {
                    println!("This should not happen");
                }
            },
            Key::Q | Key::ShiftQ => {
                keep_running = false;
            }
            other => {
                if macro_mode == 1 {
                    println!("Macro trigger: {}", other);
                    println!("Not type macro sequence, followed by AltM");
                    macro_mode = 2;
                } else if macro_mode == 2 {
                    println!("Macro sequence add: {}", other)
                } else {
                    continue;
                }
            }
        }
    }

    mgr.terminate();
}
examples/example_2.rs (line 77)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let ordering = vec![
        (start_frame, Timestamp::new(0, 500)),
        (start_frame + 1, Timestamp::new(0, 500)),
    ];
    let running = false;
    let looping = true;
    let start_time = Timestamp::now();
    let animation = Animation::new(running, looping, ordering, start_time);
    let mut animations = HashMap::new();
    let anim_id = 0;
    animations.insert(anim_id, animation);
    let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
    let fast_ordering = vec![
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
    ];
    let mut fast_anim_id = anim_id;
    if let Some(id) = gr.add_animation(Animation::new(running, looping, fast_ordering, start_time))
    {
        fast_anim_id = id;
    };

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Press 0 to set current frame to 0\n Press 1 to set current frame to 1\n Press a|Shift+a|Ctrl+a start anim \n Press s or Shift+s stop animation\n\n Press q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 80, 17);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 8))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let var_ordering = vec![
        (start_frame, Timestamp::new(0, 400)),
        (start_frame + 1, Timestamp::new(0, 400)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 100)),
        (start_frame + 1, Timestamp::new(0, 100)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
    ];
    // let mut all_results_read = false;
    // while !all_results_read {
    //     let result = mgr.read_result();
    //     match result {
    //         Ok(AnimOk::AllResultsRead) => all_results_read = true,
    //         _ => continue,
    //     }
    // }
    mgr.add_animation(
        graphic_id,
        Animation::new(false, true, var_ordering, Timestamp::now()),
    );
    let mut var_anim_id = 0;

    if let Ok(AnimOk::AnimationAdded(anim_id)) = mgr.read_result() {
        var_anim_id = anim_id;
    }

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
                Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
                Key::A => mgr.start_animation(graphic_id, anim_id),
                Key::ShiftA => mgr.start_animation(graphic_id, fast_anim_id),
                Key::P => mgr.pause_animation(graphic_id),
                Key::CtrlP => mgr.pause_animation(graphic_id),
                Key::ShiftP => mgr.pause_animation_on_frame(graphic_id, start_frame),
                Key::CtrlA => mgr.start_animation(graphic_id, var_anim_id),
                Key::S | Key::ShiftS => mgr.stop_animation(graphic_id),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
examples/example_5.rs (line 53)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
fn main() {
    let args = parse_arguments();
    let cols = args.cols;
    let rows = args.rows;
    verify_cols_and_rows(cols, rows);
    let mut g = Glyph::default();
    g.set_background(Color::green());
    g.set_char(char::from_u32(9626).unwrap());
    g.set_bright(true);

    let mut mgr = Manager::new(true, cols, rows, Some(g), None, None);
    let (cols, rows) = mgr.screen_size();

    let title = "Navigation help".to_string();
    let text = "CtrlPgUp,CtrlPgDn, -------------------------------------
AltPgUp,AltPgDn, ---------------------------------------
PgUp,PgDn, ---------------------------------------------
U,D, ---------------------------------------------------
CtrlU,CtrlD -------------------------------------------- 
AltU,AltD ----------------------------------------------
AltUp | AltK -------------------------------------------
CtrlUp | CtrlK -----------------------------------------
Up | K -------------------------------------------------
AltDown | AltJ -----------------------------------------
CtrlDown -----------------------------------------------
Down | J -----------------------------------------------
AltLeft | AltH -----------------------------------------
CtrlLeft | Backspace -----------------------------------
Left | H -----------------------------------------------
AltRight | AltL ----------------------------------------
CtrlRight | CtrlL --------------------------------------
Right | L - all above move graphics around the screen --
----------- and up/down layers. ------------------------
Tab - show a message box -------------------------------
Enter - type some text and hit Enter again -------------
        "
    .to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 60, 23);
    let mbid = mgr.add_graphic(mbox, 4, (1, 10)).unwrap();
    mgr.set_graphic(mbid, 0, true);
    let (gr, pid) = build_graphic(130, 10);
    let gr_layer = 1;
    let gid;
    let result = mgr.add_graphic(gr, gr_layer, (3, 15));
    if let Some(id) = result {
        gid = id;
    } else {
        eprintln!("Did not receive first graphic id");
        exit(2);
    }
    mgr.set_graphic(gid, pid, true);

    let pbid;
    let mut pb_layer = 3;
    let result = mgr.add_graphic(
        build_progress_bar(cols - 4),
        pb_layer,
        (2, (rows - 2) as isize),
    );
    if let Some(id) = result {
        pbid = id;
    } else {
        eprintln!("Did not receive progress bar graphic id");
        exit(2);
    }
    mgr.set_graphic(pbid, 0, true);
    mgr.start_animation(pbid, 0);
    let mut mbox_created = false;
    let mut mbox_id = 100;
    let mut mbox_layer = 2;
    if Path::new("index.txg").exists() {
        if let Some(id) =
            mgr.add_graphic(Graphic::from_file("index.txg").unwrap(), mbox_layer, (1, 0))
        {
            mgr.move_graphic(id, 2, (-1, 0));
            mbox_id = id;
            mbox_layer = 4;
        }
    } else {
        eprintln!("\x1b[97;41;5mERR\x1b[m Unable to load index.txg. Run this example from within top examples directory!");
        eprintln!("\x1b[97;41;5mERR\x1b[m Or copy *.txf and index.txg from there to current dir.");
        exit(1);
    }

    loop {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::AltUnicode(uni) => match (uni[2], uni[4]) {
                    (53, 53) => {
                        //CtrlPgUp
                        mgr.move_graphic(1, 4, (0, 0));
                    }
                    (54, 53) => {
                        //CtrlPgDn
                        mgr.move_graphic(1, 1, (0, 0));
                    }
                    (53, 51) => {
                        //AltPgUp
                        mgr.move_graphic(2, 5, (0, 0));
                    }
                    (54, 51) => {
                        //AltPgDn
                        mgr.move_graphic(2, 2, (0, 0));
                    }
                    _ => {}
                },
                Key::PgUp | Key::U => {
                    mgr.move_graphic(0, 3, (0, 0));
                }
                Key::PgDn | Key::D => {
                    mgr.move_graphic(0, 0, (0, 0));
                }
                Key::CtrlU => {
                    pb_layer = 4;
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::CtrlD => {
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::AltU => {
                    mbox_layer = 5;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltD => {
                    mbox_layer = 2;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltUp | Key::AltK => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, -1));
                }
                Key::CtrlUp | Key::CtrlK => {
                    mgr.move_graphic(pbid, pb_layer, (0, -1));
                }
                Key::Up | Key::K => {
                    mgr.stop_animation(gid);
                    mgr.move_graphic(gid, 1, (0, -1));
                    mgr.set_graphic(gid, 1, true);
                }
                Key::AltDown | Key::AltJ => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 1));
                }
                Key::CtrlDown => {
                    mgr.move_graphic(pbid, pb_layer, (0, 1));
                }
                Key::Down | Key::J => {
                    mgr.pause_animation_on_frame(pbid, 100);
                    mgr.move_graphic(gid, 1, (0, 1));
                    mgr.set_graphic(gid, pid, true);
                }
                Key::AltLeft | Key::AltH => {
                    mgr.move_graphic(mbox_id, mbox_layer, (-1, 0));
                }
                Key::CtrlLeft | Key::Backspace => {
                    mgr.move_graphic(pbid, pb_layer, (-1, 0));
                }
                Key::Left | Key::H => {
                    mgr.move_graphic(gid, 1, (-1, 0));
                    mgr.start_animation(gid, 0);
                    mgr.start_animation(pbid, 0);
                }
                Key::AltRight | Key::AltL => {
                    mgr.move_graphic(mbox_id, mbox_layer, (1, 0));
                }
                Key::CtrlRight | Key::CtrlL => {
                    mgr.move_graphic(pbid, pb_layer, (1, 0));
                }
                Key::Right | Key::L => {
                    mgr.move_graphic(gid, 1, (1, 0));
                }
                Key::Tab => {
                    mbox_layer += 1;
                    if !mbox_created {
                        if let  Some(mbid) = mgr.add_graphic(
                            build_mbox(60, 20, "La ku ka ra cza ga wi ga ba ga da da da ja nie".to_string(),
                            "lastBuildDate: Tue, 12 Apr 2022 07:52:44 GMT
* generator: Oddmuse
* copyright: This work is licensed to you under version 2 of the GNU General Public License. Alternatively, you may choose to receive this work under
 any other license that grants the right to use, copy, modify, and distribute the work, as long as that license imposes the restriction that derivative
 works have to grant the same rights and impose the same restriction. For example, you may choose to receive this work under the GNU Free
 Documentation License, the CreativeCommons ShareAlike License, the XEmacs manual license, or similar licenses.
* license: https://creativecommons.org/licenses/sa/1.0/
* license: https://www.gnu.org/copyleft/fdl.html
* license: https://www.gnu.org/copyleft/gpl.html".to_string()                        ),
                        mbox_layer,
                        (0, 0),
                    ){
                        mgr.set_graphic(mbid, 0, true);
                            mbox_created = true;
                            mbox_id = mbid;
                        }
                    }
                }
                Key::CtrlA => {
                    mgr.start_animation(gid, 0);
                }
                Key::CtrlB => {
                    mgr.stop_animation(gid);
                }
                Key::Insert => {
                    mgr.set_graphic(gid, 2, false);
                }
                Key::Delete => {}
                Key::Home => {
                    mgr.set_glyph(gid, Glyph::default(), 1, 1);
                    mgr.move_graphic(gid, 1, (0, 0));
                    mgr.empty_frame(gid);
                }
                Key::Escape | Key::Q | Key::CtrlQ => {
                    break;
                }
                Key::Enter => {
                    if !mbox_created {
                        mbox_layer += 1;
                        if let Some(tid) = mgr.add_graphic(
                            build_mbox(
                                40,
                                1,
                                "Please enter title and hit Enter".to_string(),
                                String::new(),
                            ),
                            mbox_layer,
                            (cols as isize / 2 - 20, rows as isize / 2),
                        ) {
                            mgr.set_graphic(tid, 0, true);
                            let line = mgr.read_line();
                            if let Some(mbid) = mgr.add_graphic(
                                build_mbox(
                                    60,
                                    20,
                                    line,
                                    "Hit Enter to type content in.".to_string(),
                                ),
                                mbox_layer,
                                (0, 0),
                            ) {
                                mgr.delete_graphic(tid);
                                mbox_id = mbid;
                                mgr.set_graphic(mbid, 0, true);
                                mbox_created = true;
                            }
                        }
                    } else {
                        let mut x = 1;
                        let mut y = 1;
                        mbox_created = false;
                        let mut rev = Glyph::default();
                        rev.set_reverse(true);
                        for i in 1..31 {
                            mgr.set_glyph(mbox_id, rev, i, 1);
                        }
                        loop {
                            if let Some(c) = mgr.read_char() {
                                if c == '\t' {
                                    break;
                                }
                                if c as u8 == 8 || c as u8 == 127 {
                                    x -= 1;
                                    if x == 0 {
                                        if y > 1 {
                                            y -= 1;
                                            x = 58;
                                        } else {
                                            x = 1;
                                        }
                                    }
                                    mgr.set_glyph(mbox_id, Glyph::default(), x, y);
                                    continue;
                                }
                                if c == '\n' {
                                    break;
                                }

                                mgr.set_glyph(mbox_id, Glyph::default_with_char(c), x, y);
                                x += 1;
                                if x > 58 {
                                    x = 1;
                                    y += 1;
                                }
                            }
                        }
                    }
                }
                _ => {
                    println!("You pressed: {:?}", key);
                }
            }
        }
    }
    mgr.terminate();
}
source

pub fn set_graphic_color(&self, gid: usize, color: Color)

Set color of all glyphs under current graphic’s frame to given value.

source

pub fn set_graphic_background(&self, gid: usize, color: Color)

Set background color of all glyphs under current graphic’s frame to given value.

source

pub fn set_graphic_style(&self, gid: usize, glyph: Glyph)

Set style of all glyphs under current graphic’s frame to given value.

source

pub fn delete_graphic(&self, gid: usize)

Delete a graphic from current display.

Examples found in repository?
examples/example_5.rs (line 249)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
fn main() {
    let args = parse_arguments();
    let cols = args.cols;
    let rows = args.rows;
    verify_cols_and_rows(cols, rows);
    let mut g = Glyph::default();
    g.set_background(Color::green());
    g.set_char(char::from_u32(9626).unwrap());
    g.set_bright(true);

    let mut mgr = Manager::new(true, cols, rows, Some(g), None, None);
    let (cols, rows) = mgr.screen_size();

    let title = "Navigation help".to_string();
    let text = "CtrlPgUp,CtrlPgDn, -------------------------------------
AltPgUp,AltPgDn, ---------------------------------------
PgUp,PgDn, ---------------------------------------------
U,D, ---------------------------------------------------
CtrlU,CtrlD -------------------------------------------- 
AltU,AltD ----------------------------------------------
AltUp | AltK -------------------------------------------
CtrlUp | CtrlK -----------------------------------------
Up | K -------------------------------------------------
AltDown | AltJ -----------------------------------------
CtrlDown -----------------------------------------------
Down | J -----------------------------------------------
AltLeft | AltH -----------------------------------------
CtrlLeft | Backspace -----------------------------------
Left | H -----------------------------------------------
AltRight | AltL ----------------------------------------
CtrlRight | CtrlL --------------------------------------
Right | L - all above move graphics around the screen --
----------- and up/down layers. ------------------------
Tab - show a message box -------------------------------
Enter - type some text and hit Enter again -------------
        "
    .to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 60, 23);
    let mbid = mgr.add_graphic(mbox, 4, (1, 10)).unwrap();
    mgr.set_graphic(mbid, 0, true);
    let (gr, pid) = build_graphic(130, 10);
    let gr_layer = 1;
    let gid;
    let result = mgr.add_graphic(gr, gr_layer, (3, 15));
    if let Some(id) = result {
        gid = id;
    } else {
        eprintln!("Did not receive first graphic id");
        exit(2);
    }
    mgr.set_graphic(gid, pid, true);

    let pbid;
    let mut pb_layer = 3;
    let result = mgr.add_graphic(
        build_progress_bar(cols - 4),
        pb_layer,
        (2, (rows - 2) as isize),
    );
    if let Some(id) = result {
        pbid = id;
    } else {
        eprintln!("Did not receive progress bar graphic id");
        exit(2);
    }
    mgr.set_graphic(pbid, 0, true);
    mgr.start_animation(pbid, 0);
    let mut mbox_created = false;
    let mut mbox_id = 100;
    let mut mbox_layer = 2;
    if Path::new("index.txg").exists() {
        if let Some(id) =
            mgr.add_graphic(Graphic::from_file("index.txg").unwrap(), mbox_layer, (1, 0))
        {
            mgr.move_graphic(id, 2, (-1, 0));
            mbox_id = id;
            mbox_layer = 4;
        }
    } else {
        eprintln!("\x1b[97;41;5mERR\x1b[m Unable to load index.txg. Run this example from within top examples directory!");
        eprintln!("\x1b[97;41;5mERR\x1b[m Or copy *.txf and index.txg from there to current dir.");
        exit(1);
    }

    loop {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::AltUnicode(uni) => match (uni[2], uni[4]) {
                    (53, 53) => {
                        //CtrlPgUp
                        mgr.move_graphic(1, 4, (0, 0));
                    }
                    (54, 53) => {
                        //CtrlPgDn
                        mgr.move_graphic(1, 1, (0, 0));
                    }
                    (53, 51) => {
                        //AltPgUp
                        mgr.move_graphic(2, 5, (0, 0));
                    }
                    (54, 51) => {
                        //AltPgDn
                        mgr.move_graphic(2, 2, (0, 0));
                    }
                    _ => {}
                },
                Key::PgUp | Key::U => {
                    mgr.move_graphic(0, 3, (0, 0));
                }
                Key::PgDn | Key::D => {
                    mgr.move_graphic(0, 0, (0, 0));
                }
                Key::CtrlU => {
                    pb_layer = 4;
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::CtrlD => {
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::AltU => {
                    mbox_layer = 5;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltD => {
                    mbox_layer = 2;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltUp | Key::AltK => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, -1));
                }
                Key::CtrlUp | Key::CtrlK => {
                    mgr.move_graphic(pbid, pb_layer, (0, -1));
                }
                Key::Up | Key::K => {
                    mgr.stop_animation(gid);
                    mgr.move_graphic(gid, 1, (0, -1));
                    mgr.set_graphic(gid, 1, true);
                }
                Key::AltDown | Key::AltJ => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 1));
                }
                Key::CtrlDown => {
                    mgr.move_graphic(pbid, pb_layer, (0, 1));
                }
                Key::Down | Key::J => {
                    mgr.pause_animation_on_frame(pbid, 100);
                    mgr.move_graphic(gid, 1, (0, 1));
                    mgr.set_graphic(gid, pid, true);
                }
                Key::AltLeft | Key::AltH => {
                    mgr.move_graphic(mbox_id, mbox_layer, (-1, 0));
                }
                Key::CtrlLeft | Key::Backspace => {
                    mgr.move_graphic(pbid, pb_layer, (-1, 0));
                }
                Key::Left | Key::H => {
                    mgr.move_graphic(gid, 1, (-1, 0));
                    mgr.start_animation(gid, 0);
                    mgr.start_animation(pbid, 0);
                }
                Key::AltRight | Key::AltL => {
                    mgr.move_graphic(mbox_id, mbox_layer, (1, 0));
                }
                Key::CtrlRight | Key::CtrlL => {
                    mgr.move_graphic(pbid, pb_layer, (1, 0));
                }
                Key::Right | Key::L => {
                    mgr.move_graphic(gid, 1, (1, 0));
                }
                Key::Tab => {
                    mbox_layer += 1;
                    if !mbox_created {
                        if let  Some(mbid) = mgr.add_graphic(
                            build_mbox(60, 20, "La ku ka ra cza ga wi ga ba ga da da da ja nie".to_string(),
                            "lastBuildDate: Tue, 12 Apr 2022 07:52:44 GMT
* generator: Oddmuse
* copyright: This work is licensed to you under version 2 of the GNU General Public License. Alternatively, you may choose to receive this work under
 any other license that grants the right to use, copy, modify, and distribute the work, as long as that license imposes the restriction that derivative
 works have to grant the same rights and impose the same restriction. For example, you may choose to receive this work under the GNU Free
 Documentation License, the CreativeCommons ShareAlike License, the XEmacs manual license, or similar licenses.
* license: https://creativecommons.org/licenses/sa/1.0/
* license: https://www.gnu.org/copyleft/fdl.html
* license: https://www.gnu.org/copyleft/gpl.html".to_string()                        ),
                        mbox_layer,
                        (0, 0),
                    ){
                        mgr.set_graphic(mbid, 0, true);
                            mbox_created = true;
                            mbox_id = mbid;
                        }
                    }
                }
                Key::CtrlA => {
                    mgr.start_animation(gid, 0);
                }
                Key::CtrlB => {
                    mgr.stop_animation(gid);
                }
                Key::Insert => {
                    mgr.set_graphic(gid, 2, false);
                }
                Key::Delete => {}
                Key::Home => {
                    mgr.set_glyph(gid, Glyph::default(), 1, 1);
                    mgr.move_graphic(gid, 1, (0, 0));
                    mgr.empty_frame(gid);
                }
                Key::Escape | Key::Q | Key::CtrlQ => {
                    break;
                }
                Key::Enter => {
                    if !mbox_created {
                        mbox_layer += 1;
                        if let Some(tid) = mgr.add_graphic(
                            build_mbox(
                                40,
                                1,
                                "Please enter title and hit Enter".to_string(),
                                String::new(),
                            ),
                            mbox_layer,
                            (cols as isize / 2 - 20, rows as isize / 2),
                        ) {
                            mgr.set_graphic(tid, 0, true);
                            let line = mgr.read_line();
                            if let Some(mbid) = mgr.add_graphic(
                                build_mbox(
                                    60,
                                    20,
                                    line,
                                    "Hit Enter to type content in.".to_string(),
                                ),
                                mbox_layer,
                                (0, 0),
                            ) {
                                mgr.delete_graphic(tid);
                                mbox_id = mbid;
                                mgr.set_graphic(mbid, 0, true);
                                mbox_created = true;
                            }
                        }
                    } else {
                        let mut x = 1;
                        let mut y = 1;
                        mbox_created = false;
                        let mut rev = Glyph::default();
                        rev.set_reverse(true);
                        for i in 1..31 {
                            mgr.set_glyph(mbox_id, rev, i, 1);
                        }
                        loop {
                            if let Some(c) = mgr.read_char() {
                                if c == '\t' {
                                    break;
                                }
                                if c as u8 == 8 || c as u8 == 127 {
                                    x -= 1;
                                    if x == 0 {
                                        if y > 1 {
                                            y -= 1;
                                            x = 58;
                                        } else {
                                            x = 1;
                                        }
                                    }
                                    mgr.set_glyph(mbox_id, Glyph::default(), x, y);
                                    continue;
                                }
                                if c == '\n' {
                                    break;
                                }

                                mgr.set_glyph(mbox_id, Glyph::default_with_char(c), x, y);
                                x += 1;
                                if x > 58 {
                                    x = 1;
                                    y += 1;
                                }
                            }
                        }
                    }
                }
                _ => {
                    println!("You pressed: {:?}", key);
                }
            }
        }
    }
    mgr.terminate();
}
source

pub fn print_graphic(&self, gid: usize, skip_border: bool)

Request Manager to provide a String of given graphic for manipulation or permanent storage.

source

pub fn print_screen(&self)

Request Manager to provide a String of entire screen for manipulation or permanent storage.

source

pub fn print_screen_section( &self, offset: (usize, usize), cols: usize, rows: usize, )

Request Manager to provide a String of selected screen section for manipulation or permanent storage.

source

pub fn terminate(self)

Restore terminal to regular buffer when application is about to quit.

Examples found in repository?
examples/example_3.rs (line 76)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let gr = Graphic::new(cols, rows, start_frame, library, None);

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Use arrows to move graphic around \nPress q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 37, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(graphic_id, start_frame, true);
    mgr.set_graphic(mbid, 0, true);

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Left => mgr.move_graphic(graphic_id, layer, (-1, 0)),
                Key::Right => mgr.move_graphic(graphic_id, layer, (1, 0)),
                Key::Up => mgr.move_graphic(graphic_id, layer, (0, -1)),
                Key::Down => mgr.move_graphic(graphic_id, layer, (0, 1)),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
More examples
Hide additional examples
examples/example_4.rs (line 79)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text =
        "Press 0 to select display 0\n Press 1 to select display 1\n Press q or Shift+q to quit\n"
            .to_string();
    let keep_existing = true;
    let first_display_id = 0;
    let mbox = message_box(Some(title.clone()), text.clone(), Glyph::default(), 32, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);
    let empty = Glyph::new(
        ' ',
        Color::green(),
        Color::black(),
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let full = Glyph::new(
        'X',
        Color::green(),
        Color::black(),
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let gid = mgr
        .add_graphic(progress_bar(screen_size.0, empty, full, None), 0, (1, 1))
        .unwrap();
    mgr.start_animation(gid, 0);
    let second_display_id = mgr.new_display(keep_existing);
    // let result = mgr.read_result();
    // if let Ok(AnimOk::DisplayStored(disp_id)) = result {
    //     first_display_id = disp_id;
    // }
    let mbox = message_box(Some(title), text, Glyph::default(), 32, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.restore_display(first_display_id, true),
                Key::One => mgr.restore_display(second_display_id, true),
                Key::Two => mgr.restore_display(2, true),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
examples/example_1.rs (line 126)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
fn main() {
    let macros = Some(vec![
        (Key::AltM, MacroSequence::empty()),
        (
            Key::T,
            MacroSequence::from_text(
                "This text was typed with a single key press!".to_string(),
                Duration::from_millis(100),
                false,
            ),
        ),
    ]);
    let mut mgr = Manager::new(true, None, None, None, None, macros);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let gr = Graphic::new(cols, rows, start_frame, library, None);

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    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();
    let mbox = message_box(Some(title), text, Glyph::default(), 37, 7);
    let mbid = mgr.add_graphic(mbox, 1, (1, screen_size.1 as isize - 10));
    if let Some(mid) = mbid {
        mgr.set_graphic(mid, 0, true);
    }

    let mut keep_running = true;
    mgr.move_cursor(1, 1);
    let mut macro_mode: u8 = 0;
    let mut looped = false;
    while keep_running {
        let read_result = mgr.read_key();
        if read_result.is_none() {
            continue;
        }
        let key = read_result.unwrap();
        if let Some(ch) = map_key_to_char(&key) {
            if macro_mode == 0 {
                print!("{}", ch);
            }
        }
        match key {
            Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
            Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
            Key::AltM => match macro_mode {
                0 => {
                    // let (max_x, may_y)=mgr.screen_size();
                    // mgr.clear_area(0, (0,1),(max_x,4) );
                    println!("Press trigger key (or AltM again to toggle macro looping)");
                    macro_mode = 1;
                }
                1 => {
                    looped = !looped;
                    println!("Macro looping: {}", looped);
                }
                2 => {
                    println!("Macro is defined!");
                    macro_mode = 0;
                    looped = false;
                }
                _ => {
                    println!("This should not happen");
                }
            },
            Key::Q | Key::ShiftQ => {
                keep_running = false;
            }
            other => {
                if macro_mode == 1 {
                    println!("Macro trigger: {}", other);
                    println!("Not type macro sequence, followed by AltM");
                    macro_mode = 2;
                } else if macro_mode == 2 {
                    println!("Macro sequence add: {}", other)
                } else {
                    continue;
                }
            }
        }
    }

    mgr.terminate();
}
examples/example_2.rs (line 132)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let ordering = vec![
        (start_frame, Timestamp::new(0, 500)),
        (start_frame + 1, Timestamp::new(0, 500)),
    ];
    let running = false;
    let looping = true;
    let start_time = Timestamp::now();
    let animation = Animation::new(running, looping, ordering, start_time);
    let mut animations = HashMap::new();
    let anim_id = 0;
    animations.insert(anim_id, animation);
    let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
    let fast_ordering = vec![
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
    ];
    let mut fast_anim_id = anim_id;
    if let Some(id) = gr.add_animation(Animation::new(running, looping, fast_ordering, start_time))
    {
        fast_anim_id = id;
    };

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Press 0 to set current frame to 0\n Press 1 to set current frame to 1\n Press a|Shift+a|Ctrl+a start anim \n Press s or Shift+s stop animation\n\n Press q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 80, 17);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 8))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let var_ordering = vec![
        (start_frame, Timestamp::new(0, 400)),
        (start_frame + 1, Timestamp::new(0, 400)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 100)),
        (start_frame + 1, Timestamp::new(0, 100)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
    ];
    // let mut all_results_read = false;
    // while !all_results_read {
    //     let result = mgr.read_result();
    //     match result {
    //         Ok(AnimOk::AllResultsRead) => all_results_read = true,
    //         _ => continue,
    //     }
    // }
    mgr.add_animation(
        graphic_id,
        Animation::new(false, true, var_ordering, Timestamp::now()),
    );
    let mut var_anim_id = 0;

    if let Ok(AnimOk::AnimationAdded(anim_id)) = mgr.read_result() {
        var_anim_id = anim_id;
    }

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
                Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
                Key::A => mgr.start_animation(graphic_id, anim_id),
                Key::ShiftA => mgr.start_animation(graphic_id, fast_anim_id),
                Key::P => mgr.pause_animation(graphic_id),
                Key::CtrlP => mgr.pause_animation(graphic_id),
                Key::ShiftP => mgr.pause_animation_on_frame(graphic_id, start_frame),
                Key::CtrlA => mgr.start_animation(graphic_id, var_anim_id),
                Key::S | Key::ShiftS => mgr.stop_animation(graphic_id),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
examples/example_5.rs (line 302)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
fn main() {
    let args = parse_arguments();
    let cols = args.cols;
    let rows = args.rows;
    verify_cols_and_rows(cols, rows);
    let mut g = Glyph::default();
    g.set_background(Color::green());
    g.set_char(char::from_u32(9626).unwrap());
    g.set_bright(true);

    let mut mgr = Manager::new(true, cols, rows, Some(g), None, None);
    let (cols, rows) = mgr.screen_size();

    let title = "Navigation help".to_string();
    let text = "CtrlPgUp,CtrlPgDn, -------------------------------------
AltPgUp,AltPgDn, ---------------------------------------
PgUp,PgDn, ---------------------------------------------
U,D, ---------------------------------------------------
CtrlU,CtrlD -------------------------------------------- 
AltU,AltD ----------------------------------------------
AltUp | AltK -------------------------------------------
CtrlUp | CtrlK -----------------------------------------
Up | K -------------------------------------------------
AltDown | AltJ -----------------------------------------
CtrlDown -----------------------------------------------
Down | J -----------------------------------------------
AltLeft | AltH -----------------------------------------
CtrlLeft | Backspace -----------------------------------
Left | H -----------------------------------------------
AltRight | AltL ----------------------------------------
CtrlRight | CtrlL --------------------------------------
Right | L - all above move graphics around the screen --
----------- and up/down layers. ------------------------
Tab - show a message box -------------------------------
Enter - type some text and hit Enter again -------------
        "
    .to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 60, 23);
    let mbid = mgr.add_graphic(mbox, 4, (1, 10)).unwrap();
    mgr.set_graphic(mbid, 0, true);
    let (gr, pid) = build_graphic(130, 10);
    let gr_layer = 1;
    let gid;
    let result = mgr.add_graphic(gr, gr_layer, (3, 15));
    if let Some(id) = result {
        gid = id;
    } else {
        eprintln!("Did not receive first graphic id");
        exit(2);
    }
    mgr.set_graphic(gid, pid, true);

    let pbid;
    let mut pb_layer = 3;
    let result = mgr.add_graphic(
        build_progress_bar(cols - 4),
        pb_layer,
        (2, (rows - 2) as isize),
    );
    if let Some(id) = result {
        pbid = id;
    } else {
        eprintln!("Did not receive progress bar graphic id");
        exit(2);
    }
    mgr.set_graphic(pbid, 0, true);
    mgr.start_animation(pbid, 0);
    let mut mbox_created = false;
    let mut mbox_id = 100;
    let mut mbox_layer = 2;
    if Path::new("index.txg").exists() {
        if let Some(id) =
            mgr.add_graphic(Graphic::from_file("index.txg").unwrap(), mbox_layer, (1, 0))
        {
            mgr.move_graphic(id, 2, (-1, 0));
            mbox_id = id;
            mbox_layer = 4;
        }
    } else {
        eprintln!("\x1b[97;41;5mERR\x1b[m Unable to load index.txg. Run this example from within top examples directory!");
        eprintln!("\x1b[97;41;5mERR\x1b[m Or copy *.txf and index.txg from there to current dir.");
        exit(1);
    }

    loop {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::AltUnicode(uni) => match (uni[2], uni[4]) {
                    (53, 53) => {
                        //CtrlPgUp
                        mgr.move_graphic(1, 4, (0, 0));
                    }
                    (54, 53) => {
                        //CtrlPgDn
                        mgr.move_graphic(1, 1, (0, 0));
                    }
                    (53, 51) => {
                        //AltPgUp
                        mgr.move_graphic(2, 5, (0, 0));
                    }
                    (54, 51) => {
                        //AltPgDn
                        mgr.move_graphic(2, 2, (0, 0));
                    }
                    _ => {}
                },
                Key::PgUp | Key::U => {
                    mgr.move_graphic(0, 3, (0, 0));
                }
                Key::PgDn | Key::D => {
                    mgr.move_graphic(0, 0, (0, 0));
                }
                Key::CtrlU => {
                    pb_layer = 4;
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::CtrlD => {
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::AltU => {
                    mbox_layer = 5;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltD => {
                    mbox_layer = 2;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltUp | Key::AltK => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, -1));
                }
                Key::CtrlUp | Key::CtrlK => {
                    mgr.move_graphic(pbid, pb_layer, (0, -1));
                }
                Key::Up | Key::K => {
                    mgr.stop_animation(gid);
                    mgr.move_graphic(gid, 1, (0, -1));
                    mgr.set_graphic(gid, 1, true);
                }
                Key::AltDown | Key::AltJ => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 1));
                }
                Key::CtrlDown => {
                    mgr.move_graphic(pbid, pb_layer, (0, 1));
                }
                Key::Down | Key::J => {
                    mgr.pause_animation_on_frame(pbid, 100);
                    mgr.move_graphic(gid, 1, (0, 1));
                    mgr.set_graphic(gid, pid, true);
                }
                Key::AltLeft | Key::AltH => {
                    mgr.move_graphic(mbox_id, mbox_layer, (-1, 0));
                }
                Key::CtrlLeft | Key::Backspace => {
                    mgr.move_graphic(pbid, pb_layer, (-1, 0));
                }
                Key::Left | Key::H => {
                    mgr.move_graphic(gid, 1, (-1, 0));
                    mgr.start_animation(gid, 0);
                    mgr.start_animation(pbid, 0);
                }
                Key::AltRight | Key::AltL => {
                    mgr.move_graphic(mbox_id, mbox_layer, (1, 0));
                }
                Key::CtrlRight | Key::CtrlL => {
                    mgr.move_graphic(pbid, pb_layer, (1, 0));
                }
                Key::Right | Key::L => {
                    mgr.move_graphic(gid, 1, (1, 0));
                }
                Key::Tab => {
                    mbox_layer += 1;
                    if !mbox_created {
                        if let  Some(mbid) = mgr.add_graphic(
                            build_mbox(60, 20, "La ku ka ra cza ga wi ga ba ga da da da ja nie".to_string(),
                            "lastBuildDate: Tue, 12 Apr 2022 07:52:44 GMT
* generator: Oddmuse
* copyright: This work is licensed to you under version 2 of the GNU General Public License. Alternatively, you may choose to receive this work under
 any other license that grants the right to use, copy, modify, and distribute the work, as long as that license imposes the restriction that derivative
 works have to grant the same rights and impose the same restriction. For example, you may choose to receive this work under the GNU Free
 Documentation License, the CreativeCommons ShareAlike License, the XEmacs manual license, or similar licenses.
* license: https://creativecommons.org/licenses/sa/1.0/
* license: https://www.gnu.org/copyleft/fdl.html
* license: https://www.gnu.org/copyleft/gpl.html".to_string()                        ),
                        mbox_layer,
                        (0, 0),
                    ){
                        mgr.set_graphic(mbid, 0, true);
                            mbox_created = true;
                            mbox_id = mbid;
                        }
                    }
                }
                Key::CtrlA => {
                    mgr.start_animation(gid, 0);
                }
                Key::CtrlB => {
                    mgr.stop_animation(gid);
                }
                Key::Insert => {
                    mgr.set_graphic(gid, 2, false);
                }
                Key::Delete => {}
                Key::Home => {
                    mgr.set_glyph(gid, Glyph::default(), 1, 1);
                    mgr.move_graphic(gid, 1, (0, 0));
                    mgr.empty_frame(gid);
                }
                Key::Escape | Key::Q | Key::CtrlQ => {
                    break;
                }
                Key::Enter => {
                    if !mbox_created {
                        mbox_layer += 1;
                        if let Some(tid) = mgr.add_graphic(
                            build_mbox(
                                40,
                                1,
                                "Please enter title and hit Enter".to_string(),
                                String::new(),
                            ),
                            mbox_layer,
                            (cols as isize / 2 - 20, rows as isize / 2),
                        ) {
                            mgr.set_graphic(tid, 0, true);
                            let line = mgr.read_line();
                            if let Some(mbid) = mgr.add_graphic(
                                build_mbox(
                                    60,
                                    20,
                                    line,
                                    "Hit Enter to type content in.".to_string(),
                                ),
                                mbox_layer,
                                (0, 0),
                            ) {
                                mgr.delete_graphic(tid);
                                mbox_id = mbid;
                                mgr.set_graphic(mbid, 0, true);
                                mbox_created = true;
                            }
                        }
                    } else {
                        let mut x = 1;
                        let mut y = 1;
                        mbox_created = false;
                        let mut rev = Glyph::default();
                        rev.set_reverse(true);
                        for i in 1..31 {
                            mgr.set_glyph(mbox_id, rev, i, 1);
                        }
                        loop {
                            if let Some(c) = mgr.read_char() {
                                if c == '\t' {
                                    break;
                                }
                                if c as u8 == 8 || c as u8 == 127 {
                                    x -= 1;
                                    if x == 0 {
                                        if y > 1 {
                                            y -= 1;
                                            x = 58;
                                        } else {
                                            x = 1;
                                        }
                                    }
                                    mgr.set_glyph(mbox_id, Glyph::default(), x, y);
                                    continue;
                                }
                                if c == '\n' {
                                    break;
                                }

                                mgr.set_glyph(mbox_id, Glyph::default_with_char(c), x, y);
                                x += 1;
                                if x > 58 {
                                    x = 1;
                                    y += 1;
                                }
                            }
                        }
                    }
                }
                _ => {
                    println!("You pressed: {:?}", key);
                }
            }
        }
    }
    mgr.terminate();
}

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.