Commit fa37e0a7 authored by rswindell's avatar rswindell
Browse files

Fix some cosmetic issues with saveline/restoreline and its interaction with

getstr's insert mode (Ctrl-V) indicator and edit/line modes. Global Hot Keys
(e.g. Ctrl-T) would do weird stuff like return the cursor to the end of the
line or redraw the input string multiple times.
So as part of this fix:
- backspasce() now removed the last count characters from the save-line buffer
  (it is a destructive backspace afterall).
- outchar('\b') (a non-destructive backspace) adds the \b to the save-line buf
- restoreline() now always redraws the current insert/overwrite indicator in
  the upper right-most corner fo the screen
- insert_indicator() now uses functions that aren't line-saved.

An unrelated change included in this comment: center() now sends a CR before
the cursor movement and centered-text, for times when the current column is
*not* already at 0. Very useful for use with @-codes (e.g. display some pattern
or "graphics" and then center some text over it).
parent 65f90289
......@@ -488,8 +488,10 @@ void sbbs_t::backspace(int count)
outcom(' ');
outcom('\b');
}
if(column)
if(column > 0)
column--;
if(lbuflen > 0)
lbuflen--;
}
}
}
......@@ -678,8 +680,11 @@ int sbbs_t::outchar(char ch)
case '\b': // 8
if(column > 0)
column--;
if(lbuflen > 0)
lbuflen--;
if(lbuflen<LINE_BUFSIZE) {
if(lbuflen == 0)
latr = curatr;
lbuf[lbuflen++] = ch;
}
break;
case '\n': // 10
if(lncntr || lastlinelen)
......@@ -762,6 +767,7 @@ void sbbs_t::center(char *instr, unsigned int columns)
SAFECOPY(str,instr);
truncsp(str);
len = bstrlen(str);
carriage_return();
if(len < columns)
cursor_right((columns - len) / 2);
bputs(str);
......@@ -1366,6 +1372,7 @@ struct savedline {
bool sbbs_t::saveline(void)
{
struct savedline line;
lprintf(LOG_DEBUG, "Saving %d chars, cursor at col %d: '%.*s'", lbuflen, column, lbuflen, lbuf);
line.beg_attr = latr;
line.end_attr = curatr;
line.column = column;
......@@ -1380,11 +1387,14 @@ bool sbbs_t::restoreline(void)
struct savedline* line = (struct savedline*)listPopNode(&savedlines);
if(line == NULL)
return false;
lprintf(LOG_DEBUG, "Restoring %d chars, cursor at col %d: '%s'", strlen(line->buf), line->column, line->buf);
lbuflen=0;
attr(line->beg_attr);
rputs(line->buf);
curatr = line->end_attr;
column = line->column;
carriage_return();
cursor_right(line->column);
free(line);
insert_indicator();
return true;
}
......@@ -54,6 +54,7 @@ size_t sbbs_t::getstr(char *strout, size_t maxlen, long mode, const str_list_t h
uint atr;
int hidx = -1;
long org_column = column;
int org_lbuflen = lbuflen;
long term = term_supports();
console&=~(CON_UPARROW|CON_DOWNARROW|CON_LEFTARROW|CON_BACKSPACE|CON_DELETELINE);
......@@ -66,8 +67,9 @@ size_t sbbs_t::getstr(char *strout, size_t maxlen, long mode, const str_list_t h
if(mode&K_LINE && (term&(ANSI|PETSCII)) && !(mode&K_NOECHO)) {
attr(cfg.color[clr_inputline]);
for(i=0;i<maxlen;i++)
outchar(' ');
cursor_left(maxlen);
outcom(' ');
cursor_left(maxlen);
column = org_column;
}
if(wordwrap[0]) {
SAFECOPY(str1,wordwrap);
......@@ -366,7 +368,7 @@ size_t sbbs_t::getstr(char *strout, size_t maxlen, long mode, const str_list_t h
break;
case CTRL_R: /* Ctrl-R Redraw Line */
if(!(mode&K_NOECHO))
redrwstr(str1,i,l,K_GETSTR);
redrwstr(str1,i,l,K_MSG);
break;
case TERM_KEY_INSERT: /* Ctrl-V Toggles Insert/Overwrite */
if(mode&K_NOECHO)
......@@ -426,6 +428,7 @@ size_t sbbs_t::getstr(char *strout, size_t maxlen, long mode, const str_list_t h
cursor_left(i);
cleartoeol();
l=0;
lbuflen = org_lbuflen;
}
i=0;
console|=CON_DELETELINE;
......@@ -704,17 +707,20 @@ long sbbs_t::getnum(ulong max, ulong dflt)
void sbbs_t::insert_indicator(void)
{
if(term_supports(ANSI)) {
char str[32];
long col = column;
ansi_save();
ansi_gotoxy(cols,1);
uint z=curatr; /* and go to EOL */
int tmpatr;
if(console&CON_INSERT) {
attr(BLINK|BLACK|(LIGHTGRAY<<4));
outchar('I');
putcom(ansi_attr(tmpatr = BLINK|BLACK|(LIGHTGRAY<<4), curatr, str, term_supports(COLOR)));
outcom('I');
} else {
attr(LIGHTGRAY);
outchar(' ');
putcom(ansi(tmpatr = ANSI_NORMAL));
outcom(' ');
}
attr(z);
putcom(ansi_attr(curatr, tmpatr, str, term_supports(COLOR)));
ansi_restore();
column = col;
}
}
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