1 #include <cstdlib>
2 #include <clocale>
3 #include <unistd.h>
4 #include <memory>
5 #include <ncpp/NotCurses.hh>
6 #include <ncpp/Plane.hh>
7 
8 using namespace ncpp;
9 
10 constexpr auto DELAY = 1;
11 
12 // dump two wide glyphs, then create a new plane and drop it atop them
13 
stomper(NotCurses & nc,std::shared_ptr<Plane> & nn)14 auto stomper(NotCurses& nc, std::shared_ptr<Plane>& nn) -> int {
15   // should knock out both wide glyphs
16   nn->move(0, 1);
17   nc.render();
18   sleep(DELAY);
19 
20   // first wide glyph gone, second present
21   nn->move(1, 0);
22   nc.render();
23   sleep(DELAY);
24 
25   // second wide glyph gone, first present
26   nn->move(2, 2);
27   nc.render();
28   sleep(DELAY);
29 
30   nn->move(4, 0);
31   nc.render();
32   sleep(DELAY);
33 
34   nn->move(5, 1);
35   nc.render();
36   sleep(DELAY);
37 
38   nn->move(6, 2);
39   nc.render();
40   sleep(DELAY);
41 
42   return 0;
43 }
44 
main()45 auto main() -> int {
46   setlocale(LC_ALL, "");
47   notcurses_options nopts{};
48   nopts.flags = NCOPTION_INHIBIT_SETLOCALE;
49   NotCurses nc(nopts);
50   std::shared_ptr<Plane> n(nc.get_stdplane());
51 
52   {
53     // first, a 2x1 with "AB"
54     auto nn = std::make_shared<Plane>(1, 2, 1, 16);
55     nn->set_fg_rgb8(0xc0, 0x80, 0xc0);
56     nn->set_bg_rgb8(0x20, 0x00, 0x20);
57     nn->set_base("", 0, NCCHANNELS_INITIALIZER(0xc0, 0x80, 0xc0, 0x20, 0, 0x20));
58     nn->putstr("AB");
59 
60     n->set_fg_rgb8(0x80, 0xc0, 0x80);
61     n->set_bg_rgb8(0x00, 0x40, 0x00);
62     n->putstr("\xe5\xbd\xa2\xe5\x85\xa8");
63     n->putstr(1, 0, "\xe5\xbd\xa2\xe5\x85\xa8");
64     n->putstr(2, 0, "\xe5\xbd\xa2\xe5\x85\xa8");
65     n->putstr(3, 0, "\xe5\xbd\xa2\xe5\x85\xa8");
66     n->putstr(4, 0, "abcdef");
67     n->putstr(5, 0, "abcdef");
68     n->putstr(6, 0, "abcdef");
69     n->putstr(7, 0, "abcdef");
70     nc.render();
71     sleep(1);
72 
73     stomper(nc, nn);
74     if(nn->putstr(0, 0, "\xe5\xbd\xa1") <= 0){
75       return EXIT_FAILURE;
76     }
77     stomper(nc, nn);
78     nn->erase();
79     if(nn->putstr(0, 0, "r") <= 0){
80       return EXIT_FAILURE;
81     }
82     stomper(nc, nn);
83   }
84 
85   // now a 1x1 "*"
86   auto nn = std::make_shared<Plane>(1, 1, 1, 16);
87   if(nn->putstr(0, 0, "r") <= 0){
88     return EXIT_FAILURE;
89   }
90   stomper(nc, nn);
91   return EXIT_SUCCESS;
92 }
93