Commit a5b0f07f authored by rswindell's avatar rswindell

Add sbbs_t::keybuf_space() and keybuf_level()

and JS console.keyboard_buffer_space() and keyboard_buffer_level()
... for tracking the number of character spaces used and available in the the (unget)keyboard input buffer.
parent 885eda66
......@@ -571,16 +571,18 @@ void sbbs_t::ungetkey(char ch, bool insert)
#if 0 /* this way breaks ansi_getxy() */
RingBufWrite(&inbuf,(uchar*)&ch,sizeof(uchar));
#else
if(insert) {
if(keybufbot == 0)
keybufbot = KEY_BUFSIZE - 1;
else
keybufbot--;
keybuf[keybufbot] = ch;
} else {
keybuf[keybuftop++]=ch;
if(keybuftop==KEY_BUFSIZE)
keybuftop=0;
if(keybuf_space()) {
if(insert) {
if(keybufbot == 0)
keybufbot = KEY_BUFSIZE - 1;
else
keybufbot--;
keybuf[keybufbot] = ch;
} else {
keybuf[keybuftop++]=ch;
if(keybuftop==KEY_BUFSIZE)
keybuftop=0;
}
}
#endif
}
......@@ -595,3 +597,15 @@ void sbbs_t::ungetstr(const char* str, bool insert)
for(i = 0; str[i] != '\0'; i++)
ungetkey(str[i], insert);
}
size_t sbbs_t::keybuf_space(void)
{
return sizeof(keybuf) - (keybuf_level() + 1);
}
size_t sbbs_t::keybuf_level(void)
{
if(keybufbot > keybuftop)
return (sizeof(keybuf) - keybufbot) + keybuftop;
return keybuftop - keybufbot;
}
......@@ -75,6 +75,8 @@ enum {
,CON_PROP_INBUF_SPACE
,CON_PROP_OUTBUF_LEVEL
,CON_PROP_OUTBUF_SPACE
,CON_PROP_KEYBUF_LEVEL
,CON_PROP_KEYBUF_SPACE
,CON_PROP_OUTPUT_RATE
};
......@@ -199,6 +201,12 @@ static JSBool js_console_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
case CON_PROP_OUTPUT_RATE:
val = sbbs->cur_output_rate;
break;
case CON_PROP_KEYBUF_LEVEL:
val = sbbs->keybuf_level();
break;
case CON_PROP_KEYBUF_SPACE:
val = sbbs->keybuf_space();
break;
default:
return(JS_TRUE);
......@@ -379,6 +387,8 @@ static jsSyncPropertySpec js_console_properties[] = {
{ "output_buffer_level",CON_PROP_OUTBUF_LEVEL ,JSPROP_ENUMERATE|JSPROP_READONLY, 312},
{ "output_buffer_space",CON_PROP_OUTBUF_SPACE ,JSPROP_ENUMERATE|JSPROP_READONLY, 312},
{ "output_rate" ,CON_PROP_OUTPUT_RATE ,JSPROP_ENUMERATE, 31702},
{ "keyboard_buffer_level",CON_PROP_KEYBUF_LEVEL ,JSPROP_ENUMERATE|JSPROP_READONLY, 31800},
{ "keyboard_buffer_space",CON_PROP_KEYBUF_SPACE ,JSPROP_ENUMERATE|JSPROP_READONLY, 31800},
{0}
};
......@@ -424,6 +434,8 @@ static const char* con_prop_desc[] = {
,"number of bytes currently in the output buffer (from the local server) - <small>READ ONLY</small>"
,"number of bytes available in the output buffer - <small>READ ONLY</small>"
,"emulated serial data output rate, in bits-per-second (0 = unlimited)"
,"number of characters current in the keyboard input buffer (from <tt>ungetstr</tt>) - <small>READ ONLY</small>"
,"number of characters spaces available in the keyboard input buffer - <small>READ ONLY</small>"
,NULL
};
#endif
......
......@@ -453,6 +453,8 @@ public:
char dszlog[127]; /* DSZLOG enviornment variable */
int keybuftop,keybufbot; /* Keyboard input buffer pointers (for ungetkey) */
char keybuf[KEY_BUFSIZE]; /* Keyboard input buffer */
size_t keybuf_space(void);
size_t keybuf_level(void);
ushort node_connection;
char connection[LEN_MODEM+1]; /* Connection Description */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment