appcui 0.4.8

A feature-rich and cross-platform TUI/CUI framework for Rust, enabling modern terminal-based applications on Windows, Linux, and macOS. Includes built-in UI components like buttons, menus, list views, tree views, checkboxes, and more. Perfect for building fast and interactive CLI tools and text-based interfaces.
Documentation
1
2
3
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
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
use crate::prelude::*;

#[test]
fn check_keyboard() {
    let script = "
        Paint.Enable(false)
        Paint('Initial state')
        CheckHash(0xDD19FB5257AF4C39)
        Key.Pressed(Right)
        Paint('2')
        CheckHash(0x9072EEB8678E62E)
        Key.Pressed(Right,3)
        Paint('3')
        CheckHash(0xCDCA2B1AA0D0ED78)
        Key.Pressed(Right,2)
        Paint('4')
        CheckHash(0x8D74117DDF999E46)
        Key.Pressed(Right,100)
        Paint('4 (already at margin)')
        CheckHash(0x8D74117DDF999E46)
        Key.Pressed(Left,3)
        Paint('5')
        CheckHash(0x7AEB60F729867DDE)
        Key.Pressed(Left,2)
        Paint('Back to initial state')
        CheckHash(0xDD19FB5257AF4C39)
        Key.Pressed(Down,2)
        Paint('6')
        CheckHash(0x33CCFDF3A125050)
        Key.Pressed(Down,4)
        Paint('7')
        CheckHash(0xAE6E99E7D14B45D0)
        Key.Pressed(Up,2)
        Paint('8')
        CheckHash(0x17A3D40C19A04DA8)
        Key.Pressed(Shift+Up)
        Paint('Back to initial state')
        CheckHash(0xDD19FB5257AF4C39)
        Key.Pressed(Shift+Right)
        Paint('Right top margin')
        CheckHash(0x8D74117DDF999E46)
        Key.Pressed(Shift+Down)
        Paint('9')
        CheckHash(0x94C6FF9EDFF78BD0)
        Key.Pressed(Shift+Left)
        Paint('10')
        CheckHash(0xAE6E99E7D14B45D0)
        Key.Pressed(Home)
        Paint('Back to initial state')
        CheckHash(0xDD19FB5257AF4C39)
        Key.Pressed(End)
        Paint('11')
        CheckHash(0x94C6FF9EDFF78BD0)
";
    let mut a = App::debug(60, 10, script).build().unwrap();
    let mut w = window!("Title,a:c,w:40,h:8");
    let mut c = Canvas::new(Size::new(20, 10), layout!("x:1,y:1,w:15,h:4"), canvas::Flags::None);
    let s = c.drawing_surface_mut();
    s.write_string(
        0,
        0,
        "         11111111112",
        CharAttribute::with_color(Color::White, Color::DarkRed),
        false,
    );
    s.write_string(
        0,
        1,
        "12345678901234567890",
        CharAttribute::with_color(Color::White, Color::DarkRed),
        false,
    );
    s.fill_horizontal_line(0, 9, 20, Character::new('=', Color::White, Color::DarkRed, CharFlags::None));
    for i in 2..10 {
        s.write_char(
            0,
            i,
            Character::new(((i + 48) as u8) as char, Color::White, Color::DarkRed, CharFlags::None),
        );
        s.write_char(
            7,
            i,
            Character::new(((i + 48) as u8) as char, Color::White, Color::DarkRed, CharFlags::None),
        );
        s.write_char(
            14,
            i,
            Character::new(((i + 48) as u8) as char, Color::White, Color::DarkRed, CharFlags::None),
        );
        s.write_char(
            19,
            i,
            Character::new(((i + 48) as u8) as char, Color::White, Color::DarkRed, CharFlags::None),
        );
    }
    w.add(c);
    a.add_window(w);
    a.run();
}

#[test]
fn check_keyboard_2() {
    let script = "
        Paint.Enable(false)
        Paint('Initial state')
        CheckHash(0xECD64DA8EC4ABB22)
        Key.Pressed(Ctrl+Right)
        Paint('2')
        CheckHash(0x2F6B2D52610BE94A)
        Key.Pressed(Ctrl+Right,2)
        Paint('3')
        Key.Pressed(Ctrl+Right,3)
        Paint('4')
        CheckHash(0x91FA33F25664115F)
        Key.Pressed(Ctrl+Left)
        Paint('5')
        CheckHash(0x7939B4BF72AAB9CA)
        Key.Pressed(Ctrl+Left,2)
        Paint('6')
        Key.Pressed(Ctrl+Left,1)
        Paint('Back Initial state')
        CheckHash(0xECD64DA8EC4ABB22)
        Key.Pressed(Ctrl+Down)
        Paint('7')
        CheckHash(0x8C4B46EB47038066)
        Key.Pressed(Ctrl+Down)
        Paint('8')
        CheckHash(0x88133037D51CD5B5)
        Key.Pressed(Ctrl+Down)
        Paint('9')
        CheckHash(0x7D07BFDFFDFE8F0F)
        Key.Pressed(Ctrl+Up,2)
        Paint('10')
        CheckHash(0x6B582357BD9EB6F5)
        Key.Pressed(Ctrl+Up)
        Paint('Back Initial state')
        CheckHash(0xECD64DA8EC4ABB22)
";
    let mut a = App::debug(60, 10, script).build().unwrap();
    let mut w = window!("Title,a:c,w:40,h:8");
    let mut c = Canvas::new(Size::new(20, 10), layout!("x:1,y:1,w:4,h:3"), canvas::Flags::None);
    let s = c.drawing_surface_mut();
    s.write_string(
        0,
        0,
        "         11111111112",
        CharAttribute::with_color(Color::White, Color::DarkRed),
        false,
    );
    s.write_string(
        0,
        1,
        "12345678901234567890",
        CharAttribute::with_color(Color::White, Color::DarkRed),
        false,
    );
    s.fill_horizontal_line(0, 9, 20, Character::new('=', Color::White, Color::DarkRed, CharFlags::None));
    for i in 2..10 {
        s.write_char(
            0,
            i,
            Character::new(((i + 48) as u8) as char, Color::White, Color::DarkRed, CharFlags::None),
        );
        s.write_char(
            7,
            i,
            Character::new(((i + 48) as u8) as char, Color::White, Color::DarkRed, CharFlags::None),
        );
        s.write_char(
            14,
            i,
            Character::new(((i + 48) as u8) as char, Color::White, Color::DarkRed, CharFlags::None),
        );
        s.write_char(
            19,
            i,
            Character::new(((i + 48) as u8) as char, Color::White, Color::DarkRed, CharFlags::None),
        );
    }
    w.add(c);
    a.add_window(w);
    a.run();
}

#[test]
fn check_background_char() {
    let script = "
        Paint.Enable(false)
        Paint('Initial state')
        CheckHash(0x209459BC48B6383C)
";
    let mut a = App::debug(60, 10, script).build().unwrap();
    let mut w = window!("Title,a:c,w:40,h:8");
    let mut c = Canvas::new(Size::new(2, 2), layout!("x:1,y:1,w:15,h:4"), canvas::Flags::None);
    let s = c.drawing_surface_mut();
    s.clear(Character::new('X', Color::Yellow, Color::DarkRed, CharFlags::None));
    c.set_background(Character::new('.', Color::White, Color::Black, CharFlags::None));
    w.add(c);
    a.add_window(w);
    a.run();
}

#[test]
fn check_mouse_on_scrollbars() {
    let script = "
        Paint.Enable(false)
        Paint('Initial state')
        CheckHash(0x5482fcc49857230a)
        Key.Pressed(Tab)
        Paint('Canvas focused')
        CheckHash(0x688773f2f69a827b)
        Key.Pressed(Right,5)
        Paint('bottom scrollbar moved with keys')
        CheckHash(0x824c6aac59e00fc0)
        Key.Pressed(Down,3)
        Paint('vertical scrollbar moved with keys')
        CheckHash(0x65f048227a2f5326)
        Key.Pressed(Right,20)
        Key.Pressed(Down,20)
        Paint('Scrollbars on bottom-right')
        CheckHash(0x2001b1a95626920f)
        Mouse.Move(49,7)
        Mouse.Click(49,7,left)
        Mouse.Move(31,13)
        Mouse.Click(31,13,left)
        Mouse.Move(44,16)
        Paint('scroll bars moved with mouse')
        CheckHash(0x58c2e5881e384722)
        Mouse.Move(31,13)
        Mouse.Click(31,13,left)
        Mouse.Click(31,13,left)
        Mouse.Click(31,13,left)
        Mouse.Click(31,13,left)
        Mouse.Click(31,13,left)
        Mouse.Click(31,13,left)
        Mouse.Click(31,13,left)
        Mouse.Click(31,13,left)
        Paint('move even more through left')
        CheckHash(0x94a715f8bdb37e60)
        Mouse.Move(49,7)
        Mouse.Click(49,7,left)
        Mouse.Click(49,7,left)
        Mouse.Click(49,7,left)
        Mouse.Click(49,7,left)
        Mouse.Click(49,7,left)
        Mouse.Click(49,7,left)
        Paint('move to top')
        CheckHash(0xd602abd0107382d7)
        Mouse.Move(31,13)
        Mouse.Click(31,13,left)
        Mouse.Click(31,13,left)
        Mouse.Click(31,13,left)
        Mouse.Click(31,13,left)
        Mouse.Click(31,13,left)
        Paint('Move to left')
        CheckHash(0xda9461e4fdcc6780)
        Mouse.Move(32,13)
        Paint('Mouse hover over bottom scrollbar')
        CheckHash(0xa8a93bbcfdf66b2d)
        Mouse.Hold(32,13,left)
        Mouse.Move(41,13)
        Mouse.Release(41,13,left)
        Paint('Scroll moved via drag')
        CheckHash(0x4dc5e7857a64e487)
        Mouse.Move(49,8)
        Mouse.Hold(49,8,left)
        Mouse.Move(49,10)
        Mouse.Release(49,10,left)
        Paint('Scroll move via drag (vertical)')
        CheckHash(0xd70e2e289ca96e54)
        Mouse.Move(48,13)
        Paint('Hover over window with scroll enabled')
        CheckHash(0x51e83736974739af)
        Mouse.Move(40,9)
        Mouse.Hold(40,9,left)
        Mouse.Move(36,11)
        Mouse.Release(36,11,left)
        Paint('Move via direct drag from surface')
        CheckHash(0xaf34cf74037cd71e)
        Key.Pressed(Tab)
        Mouse.Move(49,13)
        Paint('Hover over window (but with focus on button)')
        CheckHash(0x4e8b05d573a197ab)    
";
    let text: &str = r"012345678901234567890123456789
/- Some Text To Test -\
\=====================/
| () () () () () () ()| => 123
|---------------------|
\=-=-=-=-=-=-=-=-=-=-=/
 \-=-=-=-=-=-=-=-=-=-/
  \-=-=-=-=-=-=-=-=-/
   \===============/
    \ooooooooooooo/ => 1234567
";
    let mut a = App::debug(60, 20, script).build().unwrap();
    let mut w = window!("Title,a:c,w:40,h:8,flags:Sizeable");
    let mut c = Canvas::new(Size::new(30, 10), layout!("l:20,t:0,r:0,b:0"), canvas::Flags::ScrollBars);
    let s = c.drawing_surface_mut();
    s.write_string(0, 0, text, CharAttribute::with_color(Color::White, Color::Black), true);
    w.add(c);
    w.add(button!("Test,l:1,t:1,w:10")); // removed a:tl,
    a.add_window(w);
    a.run();
}

#[test]
fn check_mouse_on_scrollbars_resize() {
    let script = "
    Paint.Enable(false)
    Paint('Initial State')
    CheckHash(0x5482fcc49857230a)
    Key.Pressed(Tab)
    Paint('Focus on Canvas')
    CheckHash(0x966ee395984d4a52)
    Mouse.Move(48,13)
    Mouse.Drag(48,13,53,18)
    Mouse.Move(56,18)
    Paint('Right scroll bar disabled')
    CheckHash(0x16c9777fb66b6367)
    Mouse.Move(53,18)
    Mouse.Drag(53,18,58,18)
    Mouse.Move(34,6)
    Mouse.Drag(34,6,27,1)
    Mouse.Move(50,13)
    Mouse.Drag(50,13,58,13)
    Paint('Bottom scroll bar disabled')
    CheckHash(0x8f9d0e2f5da48de2)
    Mouse.Move(41,13)
    Mouse.Click(41,13,left)
    Mouse.Move(31,13)
    Mouse.Click(31,13,left)
    Mouse.Move(52,13)
    Mouse.Click(52,13,left)
    Mouse.Move(58,11)
    Mouse.Click(58,11,left)
    Mouse.Move(58,7)
    Mouse.Click(58,7,left)
    Mouse.Move(58,4)
    Mouse.Click(58,4,left)
    Mouse.Move(28,13)
    Mouse.Click(28,13,left)
    Paint('Nothing hapens after click on scrollbars')
    CheckHash(0x41f0bfa8a7682c72)
    Mouse.Move(58,13)
    Mouse.Drag(58,13,38,7)
    Mouse.Move(41,10)
    Paint('right scrollbar is hidden')
    CheckHash(0xc5fbc8e124456a4c)
    Mouse.Move(38,7)
    Mouse.Drag(38,7,38,9)
    Mouse.Move(39,12)
    Paint('right scrollbar visible')
    CheckHash(0xc7827de70d4271d4)
    Mouse.Move(37,9)
    Mouse.Drag(37,9,31,9)
    Paint('bottom scollbar hidden')
    CheckHash(0x78790845f2cd8e40)        
";
    let text: &str = r"012345678901234567890123456789
/- Some Text To Test -\
\=====================/
| () () () () () () ()| => 123
|---------------------|
\=-=-=-=-=-=-=-=-=-=-=/
 \-=-=-=-=-=-=-=-=-=-/
  \-=-=-=-=-=-=-=-=-/
   \===============/
    \ooooooooooooo/ => 1234567
";
    let mut a = App::debug(60, 20, script).build().unwrap();
    let mut w = window!("Title,a:c,w:40,h:8,flags:Sizeable");
    let mut c = Canvas::new(Size::new(30, 10), layout!("l:20,t:0,r:0,b:0"), canvas::Flags::ScrollBars);
    c.set_components_toolbar_margins(2, 1);
    let s = c.drawing_surface_mut();
    s.write_string(0, 0, text, CharAttribute::with_color(Color::White, Color::Black), true);
    w.add(c);
    w.add(button!("Test,l:1,t:1,w:10")); // removed a:tl,
    a.add_window(w);
    a.run();
}

#[test]
fn check_macro_init_1() {
    let script = "
    Paint.Enable(false)
    Paint('Initial State')
    CheckHash(0x5482fcc49857230a)
    Key.Pressed(Tab)
    Paint('Focus')
    CheckHash(0x966EE395984D4A52)
";
    let text: &str = r"012345678901234567890123456789
/- Some Text To Test -\
\=====================/
| () () () () () () ()| => 123
|---------------------|
\=-=-=-=-=-=-=-=-=-=-=/
 \-=-=-=-=-=-=-=-=-=-/
  \-=-=-=-=-=-=-=-=-/
   \===============/
    \ooooooooooooo/ => 1234567
";
    let mut a = App::debug(60, 20, script).build().unwrap();
    let mut w = window!("Title,a:c,w:40,h:8,flags:Sizeable");
    let mut c = canvas!("'30 x 10',l:20,t:0,r:0,b:0,flags=Scrollbars,lsm=2,tsm=1");
    let s = c.drawing_surface_mut();
    s.write_string(0, 0, text, CharAttribute::with_color(Color::White, Color::Black), true);
    w.add(c);
    w.add(button!("Test,l:1,t:1,w:10")); // removed a:tl,
    a.add_window(w);
    a.run();
}

#[test]
fn check_macro_init_2() {
    let script = "
    Paint.Enable(false)
    Paint('Initial State')
    CheckHash(0x30DC80BF114CEFBE)     
    Key.Pressed(Tab)
    Paint('With focus')
    CheckHash(0x4709CADE1C0994D3)
";
    let mut a = App::debug(60, 20, script).build().unwrap();
    let mut w = window!("Title,a:c,w:40,h:8,flags:Sizeable");
    let mut c = canvas!("'4 x 2',l:20,t:0,r:0,b:0,flags=Scrollbars,lsm=3,tsm=1,back={X,fore:Green,Back:Yellow}");
    let s = c.drawing_surface_mut();
    s.clear(char!("<->,r,black"));
    w.add(c);
    w.add(button!("Test,l:1,t:1,w:10")); // removed a:tl,
    a.add_window(w);
    a.run();
}

#[test]
fn check_pageup_pagedown() {
    let text = r"--- From Wiki ----
Rust is a multi-paradigm, general-purpose 
programming language that emphasizes performance, 
type safety, and concurrency. It enforces memory 
safety—meaning that all references point to valid 
memory—without a garbage collector. To 
simultaneously enforce memory safety and prevent 
data races, its 'borrow checker' tracks the object 
lifetime of all references in a program during 
compilation. Rust was influenced by ideas from 
functional programming, including immutability, 
higher-order functions, and algebraic data types. 
It is popular for systems programming.

From: https://en.wikipedia.org/wiki/Rust_(programming_language)
";
    let script = "
Paint.Enable(false)
Resize(60,20)
Paint('Initial state')
CheckHash(0xc9196f52d863ff88)
Key.Pressed(PageDown)
Paint('Page down (first line: simultabeously ...)')
CheckHash(0x27f6cbecd53c03f8)
Key.Pressed(PageDown)
Paint('Page Down (first line: compilation. ....)')
CheckHash(0xe1527c32d87dfd3b)
Key.Pressed(PageDown)
Paint('Another page down (nothing changes)')
CheckHash(0xe1527c32d87dfd3b)
Key.Pressed(PageUp)
Paint('Page Up (first line: type safety, and ...)')
CheckHash(0x9e29d2f1826c129)
Key.Pressed(PageUp)
Paint('Back to the initial state')
CheckHash(0xc9196f52d863ff88)
";
    let mut a = App::debug(60, 20, script).build().unwrap();
    let mut w = window!("Title,a:c,w:40,h:8,flags:Sizeable");
    let mut c = canvas!("'60x15',d:f,flags=ScrollBars,lsm:3,tsm:1");
    let s = c.drawing_surface_mut();
    s.write_string(0, 0, text, CharAttribute::with_color(Color::White, Color::Black), true);
    w.add(c);
    a.add_window(w);
    a.run();
}

#[test]
fn check_resize_surface() {
    let script = "
        Paint.Enable(false)
        Paint('Initial state')
        CheckHash(0x98D5E1882902B363)
        Key.Pressed(Enter)
        Paint('Resized')
        CheckHash(0xE8ACC85E3F652EA2)
    ";
    const TEXT: &str = r"--- From Wiki ----
    Rust is a multi-paradigm, general-purpose 
    programming language that emphasizes performance, 
    type safety, and concurrency. It enforces memory 
    safety—meaning that all references point to valid 
    memory—without a garbage collector. To 
    simultaneously enforce memory safety and prevent 
    data races, its 'borrow checker' tracks the object 
    lifetime of all references in a program during 
    compilation. Rust was influenced by ideas from 
    functional programming, including immutability, 
    higher-order functions, and algebraic data types. 
    It is popular for systems programming.
    
    From: https://en.wikipedia.org/wiki/Rust_(programming_language)
    ";

    #[Window(events = ButtonEvents, internal: true)]
    struct MyWin {
        viewer: Handle<Canvas>,
    }

    impl MyWin {
        fn new() -> Self {
            let mut win = MyWin {
                base: window!("'My Win',a:c,w:40,h:16"),
                viewer: Handle::None,
            };
            let mut c = Canvas::new(Size::new(6, 3), layout!("l:15,t:0,b:0,r:0"), canvas::Flags::ScrollBars);
            let s = c.drawing_surface_mut();
            s.write_string(0, 0, TEXT, CharAttribute::with_color(Color::White, Color::Black), true);
            win.viewer = win.add(c);
            win.add(button!("Test,l:1,t:1,w:10")); // removed: a:tl,
            win
        }
    }
    impl ButtonEvents for MyWin {
        fn on_pressed(&mut self, _handle: Handle<Button>) -> EventProcessStatus {
            let h = self.viewer;
            if let Some(canvas) = self.control_mut(h) {
                canvas.resize_surface(Size::new(60, 15));
                canvas
                    .drawing_surface_mut()
                    .write_string(0, 0, TEXT, CharAttribute::with_color(Color::White, Color::Black), true);
            }
            EventProcessStatus::Processed
        }
    }

    let mut a = App::debug(60, 20, script).build().unwrap();
    a.add_window(MyWin::new());
    a.run();
}

#[test]
fn check_mouse_wheel() {
    let script = "
        Paint.Enable(false)
        Paint('1. Initial state')
        CheckHash(0x479AB05739A30F31)
        Mouse.Wheel(25,10,down,1)
        Paint('2. Move scrollbar down')
        CheckHash(0x771A5BA8169E8B8)
        Mouse.Wheel(25,10,right,3)
        Paint('3. Move scrollbar right')
        CheckHash(0x6E43010B3FDC45D2)
        Mouse.Wheel(25,10,down,5)
        Paint('4. Move scrollbar down (again)')
        CheckHash(0x72E84695E5A9938)
        Mouse.Wheel(25,10,right,6)
        Paint('5. Move scrollbar right')
        CheckHash(0x39AB1CFAC81B3418)
        Mouse.Wheel(25,10,up,2)
        Paint('6. Move scrollbar up')
        CheckHash(0xC6AC6E97FD8AD032)
        Mouse.Wheel(25,10,left,8)
        Paint('7. Move scrollbar left')
        CheckHash(0x1FD93707DFAA63B6)
        Mouse.DoubleClick(25,10,left)
        Paint('8. Double click (nothing happens - same hash as stept 7)')
        CheckHash(0x1FD93707DFAA63B6)
    ";
    const TEXT: &str = r"--- From Wiki ----
    Rust is a multi-paradigm, general-purpose 
    programming language that emphasizes performance, 
    type safety, and concurrency. It enforces memory 
    safety—meaning that all references point to valid 
    memory—without a garbage collector. To 
    simultaneously enforce memory safety and prevent 
    data races, its 'borrow checker' tracks the object 
    lifetime of all references in a program during 
    compilation. Rust was influenced by ideas from 
    functional programming, including immutability, 
    higher-order functions, and algebraic data types. 
    It is popular for systems programming.
    
    From: https://en.wikipedia.org/wiki/Rust_(programming_language)
    ";

    let mut a = App::debug(60, 20, script).build().unwrap();
    let mut w = window!("Title,a:c,w:40,h:8");
    let mut c = canvas!("'60x15',d:f,flags=ScrollBars,lsm:3,tsm:1");
    c.clear_background();
    let s = c.drawing_surface_mut();
    s.write_string(0, 0, TEXT, CharAttribute::with_color(Color::White, Color::Black), true);
    w.add(c);
    a.add_window(w);
    a.run();
}

#[cfg(feature = "TRUE_COLORS")]
#[test]
fn check_true_colors_rendering() {
    let script = "
        Paint.Enable(false)
        Paint('1. Initial state')
        CheckHash(0xBF4312A1691D7AD8)
    ";
    let mut a = App::debug(70, 20, script).build().unwrap();
    let mut w = window!("Title,d:f");
    let mut c = canvas!("'68x15',d:f,flags=ScrollBars,lsm:3,tsm:1");
    c.clear_background();
    let s = c.drawing_surface_mut();
    for i in 0..64 {
        let v = (i * 4) as u8;
        s.write_char(1 + i, 1, Character::new(' ', Color::Black, Color::RGB(v, 0, 0), CharFlags::None));
        s.write_char(1 + i, 3, Character::new(' ', Color::Black, Color::RGB(0, v, 0), CharFlags::None));
        s.write_char(1 + i, 5, Character::new(' ', Color::Black, Color::RGB(0, 0, v), CharFlags::None));
        s.write_char(1 + i, 7, Character::new(' ', Color::Black, Color::RGB(v, v, v), CharFlags::None));
    }
    w.add(c);
    a.add_window(w);
    a.run();
}

#[test]
fn check_char_flags() {
    let script = "
        Paint.Enable(false)
        Paint('1. Initial state')
        CheckHash(0xCF13E28C3D4AADA9)
    ";
    let mut a = App::debug(70, 20, script).build().unwrap();

    let mut win = window!("Title:'Character Formatting Demo',a:c,w:60,h:20,flags:Sizeable");
    let mut c = canvas!("'60x20',d:f,flags=ScrollBars,lsm:3,tsm:1");
    let s = c.drawing_surface_mut();

    let normal_attr = charattr!("white,black");
    let bold_attr = charattr!("white,black,attr:Bold");
    let italic_attr = charattr!("white,black,attr:Italic");
    let underline_attr = charattr!("white,black,attr:Underline");
    let bold_italic_attr = charattr!("white,black,attr:Bold+Italic");
    let bold_underline_attr = charattr!("white,black,attr:Bold+Underline");
    let italic_underline_attr = charattr!("white,black,attr:Italic+Underline");
    let all_formats_attr = charattr!("white,black,attr:Bold+Italic+Underline");

    s.write_string(3, 2, "This is normal text", normal_attr, false);
    s.write_string(3, 4, "This is bold text", bold_attr, false);
    s.write_string(3, 6, "This is italic text", italic_attr, false);
    s.write_string(3, 8, "This is underlined text", underline_attr, false);
    s.write_string(3, 10, "Bold + Italic", bold_italic_attr, false);
    s.write_string(3, 12, "Bold + Underline", bold_underline_attr, false);
    s.write_string(3, 14, "Italic + Underline", italic_underline_attr, false);
    s.write_string(3, 16, "All three formats (Bold + Italic + Underline)", all_formats_attr, false);

    win.add(c);
    a.add_window(win);
    a.run();
}

#[test]
fn check_colors_schema_false() {
    let script = "
        Paint.Enable(false)
        Paint('1. Initial state')
        CheckHash(0x29C1D764587643BE)
    ";
    let mut a = App::debug(70, 20, script).color_schema(false).build().unwrap();

    let mut win = window!("Title:'Colors',a:c,w:60,h:20,flags:Sizeable");
    let mut c = canvas!("'60x20',d:f,flags=ScrollBars,lsm:3,tsm:1");
    let s = c.drawing_surface_mut();
    for b in 0..16 {
        let back = Color::from_value(b).unwrap();
        for f in 0..16 {
            let fore = Color::from_value(f).unwrap();
            s.write_string(f * 2 + 2, b + 1, "()", CharAttribute::with_color(fore, back), false);
        }
    }

    win.add(c);
    a.add_window(win);
    a.run();
}


#[test]
fn check_colors_schema_true() {
    let script = "
        Paint.Enable(false)
        Paint('1. Initial state')
        CheckHash(0x29C1D764587643BE)
    ";
    let mut a = App::debug(70, 20, script).color_schema(true).build().unwrap();

    let mut win = window!("Title:'Colors',a:c,w:60,h:20,flags:Sizeable");
    let mut c = canvas!("'60x20',d:f,flags=ScrollBars,lsm:3,tsm:1");
    let s = c.drawing_surface_mut();
    for b in 0..16 {
        let back = Color::from_value(b).unwrap();
        for f in 0..16 {
            let fore = Color::from_value(f).unwrap();
            s.write_string(f * 2 + 2, b + 1, "()", CharAttribute::with_color(fore, back), false);
        }
    }

    win.add(c);
    a.add_window(win);
    a.run();
}