Skip to content
Snippets Groups Projects
Commit e4cdd4ac authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Rename sbbs_t::ansi_getlines() to ansi_getdims(), add sbbs_t::getdimensions()

Add JS console.ansi_getdims()

Use sbbs_t::getdimensions() or JS console.getdimensions() to move user
cols/rows values to run-time console values (querying ANSI terminal if
appropriate/supported).

JS console.pushxy(), popxy(), and gotoxy() all return Boolean now.

sbbs_t::getdimensions() and its JS wrapper is now the proper way to propagate
user's cols/rows settings to the run-time console values. This was done
(post-login) only via use of the TERMROWS and TERMCOLS @-codes in
user_settings.js. Weird.
parent 6e30bb63
No related branches found
No related tags found
No related merge requests found
Pipeline #6884 passed
...@@ -192,14 +192,15 @@ char* sbbs_t::ansi(int atr, int curatr, char* str) ...@@ -192,14 +192,15 @@ char* sbbs_t::ansi(int atr, int curatr, char* str)
return ::ansi_attr(atr, curatr, str, (term&COLOR) ? TRUE:FALSE); return ::ansi_attr(atr, curatr, str, (term&COLOR) ? TRUE:FALSE);
} }
void sbbs_t::ansi_getlines() bool sbbs_t::ansi_getdims()
{ {
if(sys_status&SS_USERON && useron.misc&ANSI if(sys_status&SS_USERON && useron.misc&ANSI
&& (useron.rows == TERM_ROWS_AUTO || useron.cols == TERM_COLS_AUTO) && (useron.rows == TERM_ROWS_AUTO || useron.cols == TERM_COLS_AUTO)
&& online==ON_REMOTE) { /* Remote */ && online==ON_REMOTE) { /* Remote */
putcom("\x1b[s\x1b[255B\x1b[255C\x1b[6n\x1b[u"); putcom("\x1b[s\x1b[255B\x1b[255C\x1b[6n\x1b[u");
inkey(K_ANSI_CPR,TIMEOUT_ANSI_GETXY*1000); return inkey(K_ANSI_CPR,TIMEOUT_ANSI_GETXY*1000) == 0;
} }
return false;
} }
bool sbbs_t::ansi_getxy(int* x, int* y) bool sbbs_t::ansi_getxy(int* x, int* y)
......
...@@ -899,7 +899,7 @@ const char* sbbs_t::atcode(const char* sp, char* str, size_t maxlen, int* pmode, ...@@ -899,7 +899,7 @@ const char* sbbs_t::atcode(const char* sp, char* str, size_t maxlen, int* pmode,
} }
if(strcmp(sp, "GETDIM") == 0) { if(strcmp(sp, "GETDIM") == 0) {
ansi_getlines(); getdimensions();
return nulstr; return nulstr;
} }
......
...@@ -515,7 +515,7 @@ int sbbs_t::term_supports(int cmp_flags) ...@@ -515,7 +515,7 @@ int sbbs_t::term_supports(int cmp_flags)
char* sbbs_t::term_rows(user_t* user, char* str, size_t size) char* sbbs_t::term_rows(user_t* user, char* str, size_t size)
{ {
if(user->rows != TERM_ROWS_AUTO) if(user->rows >= TERM_ROWS_MIN && user->rows <= TERM_ROWS_MAX)
rows = user->rows; rows = user->rows;
safe_snprintf(str, size, "%s%d %s", user->rows ? nulstr:text[TerminalAutoDetect], rows, text[TerminalRows]); safe_snprintf(str, size, "%s%d %s", user->rows ? nulstr:text[TerminalAutoDetect], rows, text[TerminalRows]);
return str; return str;
...@@ -523,7 +523,7 @@ char* sbbs_t::term_rows(user_t* user, char* str, size_t size) ...@@ -523,7 +523,7 @@ char* sbbs_t::term_rows(user_t* user, char* str, size_t size)
char* sbbs_t::term_cols(user_t* user, char* str, size_t size) char* sbbs_t::term_cols(user_t* user, char* str, size_t size)
{ {
if(user->cols != TERM_COLS_AUTO) if(user->cols >= TERM_COLS_MIN && user->cols <= TERM_COLS_MAX)
cols = user->cols; cols = user->cols;
safe_snprintf(str, size, "%s%d %s", user->cols ? nulstr:text[TerminalAutoDetect], cols, text[TerminalColumns]); safe_snprintf(str, size, "%s%d %s", user->cols ? nulstr:text[TerminalAutoDetect], cols, text[TerminalColumns]);
return str; return str;
...@@ -1101,6 +1101,21 @@ void sbbs_t::set_output_rate(enum output_rate speed) ...@@ -1101,6 +1101,21 @@ void sbbs_t::set_output_rate(enum output_rate speed)
} }
} }
/****************************************************************************/
/* Get the dimensions of the current user console, place into row and cols */
/****************************************************************************/
void sbbs_t::getdimensions()
{
if(sys_status & SS_USERON) {
if(!ansi_getdims()) {
if(useron.rows >= TERM_ROWS_MIN && useron.rows <= TERM_ROWS_MAX)
rows = useron.rows;
if(useron.cols >= TERM_COLS_MIN && useron.cols <= TERM_COLS_MAX)
cols = useron.cols;
}
}
}
/****************************************************************************/ /****************************************************************************/
/* performs the correct attribute modifications for the Ctrl-A code */ /* performs the correct attribute modifications for the Ctrl-A code */
/****************************************************************************/ /****************************************************************************/
......
...@@ -1836,7 +1836,7 @@ int sbbs_t::exec(csi_t *csi) ...@@ -1836,7 +1836,7 @@ int sbbs_t::exec(csi_t *csi)
lncntr=0; lncntr=0;
return(0); return(0);
case CS_GETLINES: case CS_GETLINES:
ansi_getlines(); getdimensions();
return(0); return(0);
case CS_HANGUP: case CS_HANGUP:
hangup(); hangup();
......
...@@ -1914,10 +1914,8 @@ js_pushxy(JSContext *cx, uintN argc, jsval *arglist) ...@@ -1914,10 +1914,8 @@ js_pushxy(JSContext *cx, uintN argc, jsval *arglist)
if((sbbs=(sbbs_t*)js_GetClassPrivate(cx, JS_THIS_OBJECT(cx, arglist), &js_console_class))==NULL) if((sbbs=(sbbs_t*)js_GetClassPrivate(cx, JS_THIS_OBJECT(cx, arglist), &js_console_class))==NULL)
return(JS_FALSE); return(JS_FALSE);
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
rc=JS_SUSPENDREQUEST(cx); rc=JS_SUSPENDREQUEST(cx);
sbbs->ansi_save(); JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->ansi_save()));
JS_RESUMEREQUEST(cx, rc); JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE); return(JS_TRUE);
} }
...@@ -1931,10 +1929,8 @@ js_popxy(JSContext *cx, uintN argc, jsval *arglist) ...@@ -1931,10 +1929,8 @@ js_popxy(JSContext *cx, uintN argc, jsval *arglist)
if((sbbs=(sbbs_t*)js_GetClassPrivate(cx, JS_THIS_OBJECT(cx, arglist), &js_console_class))==NULL) if((sbbs=(sbbs_t*)js_GetClassPrivate(cx, JS_THIS_OBJECT(cx, arglist), &js_console_class))==NULL)
return(JS_FALSE); return(JS_FALSE);
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
rc=JS_SUSPENDREQUEST(cx); rc=JS_SUSPENDREQUEST(cx);
sbbs->ansi_restore(); JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->ansi_restore()));
JS_RESUMEREQUEST(cx, rc); JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE); return(JS_TRUE);
} }
...@@ -1972,7 +1968,7 @@ js_gotoxy(JSContext *cx, uintN argc, jsval *arglist) ...@@ -1972,7 +1968,7 @@ js_gotoxy(JSContext *cx, uintN argc, jsval *arglist)
} }
rc=JS_SUSPENDREQUEST(cx); rc=JS_SUSPENDREQUEST(cx);
sbbs->cursor_xy(x,y); JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->cursor_xy(x,y)));
JS_RESUMEREQUEST(cx, rc); JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE); return(JS_TRUE);
} }
...@@ -2201,7 +2197,22 @@ js_clearkeybuf(JSContext *cx, uintN argc, jsval *arglist) ...@@ -2201,7 +2197,22 @@ js_clearkeybuf(JSContext *cx, uintN argc, jsval *arglist)
} }
static JSBool static JSBool
js_getlines(JSContext *cx, uintN argc, jsval *arglist) js_ansi_getdims(JSContext *cx, uintN argc, jsval *arglist)
{
sbbs_t* sbbs;
jsrefcount rc;
if((sbbs=(sbbs_t*)js_GetClassPrivate(cx, JS_THIS_OBJECT(cx, arglist), &js_console_class))==NULL)
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->ansi_getdims()));
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
js_getdims(JSContext *cx, uintN argc, jsval *arglist)
{ {
sbbs_t* sbbs; sbbs_t* sbbs;
jsrefcount rc; jsrefcount rc;
...@@ -2212,7 +2223,7 @@ js_getlines(JSContext *cx, uintN argc, jsval *arglist) ...@@ -2212,7 +2223,7 @@ js_getlines(JSContext *cx, uintN argc, jsval *arglist)
JS_SET_RVAL(cx, arglist, JSVAL_VOID); JS_SET_RVAL(cx, arglist, JSVAL_VOID);
rc=JS_SUSPENDREQUEST(cx); rc=JS_SUSPENDREQUEST(cx);
sbbs->ansi_getlines(); sbbs->getdimensions();
JS_RESUMEREQUEST(cx, rc); JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE); return(JS_TRUE);
} }
...@@ -2711,18 +2722,18 @@ static jsSyncMethodSpec js_console_functions[] = { ...@@ -2711,18 +2722,18 @@ static jsSyncMethodSpec js_console_functions[] = {
}, },
{"ansi_save", js_pushxy, 0, JSTYPE_ALIAS }, {"ansi_save", js_pushxy, 0, JSTYPE_ALIAS },
{"ansi_pushxy", js_pushxy, 0, JSTYPE_ALIAS }, {"ansi_pushxy", js_pushxy, 0, JSTYPE_ALIAS },
{"pushxy", js_pushxy, 0, JSTYPE_VOID, JSDOCSTR("") {"pushxy", js_pushxy, 0, JSTYPE_BOOLEAN, JSDOCSTR("")
,JSDOCSTR("Save the current cursor position (x and y coordinates) in the remote terminal") ,JSDOCSTR("Save the current cursor position (x and y coordinates) in the remote terminal")
,311 ,311
}, },
{"ansi_restore", js_popxy, 0, JSTYPE_ALIAS }, {"ansi_restore", js_popxy, 0, JSTYPE_ALIAS },
{"ansi_popxy", js_popxy, 0, JSTYPE_ALIAS }, {"ansi_popxy", js_popxy, 0, JSTYPE_ALIAS },
{"popxy", js_popxy, 0, JSTYPE_VOID, JSDOCSTR("") {"popxy", js_popxy, 0, JSTYPE_BOOLEAN, JSDOCSTR("")
,JSDOCSTR("Restore a saved cursor position to the remote terminal (requires terminal support, e.g. ANSI)") ,JSDOCSTR("Restore a saved cursor position to the remote terminal (requires terminal support, e.g. ANSI)")
,311 ,311
}, },
{"ansi_gotoxy", js_gotoxy, 1, JSTYPE_ALIAS }, {"ansi_gotoxy", js_gotoxy, 1, JSTYPE_ALIAS },
{"gotoxy", js_gotoxy, 1, JSTYPE_VOID, JSDOCSTR("[x,y] or [<i>object</i> { x,y }]") {"gotoxy", js_gotoxy, 1, JSTYPE_BOOLEAN, JSDOCSTR("[x,y] or [<i>object</i> { x,y }]")
,JSDOCSTR("Move cursor to a specific screen coordinate (ANSI or PETSCII, 1-based values), " ,JSDOCSTR("Move cursor to a specific screen coordinate (ANSI or PETSCII, 1-based values), "
"arguments can be separate x and y coordinates or an object with x and y properties " "arguments can be separate x and y coordinates or an object with x and y properties "
"(like that returned from <tt>console.getxy()</tt>)") "(like that returned from <tt>console.getxy()</tt>)")
...@@ -2748,11 +2759,16 @@ static jsSyncMethodSpec js_console_functions[] = { ...@@ -2748,11 +2759,16 @@ static jsSyncMethodSpec js_console_functions[] = {
,JSDOCSTR("Move cursor left one or more columns") ,JSDOCSTR("Move cursor left one or more columns")
,311 ,311
}, },
{"ansi_getlines", js_getlines, 0, JSTYPE_ALIAS }, {"ansi_getlines", js_ansi_getdims, 0, JSTYPE_ALIAS },
{"getlines", js_getlines, 0, JSTYPE_ALIAS }, {"ansi_getdims", js_ansi_getdims, 0, JSTYPE_BOOLEAN, JSDOCSTR("")
{"getdimensions", js_getlines, 0, JSTYPE_VOID, JSDOCSTR("") ,JSDOCSTR("Query the dimensions (rows and columns) of the remote ANSI terminal")
,JSDOCSTR("Query the number of rows and columns on the remote terminal") ,320
,311 },
{"getlines", js_getdims, 0, JSTYPE_ALIAS },
{"getdimensions", js_getdims, 0, JSTYPE_VOID, JSDOCSTR("")
,JSDOCSTR("Get the dimensions of user's terminal, querying the remote terminal if possible/appropriate")
,320
}, },
{"ansi_getxy", js_getxy, 0, JSTYPE_ALIAS }, {"ansi_getxy", js_getxy, 0, JSTYPE_ALIAS },
{"getxy", js_getxy, 0, JSTYPE_OBJECT, JSDOCSTR("") {"getxy", js_getxy, 0, JSTYPE_OBJECT, JSDOCSTR("")
......
...@@ -163,7 +163,7 @@ bool sbbs_t::printfile(const char* fname, int mode, int org_cols, JSObject* obj) ...@@ -163,7 +163,7 @@ bool sbbs_t::printfile(const char* fname, int mode, int org_cols, JSObject* obj)
rioctl(IOSM|ABORT); rioctl(IOSM|ABORT);
} }
if(rip) if(rip)
ansi_getlines(); ansi_getdims();
console=savcon; console=savcon;
return true; return true;
......
...@@ -728,7 +728,7 @@ public: ...@@ -728,7 +728,7 @@ public:
bool ansi_getxy(int* x, int* y); bool ansi_getxy(int* x, int* y);
bool ansi_save(void); bool ansi_save(void);
bool ansi_restore(void); bool ansi_restore(void);
void ansi_getlines(void); bool ansi_getdims(void);
enum ansi_mouse_mode { enum ansi_mouse_mode {
ANSI_MOUSE_X10 = 9, ANSI_MOUSE_X10 = 9,
ANSI_MOUSE_NORM = 1000, ANSI_MOUSE_NORM = 1000,
...@@ -994,6 +994,7 @@ public: ...@@ -994,6 +994,7 @@ public:
output_rate_115200 = 115200, output_rate_115200 = 115200,
} cur_output_rate = output_rate_unlimited; } cur_output_rate = output_rate_unlimited;
void set_output_rate(enum output_rate); void set_output_rate(enum output_rate);
void getdimensions();
/* getstr.cpp */ /* getstr.cpp */
size_t getstr_offset = 0; size_t getstr_offset = 0;
......
...@@ -1013,7 +1013,7 @@ void sbbs_t::maindflts(user_t* user) ...@@ -1013,7 +1013,7 @@ void sbbs_t::maindflts(user_t* user)
putuserdec32(user->number, USER_COLS, i); putuserdec32(user->number, USER_COLS, i);
if(user==&useron) { if(user==&useron) {
useron.cols = i; useron.cols = i;
ansi_getlines(); getdimensions();
} }
bputs(text[HowManyRows]); bputs(text[HowManyRows]);
if((i = getnum(TERM_ROWS_MAX)) < 0) if((i = getnum(TERM_ROWS_MAX)) < 0)
...@@ -1021,7 +1021,7 @@ void sbbs_t::maindflts(user_t* user) ...@@ -1021,7 +1021,7 @@ void sbbs_t::maindflts(user_t* user)
putuserdec32(user->number, USER_ROWS, i); putuserdec32(user->number, USER_ROWS, i);
if(user==&useron) { if(user==&useron) {
useron.rows = i; useron.rows = i;
ansi_getlines(); getdimensions();
} }
break; break;
case 'P': case 'P':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment