Newer
Older
}
if (!JS_ValueToInt32(cx, argv[argn++], &left))
return JS_FALSE;
if (!JS_ValueToInt32(cx, argv[argn++], &top))
return JS_FALSE;
if (!JS_ValueToInt32(cx, argv[argn++], &width))
return JS_FALSE;
if (!JS_ValueToInt32(cx, argv[argn++], &maxlen))
return JS_FALSE;
if (!JS_ValueToInt32(cx, argv[argn++], &mode))
return JS_FALSE;
if (argn < argc && JSVAL_IS_STRING(argv[argn])) {
JSVALUE_TO_MSTRING(cx, argv[argn], org, NULL);
argn++;
if (JS_IsExceptionPending(cx)) {
if (argn < argc && JSVAL_IS_OBJECT(argv[argn])) {
if ((objarg = JSVAL_TO_OBJECT(argv[argn])) == NULL) {
free(org);
return(JS_FALSE);
}
if (JS_GetClass(cx, objarg) == &js_uifc_getstrxy_ctx_class) {
p = JS_GetPrivate(cx, objarg);
if (p != NULL) {
lastkey = &(p->lastkey);
}
}
}
JS_ReportError(cx, "max length less than one");
free(org);
return JS_FALSE;
}
if ((str = (char*)malloc(maxlen + 1)) == NULL) {
free(org);
return(JS_FALSE);
}
memset(str, 0, maxlen + 1);
if (org) {
strncpy(str, org, maxlen);
rc = JS_SUSPENDREQUEST(cx);
if (uifc->getstrxy(left, top, width, str, maxlen, mode, lastkey) < 0) {
JS_RESUMEREQUEST(cx, rc);
free(str);
JS_SET_RVAL(cx, arglist, JSVAL_NULL);
return(JS_TRUE);
}
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(JS_NewStringCopyZ(cx, str)));
if (str)
free(str);
return(JS_TRUE);
}
static JSBool
js_uifc_showbuf(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject * obj = JS_THIS_OBJECT(cx, arglist);
jsval * argv = JS_ARGV(cx, arglist);
char* str;
char* title = NULL;
int32 left = 0;
int32 top = 0;
int32 width = INT_MAX;
int32 height = INT_MAX;
int32 mode = 0;
int * cur = NULL;
int * bar = NULL;
uifcapi_t* uifc;
uintN argn = 0;
jsrefcount rc;
JSObject* objarg;
struct showbuf_ctx_private *p;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if ((uifc = get_uifc(cx, obj)) == NULL)
return(JS_FALSE);
if (argc < 3) {
JS_ReportError(cx, "showbuf requires at least three arguments");
return JS_FALSE;
}
if (!JS_ValueToInt32(cx, argv[argn++], &mode))
return JS_FALSE;
JSVALUE_TO_MSTRING(cx, argv[argn++], title, NULL);
if (JS_IsExceptionPending(cx)) {
return(JS_TRUE);
JSVALUE_TO_MSTRING(cx, argv[argn++], str, NULL);
if (JS_IsExceptionPending(cx)) {
free(title);
return JS_FALSE;
}
free(title);
return(JS_TRUE);
}
if (argn < argc && JSVAL_IS_OBJECT(argv[argn])) {
if ((objarg = JSVAL_TO_OBJECT(argv[argn])) == NULL) {
free(title);
free(str);
return(JS_FALSE);
}
if (JS_GetClass(cx, objarg) == &js_uifc_showbuf_ctx_class) {
p = JS_GetPrivate(cx, objarg);
if (p != NULL) {
cur = &(p->cur);
bar = &(p->bar);
left = p->left;
top = p->top;
width = p->width;
height = p->height;
}
}
}
rc = JS_SUSPENDREQUEST(cx);
uifc->showbuf(mode, left, top, width, height, title, str, cur, bar);
JS_RESUMEREQUEST(cx, rc);
free(title);
free(str);
return(JS_TRUE);
}
js_finalize(JSContext *cx, JSObject *obj)
{
uifcapi_t* p;
if ((p = (uifcapi_t*)JS_GetPrivate(cx, obj)) == NULL)
return;
free(p);
JS_SetPrivate(cx, obj, NULL);
}
static jsSyncMethodSpec js_functions[] = {
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
{"init", js_uifc_init, 1, JSTYPE_BOOLEAN, JSDOCSTR("<i>string</i> title [,<i>string</i> interface_mode]")
, JSDOCSTR("Initialize the UIFC library with the specified application/script title (e.g. name and maybe version).<br>"
"<tt>interface_mode</tt> is a string representing the desired console mode, one of 'STDIO', 'AUTO', "
"'X', 'CURSES', 'ANSI', 'CONIO', or 'SDL' (see <tt>conio.init()</tt> for details).<br>"
"Return <tt>true</tt> upon successful UIFC library initialization, <tt>false</tt> upon error."
)
, 314},
{"bail", js_uifc_bail, 0, JSTYPE_VOID, JSDOCSTR("")
, JSDOCSTR("Uninitialize the UIFC library")
, 314},
{"msg", js_uifc_msg, 1, JSTYPE_VOID, JSDOCSTR("<i>string</i> text")
, JSDOCSTR("Print a short text message and wait for user acknowledgment")
, 314},
{"pop", js_uifc_pop, 1, JSTYPE_VOID, JSDOCSTR("[<i>string</i> text]")
, JSDOCSTR("Pop-up (or down) a short text message. Pop-down by passing no <i>text</i> argument.")
, 314},
{"input", js_uifc_input, 0, JSTYPE_STRING, JSDOCSTR("[<i>number</i> mode] [,<i>number</i> left] [,<i>number</i> top] [,<i>string</i> prompt] [,<i>string</i> default] [,<i>number</i> maxlen [,<i>number</i> k_mode]]")
, JSDOCSTR("Prompt for a string input.<br>"
"<tt>mode</tt> is an optional combination of <tt>WIN_</tt> mode flags from <tt>uifcdefs.js</tt>.<br>"
"<tt>left</tt> and <tt>top</tt> are optional window offsets to display the input dialog box.<br>"
"<tt>prompt</tt> is an optional text string to display as part of the string input dialog box.<br>"
"<tt>default</tt> is an optional original text string that the user can edit (requires the <tt>K_EDIT k_mode</tt> flag).<br>"
"<tt>maxlen</tt> is an optional maximum input string length (default is 40 characters).<br>"
"<tt>k_mode</tt> is an optional combination of <tt>K_</tt> mode flags from either <tt>sbbsdefs.js</tt> or <tt>uifcdefs.js</tt>."
"<p>"
"Return the new/edited string or <tt>undefined</tt> if editing was aborted (e.g. via ESC key press)."
)
, 314},
{"list", js_uifc_list, 0, JSTYPE_NUMBER, JSDOCSTR("[<i>number</i> mode,] <i>string</i> title, <i>array</i> options [,<i>uifc.list.CTX</i> ctx]")
, JSDOCSTR("Select from a list of displayed options.<br>"
"<tt>title</tt> is the brief description of the list (menu) to be displayed in the list heading.<br>"
"<tt>options</tt> is an array of items (typically strings) that comprise the displayed list.<br>"
"The <tt>CTX</tt> (context) object can be created using <tt>new uifc.list.CTX</tt> and if the same object is passed in successive calls, allows <tt>WIN_SAV</tt> to work correctly.<br>"
"The context object has the following properties (<i>numbers</i>):<br><tt>cur, bar, left, top, width</tt>"
"<p>"
"Return <tt>-1</tt> if list is aborted (e.g. via ESC key press), <tt>false</tt> upon error (e.g. no option array provided), "
"or the 0-based numeric index of the option selected by the user.<br>"
"Other negative values may be returned in advanced modes/use-cases (e.g. copy/paste), see <tt>MSK_</tt> and related <tt>WIN_</tt> constants/comments in <tt>uifcdefs.js</tt> for details."
)
, 314},
{"showhelp", js_uifc_showhelp, 0, JSTYPE_VOID, JSDOCSTR("")
, JSDOCSTR("Show the current help text")
, 317},
{"scrn", js_uifc_scrn, 1, JSTYPE_BOOLEAN, JSDOCSTR("<i>string</i> text")
, JSDOCSTR("Fill the screen with the appropriate background attribute. string is the title for the application banner.")
, 31802},
{"showbuf", js_uifc_showbuf, 7, JSTYPE_VOID, JSDOCSTR("<i>number</i> mode, <i>string</i> title, <i>string</i> helpbuf [,<i>uifc.showbuf.CTX</i> ctx]")
, JSDOCSTR("Show a scrollable text buffer - optionally parsing \"help markup codes\"<br>"
"The context object can be created using <tt>new uifc.showbuf.CTX</tt> and if the same object is passed, allows <tt>WIN_SAV</tt> to work correctly.<br>"
"The context object has the following properties (<i>numbers</i>):<br><tt>cur, bar, left, top, width, height</tt>")
, 31802},
{"timedisplay", js_uifc_timedisplay, 0, JSTYPE_VOID, JSDOCSTR("[<i>bool<i/> force = false]")
, JSDOCSTR("Update time in upper right corner of screen with current time in ASCII/Unix format")
, 31802},
{"bottomline", js_uifc_bottomline, 1, JSTYPE_VOID, JSDOCSTR("<i>number</i> mode")
, JSDOCSTR("Display the bottom line using the <tt>WIN_*</tt> mode flags")
, 31802},
{"getstrxy", js_uifc_getstrxy, 7, JSTYPE_STRING, JSDOCSTR("<i>number</i> left, <i>number</i> top, <i>number</i> width, <i>number</i> max, <i>number</i> mode [,<i>string</i> original][, <i>uifc.getstrxy.CTX</i> ctx]")
, JSDOCSTR("String input/exit box at a specified position"
"The context object can be created using <tt>new uifc.showbuf.CTX</tt> and if the same object is passed, allows <tt>WIN_SAV</tt> to work correctly.<br>"
"The context object has the following properties: <i>number</i> <tt>lastkey</tt>")
, 31802},
{0}
};
static JSBool js_uifc_resolve(JSContext *cx, JSObject *obj, jsid id)
char* name = NULL;
JSBool ret;
jsval objval;
JSObject* tobj;
if (id != JSID_VOID && id != JSID_EMPTY) {
if (JSVAL_IS_STRING(idval)) {
JSSTRING_TO_MSTRING(cx, JSVAL_TO_STRING(idval), name, NULL);
HANDLE_PENDING(cx, name);
ret = js_SyncResolve(cx, obj, name, js_properties, js_functions, NULL, 0);
if (name == NULL || strcmp(name, "list") == 0) {
if (JS_GetProperty(cx, obj, "list", &objval)) {
tobj = JSVAL_TO_OBJECT(objval);
if (tobj)
JS_InitClass(cx, tobj, NULL, &js_uifc_list_ctx_class, js_list_ctx_constructor, 0, NULL, NULL, NULL, NULL);
}
}
if (name == NULL || strcmp(name, "showbuf") == 0) {
if (JS_GetProperty(cx, obj, "showbuf", &objval)) {
tobj = JSVAL_TO_OBJECT(objval);
if (tobj)
JS_InitClass(cx, tobj, NULL, &js_uifc_showbuf_ctx_class, js_showbuf_ctx_constructor, 0, NULL, NULL, NULL, NULL);
}
}
if (name == NULL || strcmp(name, "getstrxy") == 0) {
if (JS_GetProperty(cx, obj, "getstrxy", &objval)) {
tobj = JSVAL_TO_OBJECT(objval);
if (tobj)
JS_InitClass(cx, tobj, NULL, &js_uifc_getstrxy_ctx_class, js_getstrxy_ctx_constructor, 0, NULL, NULL, NULL, NULL);
}
}
}
static JSBool js_uifc_enumerate(JSContext *cx, JSObject *obj)
{
static JSClass js_uifc_class = {
"UIFC" /* name */
, JSCLASS_HAS_PRIVATE /* flags */
, JS_PropertyStub /* addProperty */
, JS_PropertyStub /* delProperty */
, js_get /* getProperty */
, js_set /* setProperty */
, js_uifc_enumerate /* enumerate */
, js_uifc_resolve /* resolve */
, JS_ConvertStub /* convert */
, js_finalize /* finalize */
};
JSObject* js_CreateUifcObject(JSContext* cx, JSObject* parent)
{
JSObject* obj;
uifcapi_t* api;
if ((obj = JS_DefineObject(cx, parent, "uifc", &js_uifc_class, NULL
, JSPROP_ENUMERATE | JSPROP_READONLY)) == NULL)
return(NULL);
if ((api = (uifcapi_t*)malloc(sizeof(uifcapi_t))) == NULL)
return(NULL);
memset(api, 0, sizeof(uifcapi_t));
api->size = sizeof(uifcapi_t);
api->esc_delay = 25;
if (!JS_SetPrivate(cx, obj, api)) /* Store a pointer to uifcapi_t */
return(NULL);
js_DescribeSyncObject(cx, obj, "User InterFaCe object - Text User Interface (TUI) menu system for JSexec", 314);
js_CreateArrayOfStrings(cx, obj, "_property_desc_list", uifc_prop_desc, JSPROP_READONLY);
#endif
return(obj);
}