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

Add K_LINEWRAP getstr() mode flag, rename K_WRAP to K_WORDWRAP

For 10 years (commit e212e2c5), sbbs_t/console.getstr() has limited length
of string input to the available columns of the terminal.

To fix issue #869, rather than change getstr()'s default behavior, add a new
mode flag: K_LINEWRAP which does not limit the string length input based on
the terminal width (and the current column) (e.g. for use with ;string
commands from the default command shell).

Ideally, I'd like to have a marquee-style option (K_mode flag) where longer
strings just side-scroll to accommodate strings longer than the terminal
width, but in the mean-time, this'll do.

So anywhere we think a narrow (e.g. 40 column) terminal is being excessively
restricted in string input width and starting the input in the first column
is not an option/solution, adding the K_LINEWRAP flag to the getstr() call is
the proposed solution.
parent 4efd16bb
No related branches found
No related tags found
No related merge requests found
Pipeline #8171 failed
...@@ -200,7 +200,7 @@ while(bbs.online && !js.terminated) { ...@@ -200,7 +200,7 @@ while(bbs.online && !js.terminated) {
if(cmd > ' ') if(cmd > ' ')
console.print(cmd); console.print(cmd);
if(cmd == ';') { if(cmd == ';') {
cmd = console.getstr(); cmd = console.getstr(100, K_LINEWRAP);
if(cmd == '!') if(cmd == '!')
cmd = last_str_cmd; cmd = last_str_cmd;
load({}, "str_cmds.js", cmd); load({}, "str_cmds.js", cmd);
......
...@@ -163,7 +163,7 @@ var K_NONE =0; /* No special behavior */ ...@@ -163,7 +163,7 @@ var K_NONE =0; /* No special behavior */
var K_UPPER =(1<<0); /* Converts all letters to upper case */ var K_UPPER =(1<<0); /* Converts all letters to upper case */
var K_UPRLWR =(1<<1); /* Upper/Lower case automatically */ var K_UPRLWR =(1<<1); /* Upper/Lower case automatically */
var K_NUMBER =(1<<2); /* Allow numbers only */ var K_NUMBER =(1<<2); /* Allow numbers only */
var K_WRAP =(1<<3); /* Allows word wrap */ var K_WORDWRAP =(1<<3); /* Allows word wrap */
var K_MSG =(1<<4); /* Allows ANSI, ^N ^A ^G */ var K_MSG =(1<<4); /* Allows ANSI, ^N ^A ^G */
var K_SPIN =(1<<5); /* Spinning cursor (same as SPIN) */ var K_SPIN =(1<<5); /* Spinning cursor (same as SPIN) */
var K_LINE =(1<<6); /* Input line (inverse color) */ var K_LINE =(1<<6); /* Input line (inverse color) */
...@@ -187,6 +187,8 @@ var K_TRIM =(1<<23); /* Trim white-space from both ends of str */ ...@@ -187,6 +187,8 @@ var K_TRIM =(1<<23); /* Trim white-space from both ends of str */
var K_CTRLKEYS =(1<<24); /* No control-key handling/eating in inkey()*/ var K_CTRLKEYS =(1<<24); /* No control-key handling/eating in inkey()*/
var K_NUL =(1<<25); /* Return null instead of "" upon timeout */ var K_NUL =(1<<25); /* Return null instead of "" upon timeout */
var K_UTF8 =(1<<26); /* Don't translate UTF-8 input to CP437 */ var K_UTF8 =(1<<26); /* Don't translate UTF-8 input to CP437 */
var K_RIGHTEXIT =(1<<27); /* Allow exit by arrowing right */
var K_LINEWRAP =(1<<29); /* Allow string input to wrap the terminal */
/********************************************/ /********************************************/
/********************************************/ /********************************************/
......
...@@ -402,7 +402,7 @@ void sbbs_t::multinodechat(int channel) ...@@ -402,7 +402,7 @@ void sbbs_t::multinodechat(int channel)
j = 0; j = 0;
pgraph[0] = 0; pgraph[0] = 0;
while (j < 5) { while (j < 5) {
if (!getstr(line, 66, K_WRAP | K_MSG | K_CHAT)) if (!getstr(line, 66, K_WORDWRAP | K_MSG | K_CHAT))
break; break;
if (j) { if (j) {
snprintf(str, sizeof str, text[ChatLineFmt] snprintf(str, sizeof str, text[ChatLineFmt]
...@@ -1361,7 +1361,7 @@ void sbbs_t::nodemsg() ...@@ -1361,7 +1361,7 @@ void sbbs_t::nodemsg()
logbuf[0] = 0; logbuf[0] = 0;
while (online && i < 5) { while (online && i < 5) {
bprintf("%4s", nulstr); bprintf("%4s", nulstr);
if (!getstr(line, 70, K_WRAP | K_MSG)) if (!getstr(line, 70, K_WORDWRAP | K_MSG))
break; break;
SAFEPRINTF2(str, "%4s%s\r\n", nulstr, line); SAFEPRINTF2(str, "%4s%s\r\n", nulstr, line);
SAFECAT(buf, str); SAFECAT(buf, str);
...@@ -1956,7 +1956,7 @@ void sbbs_t::localguru(char *gurubuf, int gurunum) ...@@ -1956,7 +1956,7 @@ void sbbs_t::localguru(char *gurubuf, int gurunum)
ungetkey(ch); ungetkey(ch);
} }
attr(cfg.color[clr_chatremote]); attr(cfg.color[clr_chatremote]);
getstr(str, 78, K_WRAP | K_CHAT); getstr(str, 78, K_WORDWRAP | K_CHAT);
} }
bputs(text[EndOfChat]); bputs(text[EndOfChat]);
sys_status &= ~SS_GURUCHAT; sys_status &= ~SS_GURUCHAT;
......
...@@ -43,10 +43,10 @@ size_t sbbs_t::getstr(char *strout, size_t maxlen, int mode, const str_list_t hi ...@@ -43,10 +43,10 @@ size_t sbbs_t::getstr(char *strout, size_t maxlen, int mode, const str_list_t hi
int term = term_supports(); int term = term_supports();
console &= ~(CON_UPARROW | CON_DOWNARROW | CON_LEFTARROW | CON_RIGHTARROW | CON_BACKSPACE | CON_DELETELINE); console &= ~(CON_UPARROW | CON_DOWNARROW | CON_LEFTARROW | CON_RIGHTARROW | CON_BACKSPACE | CON_DELETELINE);
if (!(mode & K_WRAP)) if (!(mode & K_WORDWRAP))
console &= ~CON_INSERT; console &= ~CON_INSERT;
sys_status &= ~SS_ABORT; sys_status &= ~SS_ABORT;
if (cols >= TERM_COLS_MIN && !(mode & K_NOECHO) && !(console & CON_R_ECHOX) if (!(mode & K_LINEWRAP) && cols >= TERM_COLS_MIN && !(mode & K_NOECHO) && !(console & CON_R_ECHOX)
&& column + (int)maxlen >= cols) /* Don't allow the terminal to auto line-wrap */ && column + (int)maxlen >= cols) /* Don't allow the terminal to auto line-wrap */
maxlen = cols - column - 1; maxlen = cols - column - 1;
if (mode & K_LINE && (term & (ANSI | PETSCII)) && !(mode & K_NOECHO)) { if (mode & K_LINE && (term & (ANSI | PETSCII)) && !(mode & K_NOECHO)) {
...@@ -130,7 +130,7 @@ size_t sbbs_t::getstr(char *strout, size_t maxlen, int mode, const str_list_t hi ...@@ -130,7 +130,7 @@ size_t sbbs_t::getstr(char *strout, size_t maxlen, int mode, const str_list_t hi
console |= CON_RIGHTARROW; console |= CON_RIGHTARROW;
break; break;
} }
if (ch == TAB && (mode & K_TAB || (!(mode & K_WRAP) && history == NULL))) /* TAB same as CR */ if (ch == TAB && (mode & K_TAB || (!(mode & K_WORDWRAP) && history == NULL))) /* TAB same as CR */
break; break;
if (!i && (mode & (K_UPRLWR | K_TRIM)) && (ch == ' ' || ch == TAB)) if (!i && (mode & (K_UPRLWR | K_TRIM)) && (ch == ' ' || ch == TAB))
continue; /* ignore beginning white space if upper/lower */ continue; /* ignore beginning white space if upper/lower */
...@@ -528,7 +528,7 @@ size_t sbbs_t::getstr(char *strout, size_t maxlen, int mode, const str_list_t hi ...@@ -528,7 +528,7 @@ size_t sbbs_t::getstr(char *strout, size_t maxlen, int mode, const str_list_t hi
cursor_left((l - i) + 1); cursor_left((l - i) + 1);
break; break;
default: default:
if (mode & K_WRAP && i == maxlen && ch >= ' ' && !(console & CON_INSERT)) { if (mode & K_WORDWRAP && i == maxlen && ch >= ' ' && !(console & CON_INSERT)) {
str1[i] = 0; str1[i] = 0;
if (ch == ' ' && !(mode & K_CHAT)) { /* don't wrap a space */ if (ch == ' ' && !(mode & K_CHAT)) { /* don't wrap a space */
strcpy(strout, str1); /* as last char */ strcpy(strout, str1); /* as last char */
......
...@@ -3619,7 +3619,7 @@ js_put_telegram(JSContext *cx, uintN argc, jsval *arglist) ...@@ -3619,7 +3619,7 @@ js_put_telegram(JSContext *cx, uintN argc, jsval *arglist)
while (sbbs->online && i < 5) { while (sbbs->online && i < 5) {
char line[256]; char line[256];
sbbs->bputs("\1n: \1h"); sbbs->bputs("\1n: \1h");
if (!sbbs->getstr(line, 70, i < 4 ? (K_WRAP | K_MSG) : (K_MSG))) if (!sbbs->getstr(line, 70, i < 4 ? (K_WORDWRAP | K_MSG) : (K_MSG)))
break; break;
SAFEPRINTF2(str, "%4s%s\r\n", nulstr, line); SAFEPRINTF2(str, "%4s%s\r\n", nulstr, line);
SAFECAT(buf, str); SAFECAT(buf, str);
......
...@@ -643,7 +643,7 @@ typedef enum { /* Values for xtrn_t.event */ ...@@ -643,7 +643,7 @@ typedef enum { /* Values for xtrn_t.event */
#define K_UPPER (1 << 0) /* Converts all letters to upper case */ #define K_UPPER (1 << 0) /* Converts all letters to upper case */
#define K_UPRLWR (1 << 1) /* Upper/Lower case automatically */ #define K_UPRLWR (1 << 1) /* Upper/Lower case automatically */
#define K_NUMBER (1 << 2) /* Allow numbers only */ #define K_NUMBER (1 << 2) /* Allow numbers only */
#define K_WRAP (1 << 3) /* Allows word wrap */ #define K_WORDWRAP (1 << 3) /* Allows word wrap */
#define K_MSG (1 << 4) /* Allows ANSI, ^N ^A ^G */ #define K_MSG (1 << 4) /* Allows ANSI, ^N ^A ^G */
#define K_SPIN (1 << 5) /* Spinning cursor (same as SPIN) */ #define K_SPIN (1 << 5) /* Spinning cursor (same as SPIN) */
#define K_LINE (1 << 6) /* Input line (inverse color) */ #define K_LINE (1 << 6) /* Input line (inverse color) */
...@@ -668,6 +668,7 @@ typedef enum { /* Values for xtrn_t.event */ ...@@ -668,6 +668,7 @@ typedef enum { /* Values for xtrn_t.event */
#define K_NUL (1 << 25) /* Return NOINP on timeout instead of '\0' */ #define K_NUL (1 << 25) /* Return NOINP on timeout instead of '\0' */
#define K_UTF8 (1 << 26) /* Don't translate UTF-8 input into CP437 */ #define K_UTF8 (1 << 26) /* Don't translate UTF-8 input into CP437 */
#define K_RIGHTEXIT (1 << 27) /* Allow exit by arrowing right */ #define K_RIGHTEXIT (1 << 27) /* Allow exit by arrowing right */
#define K_LINEWRAP (1 << 29) /* Allow string input to wrap the terminal */
/* Bits in 'mode' for putmsg and printfile */ /* Bits in 'mode' for putmsg and printfile */
#define P_NONE 0 /* No mode flags */ #define P_NONE 0 /* No mode flags */
......
...@@ -1008,7 +1008,7 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title, uint maxlines, u ...@@ -1008,7 +1008,7 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title, uint maxlines, u
if (line < 1) if (line < 1)
carriage_return(); carriage_return();
ulong prev_con = console; ulong prev_con = console;
int kmode = K_WRAP | K_MSG | K_EDIT | K_NOCRLF | K_USEOFFSET; int kmode = K_WORDWRAP | K_MSG | K_EDIT | K_NOCRLF | K_USEOFFSET;
if (line) if (line)
kmode |= K_LEFTEXIT; kmode |= K_LEFTEXIT;
if (str[line] != NULL) if (str[line] != NULL)
...@@ -1125,7 +1125,7 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title, uint maxlines, u ...@@ -1125,7 +1125,7 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title, uint maxlines, u
j = K_MSG | K_EDIT; /* use j for the getstr mode */ j = K_MSG | K_EDIT; /* use j for the getstr mode */
if (i == -1) { /* /E means edit last line */ if (i == -1) { /* /E means edit last line */
i = lines - 1; i = lines - 1;
j |= K_WRAP; /* wrap when editing last line */ j |= K_WORDWRAP; /* wrap when editing last line */
} }
if (i >= (int)lines || i < 0) if (i >= (int)lines || i < 0)
bputs(text[InvalidLineNumber]); bputs(text[InvalidLineNumber]);
...@@ -1556,7 +1556,7 @@ bool sbbs_t::forwardmsg(smb_t* smb, smbmsg_t* orgmsg, const char* to, const char ...@@ -1556,7 +1556,7 @@ bool sbbs_t::forwardmsg(smb_t* smb, smbmsg_t* orgmsg, const char* to, const char
if (comment == NULL) { if (comment == NULL) {
while (online && !msgabort()) { while (online && !msgabort()) {
bputs(text[UeditComment]); bputs(text[UeditComment]);
if (!getstr(str, 70, K_WRAP)) if (!getstr(str, 70, K_WORDWRAP))
break; break;
smb_hfield_string(&msg, SMB_COMMENT, str); smb_hfield_string(&msg, SMB_COMMENT, str);
smb_hfield_string(&msg, SMB_COMMENT, br); smb_hfield_string(&msg, SMB_COMMENT, br);
......
...@@ -181,7 +181,7 @@ typedef int64_t uifc_winmode_t; ...@@ -181,7 +181,7 @@ typedef int64_t uifc_winmode_t;
#define K_UPPER (1 << 0) /* Converts all letters to upper case */ #define K_UPPER (1 << 0) /* Converts all letters to upper case */
#define K_UPRLWR (1 << 1) /* Upper/Lower case automatically */ #define K_UPRLWR (1 << 1) /* Upper/Lower case automatically */
#define K_NUMBER (1 << 2) /* Allow numbers only */ #define K_NUMBER (1 << 2) /* Allow numbers only */
#define K_WRAP (1 << 3) /* Allows word wrap */ #define K_WORDWRAP (1 << 3) /* Allows word wrap */
#define K_MSG (1 << 4) /* Allows ANSI, ^N ^A ^G */ #define K_MSG (1 << 4) /* Allows ANSI, ^N ^A ^G */
#define K_SPIN (1 << 5) /* Spinning cursor (same as SPIN) */ #define K_SPIN (1 << 5) /* Spinning cursor (same as SPIN) */
#define K_LINE (1 << 6) /* Input line (inverse color) */ #define K_LINE (1 << 6) /* Input line (inverse color) */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment