1 #include <errno.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <locale.h>
7 #include <notcurses/direct.h>
8 
9 // can we leave what was already on the screen there? (narrator: it seems not)
main(void)10 int main(void){
11   if(!setlocale(LC_ALL, "")){
12     fprintf(stderr, "Couldn't set locale\n");
13     return EXIT_FAILURE;
14   }
15   struct ncdirect* n; // see bug #391
16   if((n = ncdirect_core_init(NULL, NULL, 0)) == NULL){
17     return EXIT_FAILURE;
18   }
19   int dimy = ncdirect_dim_y(n);
20   int dimx = ncdirect_dim_x(n);
21   for(int y = 0 ; y < dimy ; ++y){
22     for(int x = 0 ; x < dimx ; ++x){
23       printf("X");
24     }
25   }
26   int ret = 0;
27   ret |= ncdirect_set_fg_rgb(n, 0xff8080);
28   ret |= ncdirect_on_styles(n, NCSTYLE_BOLD);
29   printf(" erp erp \n");
30   ret |= ncdirect_set_fg_rgb(n, 0x80ff80);
31   printf(" erp erp \n");
32   ret |= ncdirect_off_styles(n, NCSTYLE_BOLD);
33   printf(" erp erp \n");
34   ret |= ncdirect_set_fg_rgb(n, 0xff8080);
35   printf(" erp erp \n");
36   ret |= ncdirect_cursor_right(n, dimx / 2);
37   ret |= ncdirect_cursor_up(n, dimy / 2);
38   printf(" erperperp! \n");
39   unsigned y, x;
40   // FIXME try a push/pop
41   if(ncdirect_cursor_yx(n, &y, &x) == 0){
42     printf("\n\tRead cursor position: y: %d x: %d\n", y, x);
43     y += 2; // we just went down two lines
44     while(y > 3){
45       ret = -1;
46       unsigned newy;
47       if(ncdirect_cursor_yx(n, &newy, NULL)){
48         break;
49       }
50       if(newy != y){
51         fprintf(stderr, "Expected %d, got %d\n", y, newy);
52         break;
53       }
54       printf("\n\tRead cursor position: y: %d x: %d\n", newy, x);
55       y += 2;
56       const int up = 3;
57       if(ncdirect_cursor_up(n, up)){
58         break;
59       }
60       y -= up;
61       ret = 0;
62     }
63   }else{
64     ret = -1;
65   }
66   return ncdirect_stop(n) || ret ? EXIT_FAILURE : EXIT_SUCCESS;
67 }
68