X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=src%2Fgridtest.c;h=cec6004344bd8c74d32a158f996b2ca70145859d;hb=91214934fbcdfd363202a65c142194506604ff7b;hp=58ed6f698b346fe70746a9b7520c2fbcd5f1e2da;hpb=fac4f5bfb95b6e8e60b675beb325cfbcdfd2a4f1;p=projects%2Fchimara%2Fchimara.git diff --git a/src/gridtest.c b/src/gridtest.c index 58ed6f6..cec6004 100644 --- a/src/gridtest.c +++ b/src/gridtest.c @@ -1,34 +1,84 @@ -#include "stdio.h" +#include +#include +#include +#include #include "glk.h" void glk_main(void) { event_t ev; - winid_t mainwin = glk_window_open(0, 0, 0, wintype_TextBuffer, 0); + winid_t mainwin = glk_window_open(0, 0, 0, wintype_TextGrid, 0); if(!mainwin) return; - winid_t subwin = glk_window_open(mainwin, winmethod_Right | winmethod_Proportional, 50, wintype_TextBuffer, 1); - printf("created new window\n"); glk_set_window(mainwin); glk_put_string("Philip en Marijn zijn vet goed.\n"); - glk_set_window(subwin); glk_put_string("A veeeeeeeeeeeeeeeeeeeeeeeeeeeery looooooooooooooooooooooooong striiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiing.\n"); - - guint32 width, height; + int count; + for(count = 0; count < 30; count++) + glk_put_string("I want to write past the end of this text buffer! "); + + glui32 width, height; glk_window_get_size(mainwin, &width, &height); - printf("got window size\n"); - fprintf(stderr, "\nWidth: %d\nHeight: %d\n", width, height); + fprintf(stderr, "\nWidth: %d\nHeight: %d\nPress a key in the window, not in the terminal.\n", width, height); + glk_request_char_event(mainwin); + while(1) { + glk_select(&ev); + if(ev.type == evtype_CharInput) + break; + } + glk_window_move_cursor(mainwin, 15, 15); + glk_put_string(". . "); + glk_window_move_cursor(mainwin, 15, 16); + glk_put_string(" . ."); + glk_window_move_cursor(mainwin, 15, 17); + glk_put_string(". . "); + glk_window_move_cursor(mainwin, 15, 18); + glk_put_string(" . ."); + fprintf(stderr, "Cursor location test.\nPress another key.\n"); glk_request_char_event(mainwin); - //while(1) { + while(1) { + glk_select(&ev); + if(ev.type == evtype_CharInput) + break; + } + + char *buffer = calloc(256, sizeof(char)); + assert(buffer); + + fprintf(stderr, "Line input field until end of line\n"); + glk_window_move_cursor(mainwin, 10, 20); + glk_request_line_event(mainwin, buffer, 256, 0); + while(1) { glk_select(&ev); - if(ev.type == evtype_CharInput) { - glk_window_get_size(mainwin, &width, &height); - fprintf(stderr, "\nWidth: %d\nHeight: %d\n", width, height); - } - //} - glk_window_close(subwin, NULL); - printf("closed window\n"); + if(ev.type == evtype_LineInput) + break; + } + + fprintf(stderr, "Now edit your previous line input\n"); + glk_window_move_cursor(mainwin, 10, 22); + glk_request_line_event(mainwin, buffer, 256, strlen(buffer)); + while(1) { + glk_select(&ev); + if(ev.type == evtype_LineInput) + break; + } + + char *text = calloc(ev.val1 + 1, sizeof(char)); + assert(text); + strncpy(text, buffer, ev.val1); + text[ev.val1] = '\0'; + fprintf(stderr, "Your string was: '%s'.\nPress another key to clear the window and exit.\n", text); + free(text); + glk_request_char_event(mainwin); + while(1) { + glk_select(&ev); + if(ev.type == evtype_CharInput) + break; + } + + glk_window_clear(mainwin); + free(buffer); }