Fixed ordering of the application of the styles
[rodin/chimara.git] / tests / gridtest.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <assert.h>
5 #include <libchimara/glk.h>
6
7 void glk_main(void)
8 {
9     event_t ev;
10     winid_t mainwin = glk_window_open(0, 0, 0, wintype_TextGrid, 0);
11     if(!mainwin)
12         return;
13     
14     glk_set_window(mainwin);
15     glui32 width, height, x, y;
16     glk_window_get_size(mainwin, &width, &height);
17     if(height < 4 || width < 22)
18     {
19         glk_put_string("Window not big enough");
20         glk_exit();
21     }
22     x = width / 2 - 10;
23     y = height / 2;
24     
25     char *buffer = calloc(256, sizeof(char));
26     assert(buffer);
27     
28     glk_window_move_cursor(mainwin, x, y - 1);
29     glk_put_string("Enter text, or 'quit'");
30     glk_window_move_cursor(mainwin, x, y);
31     glk_request_line_event(mainwin, buffer, 21, 0);
32     while(strncmp(buffer, "quit", 4)) 
33     {
34         glk_select(&ev);
35         if(ev.type == evtype_LineInput)
36         {
37                 glk_window_move_cursor(mainwin, x, y + 1);
38                 glk_put_string("                     ");
39                 glk_window_move_cursor(mainwin, x, y + 1);
40                 glk_put_buffer(buffer, ev.val1);
41                 glk_window_move_cursor(mainwin, x, y);
42                 glk_request_line_event(mainwin, buffer, 21, 0);
43         }
44     }
45     glk_cancel_line_event(mainwin, NULL);
46     glk_window_clear(mainwin);
47     free(buffer);
48 }