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

Internal message/line editor improvements

* Allow left and right arrow keys to move between lines (within reason)
* Use the K_USEOFFSET getstr() mode flag to keep cursor position when moving
  between lines with arrow keys
* Be smart about integer padding when /Listing lines with numbers
* Add range checking (!) and better error reporting for /Lx argument value
parent 7fb6c7b4
No related branches found
No related tags found
No related merge requests found
Pipeline #7045 passed
...@@ -1006,7 +1006,12 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title, uint maxlines, u ...@@ -1006,7 +1006,12 @@ 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;
getstr(strin, cols-1, K_WRAP|K_MSG|K_EDIT|K_LEFTEXIT|K_NOCRLF); int kmode = K_WRAP|K_MSG|K_EDIT|K_NOCRLF|K_USEOFFSET;
if(line)
kmode |= K_LEFTEXIT;
if(str[line] != NULL)
kmode |= K_RIGHTEXIT;
getstr(strin, cols-1, kmode);
if((prev_con&CON_DELETELINE) /* Ctrl-X/ZDLE */ && strncmp(strin, "B00", 3) == 0) { if((prev_con&CON_DELETELINE) /* Ctrl-X/ZDLE */ && strncmp(strin, "B00", 3) == 0) {
strin[0] = 0; strin[0] = 0;
prot = 'Z'; prot = 'Z';
...@@ -1017,7 +1022,7 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title, uint maxlines, u ...@@ -1017,7 +1022,7 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title, uint maxlines, u
if(sys_status&SS_ABORT) if(sys_status&SS_ABORT)
continue; continue;
if(console&(CON_UPARROW|CON_BACKSPACE)) { if(console&(CON_UPARROW|CON_LEFTARROW|CON_BACKSPACE)) {
if(console&CON_BACKSPACE && strin[0] == 0) { if(console&CON_BACKSPACE && strin[0] == 0) {
strListRemove(&str, line); strListRemove(&str, line);
for(i = line; str[i]; i++) { for(i = line; str[i]; i++) {
...@@ -1026,6 +1031,8 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title, uint maxlines, u ...@@ -1026,6 +1031,8 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title, uint maxlines, u
newline(); newline();
} }
clearline(); clearline();
if(line)
--line;
cursor_up(i - line); cursor_up(i - line);
continue; continue;
} else if(str[line] == NULL) { } else if(str[line] == NULL) {
...@@ -1046,7 +1053,7 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title, uint maxlines, u ...@@ -1046,7 +1053,7 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title, uint maxlines, u
continue; continue;
} }
newline(); newline();
if(console&CON_DOWNARROW) { if(console & (CON_DOWNARROW | CON_RIGHTARROW)) {
if(str[line] != NULL) { if(str[line] != NULL) {
strListReplace(str, line, strin); strListReplace(str, line, strin);
line++; line++;
...@@ -1136,20 +1143,25 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title, uint maxlines, u ...@@ -1136,20 +1143,25 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title, uint maxlines, u
continue; continue;
} }
else if(toupper(strin[1])=='L') { /* list message */ else if(toupper(strin[1])=='L') { /* list message */
bool linenums = false;
if(str[0] != NULL)
linenums = !noyes(text[WithLineNumbersQ]);
CRLF;
attr(LIGHTGRAY);
putmsg(top, pmode);
if(str[0] == NULL) { if(str[0] == NULL) {
continue; continue;
} }
j=atoi(strin+2); lines = strListCount(str);
if(j) j--; /* start from line j */ j = atoi(strin+2) - 1;
if(j < 0)
j = 0;
if(j >= (int)lines) {
bputs(text[InvalidLineNumber]);
continue;
}
bool linenums = !noyes(text[WithLineNumbersQ]);
CRLF;
attr(LIGHTGRAY);
putmsg(top, pmode);
int digits = DEC_DIGITS(lines);
while(str[j] != NULL && !msgabort()) { while(str[j] != NULL && !msgabort()) {
if(linenums) { /* line numbers */ if(linenums) { /* line numbers */
SAFEPRINTF3(tmp,"%3d: %-.*s", j+1, (int)(cols-6), str[j]); snprintf(tmp, sizeof tmp, "%*d: %-.*s", digits, j+1, (int)(cols-(digits + 3)), str[j]);
putmsg(tmp, pmode); putmsg(tmp, pmode);
} }
else else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment