return;
glk_set_window(mainwin);
- glk_put_string("Philip en Marijn zijn vet goed.\n");
- glk_put_string("A veeeeeeeeeeeeeeeeeeeeeeeeeeeery looooooooooooooooooooooooong striiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiing.\n");
-
- 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;
+ glui32 width, height, x, y;
glk_window_get_size(mainwin, &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) {
- glk_select(&ev);
- if(ev.type == evtype_CharInput)
- break;
+ if(height < 4 || width < 22)
+ {
+ glk_put_string("Window not big enough");
+ glk_exit();
}
+ x = width / 2 - 10;
+ y = height / 2;
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_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_window_move_cursor(mainwin, x, y - 1);
+ glk_put_string("Enter text, or 'quit'");
+ glk_window_move_cursor(mainwin, x, y);
+ glk_request_line_event(mainwin, buffer, 21, 0);
+ while(strncmp(buffer, "quit", 4))
+ {
glk_select(&ev);
if(ev.type == evtype_LineInput)
- break;
+ {
+ glk_window_move_cursor(mainwin, x, y + 1);
+ glk_put_string(" ");
+ glk_window_move_cursor(mainwin, x, y + 1);
+ glk_put_buffer(buffer, ev.val1);
+ glk_window_move_cursor(mainwin, x, y);
+ glk_request_line_event(mainwin, buffer, 21, 0);
+ }
}
-
- 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_cancel_line_event(mainwin, NULL);
glk_window_clear(mainwin);
free(buffer);
}