92d3d0cddafd1402aeef9f316371665258da4cd3
[rodin/chimara.git] / src / gridtest.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "glk.h"
4
5 void glk_main(void)
6 {
7     event_t ev;
8     winid_t mainwin = glk_window_open(0, 0, 0, wintype_TextGrid, 0);
9     if(!mainwin)
10         return;
11     
12     glk_set_window(mainwin);
13     glk_put_string("Philip en Marijn zijn vet goed.\n");
14     glk_put_string("A veeeeeeeeeeeeeeeeeeeeeeeeeeeery looooooooooooooooooooooooong striiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiing.\n");
15     
16     int count;
17     for(count = 0; count < 30; count++)
18         glk_put_string("I want to write past the end of this text buffer! ");
19     
20     guint32 width, height;
21     glk_window_get_size(mainwin, &width, &height);
22     fprintf(stderr, "\nWidth: %d\nHeight: %d\nPress a key in the window, not in the terminal.\n", width, height);
23     glk_request_char_event(mainwin);
24     while(1) {
25         glk_select(&ev);
26         if(ev.type == evtype_CharInput)
27             break;
28     }
29     
30     glk_window_move_cursor(mainwin, 15, 15);
31     glk_put_string(". . ");
32     glk_window_move_cursor(mainwin, 15, 16);
33     glk_put_string(" . .");
34     glk_window_move_cursor(mainwin, 15, 17);
35     glk_put_string(". . ");
36     glk_window_move_cursor(mainwin, 15, 18);
37     glk_put_string(" . .");
38     fprintf(stderr, "Cursor location test.\nPress another key.\n");
39     glk_request_char_event(mainwin);
40     while(1) {
41         glk_select(&ev);
42         if(ev.type == evtype_CharInput)
43             break;
44     }
45     
46     gchar *buffer = g_malloc0(256);
47     
48     fprintf(stderr, "Line input field until end of line\n");
49     glk_window_move_cursor(mainwin, 10, 20);
50     glk_request_line_event(mainwin, buffer, 256, 0);
51     while(1) {
52         glk_select(&ev);
53         if(ev.type == evtype_LineInput)
54             break;
55     }
56     
57     fprintf(stderr, "Now edit your previous line input\n");
58     glk_window_move_cursor(mainwin, 10, 22);
59     glk_request_line_event(mainwin, buffer, 256, strlen(buffer));
60     while(1) {
61         glk_select(&ev);
62         if(ev.type == evtype_LineInput)
63             break;
64     }
65     
66     fprintf(stderr, "Your string was: '%s'.\nPress another key to clear the window and exit.\n", buffer);
67     glk_request_char_event(mainwin);
68     while(1) {
69         glk_select(&ev);
70         if(ev.type == evtype_CharInput)
71             break;
72     }
73     
74     glk_window_clear(mainwin);
75     g_free(buffer);
76 }