Commit 07f31378 authored by rswindell's avatar rswindell

sbbs_t::yesno() and noyes() and their JS equivalents (console.yesno/noyes)

now accept an optional print-mode (a.k.a. pmode) argument to provide more
control over the printing that happens in these functions/methods.
The immediate use is for P_NOCRLF to stop the newline from being printed
after a yes or no response (e.g. in a full-screen UI), but there could be other
uses.
parent c6c5301c
......@@ -362,7 +362,7 @@ void sbbs_t::mnemonics(const char *str)
/* Returns true for Yes or false for No */
/* Called from quite a few places */
/****************************************************************************/
bool sbbs_t::yesno(const char *str)
bool sbbs_t::yesno(const char *str, long mode)
{
char ch;
......@@ -370,20 +370,20 @@ bool sbbs_t::yesno(const char *str)
return true;
SAFECOPY(question,str);
SYNC;
bprintf(text[YesNoQuestion],str);
bprintf(mode, text[YesNoQuestion], str);
while(online) {
if(sys_status&SS_ABORT)
ch=text[YNQP][1];
else
ch=getkey(K_UPPER|K_COLD);
if(ch==text[YNQP][0] || ch==CR) {
if(bputs(text[Yes]))
if(bputs(text[Yes], mode) && !(mode&P_NOCRLF))
CRLF;
lncntr=0;
return(true);
}
if(ch==text[YNQP][1]) {
if(bputs(text[No]))
if(bputs(text[No], mode) && !(mode&P_NOCRLF))
CRLF;
lncntr=0;
return(false);
......@@ -396,7 +396,7 @@ bool sbbs_t::yesno(const char *str)
/* Prompts user for N or Y (no or yes) and CR is interpreted as a N */
/* Returns true for No or false for Yes */
/****************************************************************************/
bool sbbs_t::noyes(const char *str)
bool sbbs_t::noyes(const char *str, long mode)
{
char ch;
......@@ -404,20 +404,20 @@ bool sbbs_t::noyes(const char *str)
return true;
SAFECOPY(question,str);
SYNC;
bprintf(text[NoYesQuestion],str);
bprintf(mode, text[NoYesQuestion], str);
while(online) {
if(sys_status&SS_ABORT)
ch=text[YNQP][1];
else
ch=getkey(K_UPPER|K_COLD);
if(ch==text[YNQP][1] || ch==CR) {
if(bputs(text[No]))
if(bputs(text[No], mode) && !(mode&P_NOCRLF))
CRLF;
lncntr=0;
return(true);
}
if(ch==text[YNQP][0]) {
if(bputs(text[Yes]))
if(bputs(text[Yes], mode) && !(mode&P_NOCRLF))
CRLF;
lncntr=0;
return(false);
......
......@@ -846,6 +846,7 @@ js_yesno(JSContext *cx, uintN argc, jsval *arglist)
sbbs_t* sbbs;
JSString* js_str;
char* cstr;
int32 mode = P_NONE;
jsrefcount rc;
if((sbbs=(sbbs_t*)js_GetClassPrivate(cx, JS_THIS_OBJECT(cx, arglist), &js_console_class))==NULL)
......@@ -859,8 +860,12 @@ js_yesno(JSContext *cx, uintN argc, jsval *arglist)
JSSTRING_TO_MSTRING(cx, js_str, cstr, NULL);
if(cstr==NULL)
return JS_FALSE;
if(JSVAL_IS_NUMBER(argv[1])) {
if(!JS_ValueToInt32(cx, argv[1], &mode))
return JS_FALSE;
}
rc=JS_SUSPENDREQUEST(cx);
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->yesno(cstr)));
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->yesno(cstr, mode)));
free(cstr);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
......@@ -873,6 +878,7 @@ js_noyes(JSContext *cx, uintN argc, jsval *arglist)
sbbs_t* sbbs;
JSString* js_str;
char* cstr;
int32 mode = P_NONE;
jsrefcount rc;
if((sbbs=(sbbs_t*)js_GetClassPrivate(cx, JS_THIS_OBJECT(cx, arglist), &js_console_class))==NULL)
......@@ -886,8 +892,12 @@ js_noyes(JSContext *cx, uintN argc, jsval *arglist)
JSSTRING_TO_MSTRING(cx, js_str, cstr, NULL);
if(cstr==NULL)
return JS_FALSE;
if(JSVAL_IS_NUMBER(argv[1])) {
if(!JS_ValueToInt32(cx, argv[1], &mode))
return JS_FALSE;
}
rc=JS_SUSPENDREQUEST(cx);
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->noyes(cstr)));
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->noyes(cstr, mode)));
free(cstr);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
......@@ -1976,12 +1986,12 @@ static jsSyncMethodSpec js_console_functions[] = {
,JSDOCSTR("put a data (e.g. a string of characters) in the keyboard input buffer")
,310
},
{"yesno", js_yesno, 1, JSTYPE_BOOLEAN, JSDOCSTR("question")
,JSDOCSTR("YES/no question - returns <i>true</i> if yes is selected")
{"yesno", js_yesno, 1, JSTYPE_BOOLEAN, JSDOCSTR("question [,mode = P_NONE]")
,JSDOCSTR("YES/no question - returns <i>true</i> if 'yes' is selected")
,310
},
{"noyes", js_noyes, 1, JSTYPE_BOOLEAN, JSDOCSTR("question")
,JSDOCSTR("NO/yes question - returns <i>true</i> if no is selected")
{"noyes", js_noyes, 1, JSTYPE_BOOLEAN, JSDOCSTR("question [,mode = P_NONE]")
,JSDOCSTR("NO/yes question - returns <i>true</i> if 'no' is selected")
,310
},
{"mnemonics", js_mnemonics, 1, JSTYPE_VOID, JSDOCSTR("text")
......
......@@ -790,8 +790,8 @@ public:
long getkeys(const char *str, ulong max, long mode = K_UPPER);
void ungetkey(char ch); /* Places 'ch' into the input buffer */
char question[MAX_TEXTDAT_ITEM_LEN+1];
bool yesno(const char *str);
bool noyes(const char *str);
bool yesno(const char *str, long mode = 0);
bool noyes(const char *str, long mode = 0);
void pause(void);
const char * mnestr;
void mnemonics(const char *str);
......
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