Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 77f2c366 authored by rswindell's avatar rswindell

sbbs_t::center() and thusly JS console.center() now accepts an optional

"width" argument (in columns), defaults the user's current screen column-width
but you can now over-ride this value when an additional/optional argument.
Also, center() now clears-to-EOL before sending the CRLF to the terminal.
Hopefully this doesn't mess up anyone's existing use of center().
parent 131f3961
......@@ -746,18 +746,22 @@ void sbbs_t::inc_column(int count)
}
}
void sbbs_t::center(char *instr)
void sbbs_t::center(char *instr, unsigned int columns)
{
char str[256];
int i,j;
if(columns < 1)
columns = cols;
SAFECOPY(str,instr);
truncsp(str);
j=bstrlen(str);
if(j < cols)
for(i=0;i<(cols-j)/2;i++)
if(j < columns)
for(i=0;i<(columns-j)/2;i++)
outchar(' ');
bputs(str);
cleartoeol();
newline();
}
......
......@@ -1445,6 +1445,7 @@ js_center(JSContext *cx, uintN argc, jsval *arglist)
JSString* str;
sbbs_t* sbbs;
char* cstr;
int32 cols = 0;
jsrefcount rc;
if((sbbs=(sbbs_t*)js_GetClassPrivate(cx, JS_THIS_OBJECT(cx, arglist), &js_console_class))==NULL)
......@@ -1456,11 +1457,16 @@ js_center(JSContext *cx, uintN argc, jsval *arglist)
if (!str)
return(JS_FALSE);
if(argc > 1) {
if(!JS_ValueToInt32(cx, argv[1], &cols))
return JS_FALSE;
}
JSSTRING_TO_MSTRING(cx, str, cstr, NULL);
if(cstr==NULL)
return JS_FALSE;
rc=JS_SUSPENDREQUEST(cx);
sbbs->center(cstr);
sbbs->center(cstr, cols);
free(cstr);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
......@@ -2033,8 +2039,8 @@ static jsSyncMethodSpec js_console_functions[] = {
"When <tt>P_WORDWRAP</tt> mode flag is specified, <i>orig_columns</i> specifies the original text column width, if known")
,310
},
{"center", js_center, 1, JSTYPE_VOID, JSDOCSTR("text")
,JSDOCSTR("display a string centered on the screen")
{"center", js_center, 1, JSTYPE_VOID, JSDOCSTR("text [,width]")
,JSDOCSTR("display a string centered on the screen, with an optionally-specified screen width (in columns)")
,310
},
{"wide", js_wide, 1, JSTYPE_VOID, JSDOCSTR("text")
......
......@@ -734,7 +734,7 @@ public:
int outchar(enum unicode_codepoint, char cp437_fallback);
int outchar(enum unicode_codepoint, const char* cp437_fallback = NULL);
void inc_column(int count);
void center(char *str);
void center(char *str, unsigned int columns = 0);
void wide(const char*);
void clearline(void);
void cleartoeol(void);
......
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