GLK: FROTZ: Added OS read line and character methods

This commit is contained in:
Paul Gilbert 2018-11-12 11:51:49 -08:00 committed by Paul Gilbert
parent 7d2406870e
commit ce7113b34a
4 changed files with 124 additions and 5 deletions

View File

@ -404,5 +404,95 @@ void GlkInterface::gos_cancel_pending_line() {
gos_linepending = 0;
}
zchar GlkInterface::os_read_key(int timeout, bool show_cursor) {
event_t ev;
winid_t win = gos_curwin ? gos_curwin : gos_lower;
if (gos_linepending)
gos_cancel_pending_line();
glk_request_char_event_uni(win);
if (timeout != 0)
glk_request_timer_events(timeout * 100);
while (!shouldQuit()) {
glk_select(&ev);
if (ev.type == evtype_Arrange) {
gos_update_height();
gos_update_width();
} else if (ev.type == evtype_Timer) {
glk_cancel_char_event(win);
glk_request_timer_events(0);
return ZC_TIME_OUT;
} else if (ev.type == evtype_CharInput)
break;
}
if (shouldQuit())
return 0;
glk_request_timer_events(0);
if (gos_upper && mach_status_ht < curr_status_ht)
reset_status_ht();
curr_status_ht = 0;
switch (ev.val1) {
case keycode_Escape: return ZC_ESCAPE;
case keycode_PageUp: return ZC_ARROW_MIN;
case keycode_PageDown: return ZC_ARROW_MAX;
case keycode_Left: return ZC_ARROW_LEFT;
case keycode_Right: return ZC_ARROW_RIGHT;
case keycode_Up: return ZC_ARROW_UP;
case keycode_Down: return ZC_ARROW_DOWN;
case keycode_Return: return ZC_RETURN;
case keycode_Delete: return ZC_BACKSPACE;
case keycode_Tab: return ZC_INDENT;
default:
return ev.val1;
}
}
zchar GlkInterface::os_read_line(int max, zchar *buf, int timeout, int width, int continued) {
event_t ev;
winid_t win = gos_curwin ? gos_curwin : gos_lower;
if (!continued && gos_linepending)
gos_cancel_pending_line();
if (!continued || !gos_linepending) {
glk_request_line_event_uni(win, buf, max, os_string_length(buf));
if (timeout != 0)
glk_request_timer_events(timeout * 100);
}
gos_linepending = 0;
while (!shouldQuit()) {
glk_select(&ev);
if (ev.type == evtype_Arrange) {
gos_update_height();
gos_update_width();
} else if (ev.type == evtype_Timer) {
gos_linewin = win;
gos_linepending = 1;
gos_linebuf = buf;
return ZC_TIME_OUT;
} else if (ev.type == evtype_LineInput) {
break;
}
}
if (shouldQuit())
return 0;
glk_request_timer_events(0);
buf[ev.val1] = '\0';
if (gos_upper && mach_status_ht < curr_status_ht)
reset_status_ht();
curr_status_ht = 0;
return ZC_RETURN;
}
} // End of namespace Scott
} // End of namespace Gargoyle

View File

@ -159,6 +159,24 @@ protected:
// Not implemented
return 0;
}
void os_scrollback_char(zchar z) {
// Not implemented
}
void os_scrollback_erase(int amount) {
// Not implemented
}
/**
* Waits for a keypress
*/
zchar os_read_key(int timeout, bool show_cursor);
/**
* Waits for the user to type an input line
*/
zchar os_read_line(int max, zchar *buf, int timeout, int width, int continued);
public:
/**
* Constructor

View File

@ -308,6 +308,16 @@ private:
* @{
*/
/**
* Waits for the user to type an input line
*/
zchar console_read_input(int max, zchar *buf, zword timeout, bool continued);
/**
* Waits for a keypress
*/
zchar console_read_key(zword timeout);
/**
* Write a single character to the scrollback buffer.
*

View File

@ -25,12 +25,13 @@
namespace Gargoyle {
namespace Frotz {
// TODO: Implement method stubs
static void os_scrollback_char(zchar) {}
static void os_scrollback_erase(zword) {}
static zchar console_read_key(zword) { return 0; }
static zchar console_read_input(uint, zchar *, uint, bool) { return 0; }
zchar Processor::console_read_input(int max, zchar *buf, zword timeout, bool continued) {
return os_read_line(max, buf, timeout, max, continued);
}
zchar Processor::console_read_key(zword timeout) {
return os_read_key(timeout, 0);
}
void Processor::scrollback_char(zchar c) {
if (c == ZC_INDENT)