summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2007-12-20 22:49:42 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2007-12-20 22:49:42 +0800
commit0b01c7c5269e8a5764ad7ed35087097a19000f00 (patch)
tree37dc772b476404f3bd2d2e54c335d982d6fb30ca
parentfbc5dde7a03e9272a3ef0d9cc2eb70ee50b1acc1 (diff)
downloadpttbbs-0b01c7c5269e8a5764ad7ed35087097a19000f00.tar
pttbbs-0b01c7c5269e8a5764ad7ed35087097a19000f00.tar.gz
pttbbs-0b01c7c5269e8a5764ad7ed35087097a19000f00.tar.bz2
pttbbs-0b01c7c5269e8a5764ad7ed35087097a19000f00.tar.lz
pttbbs-0b01c7c5269e8a5764ad7ed35087097a19000f00.tar.xz
pttbbs-0b01c7c5269e8a5764ad7ed35087097a19000f00.tar.zst
pttbbs-0b01c7c5269e8a5764ad7ed35087097a19000f00.zip
-remove standout() API, prepare for pfterm
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3714 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--mbbsd/io.c241
-rw-r--r--mbbsd/name.c154
2 files changed, 163 insertions, 232 deletions
diff --git a/mbbsd/io.c b/mbbsd/io.c
index 9e59c099..7b343b29 100644
--- a/mbbsd/io.c
+++ b/mbbsd/io.c
@@ -678,36 +678,33 @@ int
oldgetdata(int line, int col, const char *prompt, char *buf, int len, int echo)
{
register int ch, i;
- int clen;
- int x = col, y = line;
- int dirty_line = 0; /* if this line contains ansi escapes,
- we have to dirty entire line. */
+ int clen, lprompt = 0;
+ int cx = col, cy = line;
static char lastcmd[MAXLASTCMD][80];
- unsigned char occupy_msg = 0;
+ unsigned char occupy_msg = 0;
#ifdef DBCSAWARE
unsigned int dbcsincomplete = 0;
#endif
strip_ansi(buf, buf, STRIP_ALL);
+ if (prompt)
+ {
+ lprompt = strlen_noansi(prompt);
+ cx += lprompt;
+ }
if(line == b_lines-msg_occupied)
occupy_msg=1, msg_occupied ++;
- if (prompt) {
- x += strip_ansi(NULL, prompt, STRIP_ALL);
- if(strlen(prompt) + col != x)
- dirty_line = 1;
-
- if(!echo || !dirty_line)
- {
- move(line, col);
- clrtoeol();
- outs(prompt);
- }
- }
+ // workaround poor terminal
+ move_ansi(line, col);
+ getyx(&line, &col);
+ // (line, col) are real starting address
+
if (!echo) {
+ if (prompt) outs(prompt);
len--;
clen = 0;
while ((ch = igetch()) != '\r') {
@@ -720,9 +717,11 @@ oldgetdata(int line, int col, const char *prompt, char *buf, int len, int echo)
continue;
}
if (ch>=0x100 || !isprint(ch)) {
+ bell();
continue;
}
if (clen >= len) {
+ bell();
continue;
}
buf[clen++] = ch;
@@ -738,165 +737,116 @@ oldgetdata(int line, int col, const char *prompt, char *buf, int len, int echo)
buf[len] = '\0';
clen = currchar = strlen(buf);
- if(!dirty_line)
- {
- standout();
- for(i=0; i<=len; i++)
- outc(' ');
- standend();
- move(y, x);
- edit_outs(buf);
- }
-
while (1) {
- assert(0<=clen);
- if(dirty_line) {
- move(line, col);
- clrtoeol();
- outs(prompt);
- standout();
- for(i=0; i<=len; i++)
- {
- if(i < clen)
- outc(buf[i]);
- else
- outc(' ');
- }
- // edit_outs(buf);
- standend();
- }
- move(y, x + currchar);
+ // refresh from prompt
+ move(line, col); outc(' '); move(line, col); clrtoeol();
+ if (prompt) outs(prompt);
+
+ outs(ANSI_COLOR(7));
+ outs(buf);
+ for(i=clen; i<=len; i++)
+ outc(' ');
+ outs(ANSI_RESET);
+ move(cy, cx + currchar);
if ((ch = igetch()) == '\r')
break;
- assert(0<=clen);
+
switch (ch) {
- case KEY_DOWN: case Ctrl('N'):
- case KEY_UP: case Ctrl('P'):
- strlcpy(lastcmd[cmdpos], buf, sizeof(lastcmd[0]));
- if (ch == KEY_UP || ch == Ctrl('P'))
- cmdpos++;
- else
- cmdpos += MAXLASTCMD - 1;
- cmdpos %= MAXLASTCMD;
- strlcpy(buf, lastcmd[cmdpos], len+1);
+ case Ctrl('A'):
+ case KEY_HOME:
+ currchar = 0;
+ break;
- if(!dirty_line)
- {
- move(y, x); /* clrtoeof */
- for (i = 0; i <= clen; i++)
- outc(' ');
- move(y, x);
- edit_outs(buf);
- }
- clen = currchar = strlen(buf);
+ case Ctrl('E'):
+ case KEY_END:
+ currchar = clen;
+ break;
+
+ case KEY_UNKNOWN:
break;
+
case KEY_LEFT:
- if (currchar > 0)
- {
- --currchar;
+ if (currchar <= 0)
+ break;
+ --currchar;
#ifdef DBCSAWARE
- if(currchar > 0 &&
- ISDBCSAWARE() &&
- getDBCSstatus((unsigned char*)buf, currchar) == DBCS_TRAILING)
- currchar --;
+ if(currchar > 0 && ISDBCSAWARE() &&
+ getDBCSstatus((unsigned char*)buf, currchar) == DBCS_TRAILING)
+ currchar --;
#endif
- }
- assert(0<=clen);
break;
+
case KEY_RIGHT:
- if (buf[currchar])
- {
- ++currchar;
+ if (!buf[currchar])
+ break;
+ ++currchar;
#ifdef DBCSAWARE
- if(buf[currchar] &&
- ISDBCSAWARE() &&
- getDBCSstatus((unsigned char*)buf, currchar) == DBCS_TRAILING)
- currchar++;
+ if(buf[currchar] && ISDBCSAWARE() &&
+ getDBCSstatus((unsigned char*)buf, currchar) == DBCS_TRAILING)
+ currchar++;
#endif
- }
- assert(0<=clen);
break;
- case '\177':
- case Ctrl('H'):
- if (currchar) {
-#ifdef DBCSAWARE
- int dbcs_off = 1;
- if (ISDBCSAWARE() &&
- getDBCSstatus((unsigned char*)buf, currchar-1) == DBCS_TRAILING)
- dbcs_off = 2;
-#endif
- currchar -= dbcs_off;
- clen -= dbcs_off;
- for (i = currchar; i <= clen; i++)
- buf[i] = buf[i + dbcs_off];
- if(!dirty_line)
- {
- move(y, x + clen);
- outc(' ');
-#ifdef DBCSAWARE
- while(--dbcs_off > 0) outc(' ');
-#endif
- move(y, x);
- edit_outs(buf);
- }
- }
- break;
case Ctrl('Y'):
currchar = 0;
case Ctrl('K'):
/* we shoud be able to avoid DBCS issues in ^K mode */
buf[currchar] = '\0';
- if(!dirty_line)
+ clen = currchar;
+ break;
+
+ case KEY_DOWN: case Ctrl('N'):
+ case KEY_UP: case Ctrl('P'):
+ strlcpy(lastcmd[cmdpos], buf, sizeof(lastcmd[0]));
+ if (ch == KEY_UP || ch == Ctrl('P'))
+ cmdpos++;
+ else
+ cmdpos += MAXLASTCMD - 1;
+ cmdpos %= MAXLASTCMD;
+ strlcpy(buf, lastcmd[cmdpos], len+1);
+ clen = currchar = strlen(buf);
+ break;
+
+ case '\177':
+ case Ctrl('H'):
+ if (!currchar)
+ break;
+#ifdef DBCSAWARE
+ if (ISDBCSAWARE() && getDBCSstatus((unsigned char*)buf,
+ currchar-1) == DBCS_TRAILING)
{
- move(y, x + currchar);
- for (i = currchar; i < clen; i++)
- outc(' ');
+ memmove(buf+currchar-1, buf+currchar, clen-currchar+1);
+ currchar--, clen--;
}
- clen = currchar;
+#endif
+ memmove(buf+currchar-1, buf+currchar, clen-currchar+1);
+ currchar--, clen--;
break;
+
case Ctrl('D'):
case KEY_DEL:
- if (buf[currchar]) {
-#ifdef DBCSAWARE
- int dbcs_off = 1;
- if (ISDBCSAWARE() && buf[currchar+1] &&
- getDBCSstatus((unsigned char*)buf, currchar+1) == DBCS_TRAILING)
- dbcs_off = 2;
-#endif
- clen -= dbcs_off;
- for (i = currchar; i <= clen; i++)
- buf[i] = buf[i + dbcs_off];
- if(!dirty_line)
- {
- move(y, x + clen);
- outc(' ');
+ if (!buf[currchar])
+ break;
#ifdef DBCSAWARE
- while(--dbcs_off > 0) outc(' ');
-#endif
- move(y, x);
- edit_outs(buf);
- }
+ if (ISDBCSAWARE() && buf[currchar+1] && getDBCSstatus(
+ (unsigned char*)buf, currchar+1) == DBCS_TRAILING)
+ {
+ memmove(buf+currchar, buf+currchar+1, clen-currchar);
+ clen --;
}
+#endif
+ memmove(buf+currchar, buf+currchar+1, clen-currchar);
+ clen --;
break;
- case Ctrl('A'):
- case KEY_HOME:
- currchar = 0;
- break;
- case Ctrl('E'):
- case KEY_END:
- currchar = clen;
- break;
- case KEY_UNKNOWN:
- break;
+
default:
if (echo == NUMECHO && !isdigit(ch))
{
bell();
break;
}
- if (isprint2(ch) && clen < len && x + clen < scr_cols) {
+ if (isprint2(ch) && clen < len && cx + clen < scr_cols) {
#ifdef DBCSAWARE
if(ISDBCSAWARE())
{
@@ -923,11 +873,6 @@ oldgetdata(int line, int col, const char *prompt, char *buf, int len, int echo)
for (i = clen + 1; i > currchar; i--)
buf[i] = buf[i - 1];
buf[currchar] = ch;
- if(!dirty_line)
- {
- move(y, x + currchar);
- edit_outs(buf + currchar);
- }
currchar++;
clen++;
}
@@ -942,11 +887,13 @@ oldgetdata(int line, int col, const char *prompt, char *buf, int len, int echo)
}
/* why return here? because some code then outs.*/
// outc('\n');
- move(y+1, 0);
+ move(line+1, 0);
refresh();
+
assert(0<=currchar && currchar<=clen);
assert(0<=clen && clen<=len);
}
+
if ((echo == LCECHO) && isupper((int)buf[0]))
buf[0] = tolower(buf[0]);
diff --git a/mbbsd/name.c b/mbbsd/name.c
index f427378e..0f2b1ef4 100644
--- a/mbbsd/name.c
+++ b/mbbsd/name.c
@@ -405,7 +405,7 @@ namecomplete(const char *prompt, char *data)
{
char *temp;
word_t *cwlist, *morelist;
- int x, y, origx, origy;
+ int x, y, origx, scrx;
int ch;
int count = 0;
int clearbot = NA;
@@ -419,13 +419,22 @@ namecomplete(const char *prompt, char *data)
outs(prompt);
clrtoeol();
getyx(&y, &x);
- standout();
- prints("%*s", IDLEN + 1, "");
- standend();
- move(y, x);
- origy = y; origx = x;
+ scrx = origx = x;
+ data[count] = 0;
+
+ while (1)
+ {
+ // print input field again
+ move(y, scrx); outc(' '); clrtoeol(); move(y, scrx);
+ outs(ANSI_COLOR(7));
+ prints("%-*s", IDLEN + 1, data);
+ outs(ANSI_RESET);
+ move(y, scrx + count);
+
+ // get input
+ if ((ch = igetch()) == EOF)
+ break;
- while ((ch = igetch()) != EOF) {
if (ch == '\n' || ch == '\r') {
*temp = '\0';
// outc('\n');
@@ -441,11 +450,8 @@ namecomplete(const char *prompt, char *data)
if (NumInList(cwlist) == 1) {
strcpy(data, cwlist->word);
- move(y, x);
- outs(data + count);
count = strlen(data);
temp = data + count;
- getyx(&y, &x);
continue;
}
clearbot = YEA;
@@ -472,7 +478,6 @@ namecomplete(const char *prompt, char *data)
if (morelist) {
vmsg(msg_more);
}
- move(y, x);
continue;
}
if (ch == '\177' || ch == '\010') {
@@ -484,10 +489,6 @@ namecomplete(const char *prompt, char *data)
ClearSubList(cwlist);
cwlist = GetSubList(data, toplev);
morelist = NULL;
- x--;
- move(y, x);
- outc(' ');
- move(y, x);
continue;
}
if (count < STRLEN && isprint(ch)) {
@@ -506,9 +507,6 @@ namecomplete(const char *prompt, char *data)
ClearSubList(cwlist);
cwlist = node;
morelist = NULL;
- move(y, x);
- outc(ch);
- x++;
}
}
if (ch == EOF)
@@ -521,7 +519,7 @@ namecomplete(const char *prompt, char *data)
clrtobot();
}
if (*data) {
- move(origy, origx);
+ move(y, origx);
outs(data);
outc('\n');
}
@@ -531,7 +529,7 @@ void
namecomplete2(struct NameList *namelist, const char *prompt, char *data)
{
char *temp;
- int x, y, origx, origy;
+ int x, y, origx, scrx;
int ch;
int count = 0;
int clearbot = NA;
@@ -546,14 +544,23 @@ namecomplete2(struct NameList *namelist, const char *prompt, char *data)
outs(prompt);
clrtoeol();
getyx(&y, &x);
- standout();
- prints("%*s", IDLEN + 1, "");
- standend();
- move(y, x);
- origy = y; origx = x;
+ scrx = origx = x;
+ data[count] = 0;
viewoffset = 0;
- while ((ch = igetch()) != EOF) {
+ while (1)
+ {
+ // print input field
+ move(y, scrx); outc(' '); clrtoeol(); move(y, scrx);
+ outs(ANSI_COLOR(7));
+ prints("%-*s", IDLEN + 1, data);
+ outs(ANSI_RESET);
+ move(y, scrx + count);
+
+ // get input
+ if ((ch = igetch()) == EOF)
+ break;
+
if (ch == '\n' || ch == '\r') {
*temp = '\0';
if (NameList_length(&sublist)==1)
@@ -568,11 +575,8 @@ namecomplete2(struct NameList *namelist, const char *prompt, char *data)
if (NameList_length(&sublist) == 1) {
strcpy(data, NameList_get(&sublist, 0));
- move(y, x);
- outs(data + count);
count = strlen(data);
temp = data + count;
- getyx(&y, &x);
continue;
}
clearbot = YEA;
@@ -599,7 +603,6 @@ namecomplete2(struct NameList *namelist, const char *prompt, char *data)
if (viewoffset < NameList_length(&sublist)) {
vmsg(msg_more);
}
- move(y, x);
continue;
}
if (ch == '\177' || ch == '\010') {
@@ -610,10 +613,6 @@ namecomplete2(struct NameList *namelist, const char *prompt, char *data)
*temp = '\0';
NameList_sublist(namelist, &sublist, data);
viewoffset = 0;
- x--;
- move(y, x);
- outc(' ');
- move(y, x);
continue;
}
if (count < STRLEN && isprint(ch)) {
@@ -635,9 +634,6 @@ namecomplete2(struct NameList *namelist, const char *prompt, char *data)
NameList_delete(&sublist);
sublist = tmplist;
viewoffset = 0;
- move(y, x);
- outc(ch);
- x++;
}
}
if (ch == EOF)
@@ -650,7 +646,7 @@ namecomplete2(struct NameList *namelist, const char *prompt, char *data)
clrtobot();
}
if (*data) {
- move(origy, origx);
+ move(y, origx);
outs(data);
outc('\n');
}
@@ -661,7 +657,7 @@ usercomplete(const char *prompt, char *data)
{
char *temp;
char *cwbuf, *cwlist;
- int cwnum, x, y, origx, origy;
+ int cwnum, x, y, origx, scrx;
int clearbot = NA, count = 0, morenum = 0;
char ch;
int dashdirty = 0;
@@ -674,13 +670,21 @@ usercomplete(const char *prompt, char *data)
outs(prompt);
clrtoeol();
getyx(&y, &x);
- standout();
- prints("%*s", IDLEN + 1, "");
- standend();
- move(y, x);
- origy = y; origx = x;
-
- while ((ch = igetch()) != EOF) {
+ scrx = origx = x;
+ data[count] = 0;
+
+ while (1)
+ {
+ // print input field again
+ move(y, scrx); outc(' '); clrtoeol(); move(y, scrx);
+ outs(ANSI_COLOR(7));
+ prints("%-*s", IDLEN + 1, data);
+ outs(ANSI_RESET);
+ move(y, scrx + count);
+
+ // get input
+ if ((ch = igetch()) == EOF)
+ break;
if (ch == '\n' || ch == '\r') {
int i;
@@ -708,10 +712,6 @@ usercomplete(const char *prompt, char *data)
*temp = '\0';
cwlist = u_namearray((arrptr) cwbuf, &cwnum, data);
morenum = 0;
- x--;
- move(y, x);
- outc(' ');
- move(y, x);
continue;
} else if (!(count <= IDLEN && isprint((int)ch))) {
@@ -733,10 +733,6 @@ usercomplete(const char *prompt, char *data)
count++;
cwnum = n;
morenum = 0;
- move(y, x);
- outc(ch);
- x++;
-
continue;
}
/* no break, no continue, list later. */
@@ -754,11 +750,8 @@ usercomplete(const char *prompt, char *data)
printdash(cwlist, 0);
}
strcpy(data, cwlist);
- move(y, x);
- outs(data + count);
count = strlen(data);
temp = data + count;
- getyx(&y, &x);
continue;
}
@@ -804,8 +797,6 @@ usercomplete(const char *prompt, char *data)
} else
morenum = 0;
- move(y, x);
-
continue;
}
}
@@ -819,7 +810,7 @@ usercomplete(const char *prompt, char *data)
clrtobot();
}
if (*data) {
- move(origy, origx);
+ move(y, origx);
outs(data);
outc('\n');
}
@@ -893,24 +884,33 @@ generalnamecomplete(const char *prompt, char *data, int len, size_t nmemb,
gnc_comp_func compar, gnc_perm_func permission,
gnc_getname_func getname)
{
- int x, y, origx, origy, ch, i, morelist = -1, col, ret = -1;
+ int x, y, origx, scrx, ch, i, morelist = -1, col, ret = -1;
int start, end, ptr;
int clearbot = NA;
outs(prompt);
clrtoeol();
getyx(&y, &x);
- standout();
- prints("%*s", IDLEN + 1, "");
- standend();
- move(y, x);
- origy = y; origx = x;
+ scrx = origx = x;
ptr = 0;
data[ptr] = 0;
start = 0; end = nmemb - 1;
- while ((ch = igetch()) != EOF) {
+ while (1)
+ {
+ // print input field again
+ move(y, scrx); outc(' '); clrtoeol(); move(y, scrx);
+ outs(ANSI_COLOR(7));
+ // data[ptr] = 0;
+ prints("%-*s", len, data);
+ outs(ANSI_RESET);
+ move(y, scrx + ptr);
+
+ // get input
+ if ((ch = igetch()) == EOF)
+ break;
+
if (ch == '\n' || ch == '\r') {
data[ptr] = 0;
outc('\n');
@@ -933,10 +933,7 @@ generalnamecomplete(const char *prompt, char *data, int len, size_t nmemb,
continue;
i = gnc_complete(data, &start, &end, permission, getname);
if (i == 1) {
- move(origy, origx);
- outs(data);
ptr = strlen(data);
- getyx(&y, &x);
continue;
} else {
char* first = (*getname)(start);
@@ -948,9 +945,6 @@ generalnamecomplete(const char *prompt, char *data, int len, size_t nmemb,
data[i] = '\0';
if (i != ptr) { /* did complete several words */
- move(y, x);
- outs(data + ptr);
- getyx(&y, &x);
ptr = i;
}
}
@@ -963,7 +957,7 @@ generalnamecomplete(const char *prompt, char *data, int len, size_t nmemb,
printdash("相關資訊一覽表", 0);
col = 0;
- while (len + col < 79) {
+ while (len + col < t_columns-1) {
for (i = 0; morelist <= end && i < p_lines; ++morelist) {
if ((*permission)(morelist)) {
move(3 + i, col);
@@ -977,7 +971,6 @@ generalnamecomplete(const char *prompt, char *data, int len, size_t nmemb,
if (morelist != end + 1) {
vmsg(msg_more);
}
- move(y, x);
continue;
} else if (ch == '\177' || ch == '\010') { /* backspace */
@@ -985,11 +978,7 @@ generalnamecomplete(const char *prompt, char *data, int len, size_t nmemb,
continue;
morelist = -1;
--ptr;
- --x;
data[ptr] = 0;
- move(y, x);
- outc(' ');
- move(y, x);
continue;
} else if (isprint(ch) && ptr <= (len - 2)) {
morelist = -1;
@@ -1004,11 +993,6 @@ generalnamecomplete(const char *prompt, char *data, int len, size_t nmemb,
break;
if (i == end + 1)
data[--ptr] = 0;
- else {
- move(y, x);
- outc(ch);
- x++;
- }
}
}
}
@@ -1019,7 +1003,7 @@ generalnamecomplete(const char *prompt, char *data, int len, size_t nmemb,
clrtobot();
}
if (*data) {
- move(origy, origx);
+ move(y, origx);
outs(data);
outc('\n');
}