summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-07-16 09:47:40 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-07-16 09:47:40 +0800
commit1e09228b6566d733f75b150078149b0046b46e45 (patch)
treeccb32380ad1659104b7ef00a24a585520d5518e3
parentabc6c1897ac5c424942693652750d08266b0fd2f (diff)
downloadpttbbs-1e09228b6566d733f75b150078149b0046b46e45.tar
pttbbs-1e09228b6566d733f75b150078149b0046b46e45.tar.gz
pttbbs-1e09228b6566d733f75b150078149b0046b46e45.tar.bz2
pttbbs-1e09228b6566d733f75b150078149b0046b46e45.tar.lz
pttbbs-1e09228b6566d733f75b150078149b0046b46e45.tar.xz
pttbbs-1e09228b6566d733f75b150078149b0046b46e45.tar.zst
pttbbs-1e09228b6566d733f75b150078149b0046b46e45.zip
make getdata support prompt with ANSI escapes.
old code makes correct positioning but wrong attributes git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2933 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--include/ansi.h3
-rw-r--r--mbbsd/io.c109
2 files changed, 81 insertions, 31 deletions
diff --git a/include/ansi.h b/include/ansi.h
index d75df914..faa3b0f8 100644
--- a/include/ansi.h
+++ b/include/ansi.h
@@ -19,6 +19,9 @@
#define ANSI_MOVETO(y,x) ESC_STR "[" #y ";" #x "H"
#define ANSI_CLRTOEND ESC_STR "[K"
+#define ANSI_SAVEPOS ESC_STR "[s"
+#define ANSI_RESTOREPOS ESC_STR "[u"
+
#define ANSI_IN_ESCAPE(x) (((x) >= '0' && (x) <= '9') || \
(x) == ';' || (x) == ',' || (x) == '[')
diff --git a/mbbsd/io.c b/mbbsd/io.c
index c960af22..76fe3065 100644
--- a/mbbsd/io.c
+++ b/mbbsd/io.c
@@ -756,13 +756,15 @@ int getDBCSstatus(unsigned char *s, int pos)
#endif
+#define MAXLASTCMD 12
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;
-#define MAXLASTCMD 12
+ int dirty_line = 0; /* if this line contains ansi escapes,
+ we have to dirty entire line. */
static char lastcmd[MAXLASTCMD][80];
#ifdef DBCSAWARE_GETDATA
@@ -772,10 +774,16 @@ oldgetdata(int line, int col, const char *prompt, char *buf, int len, int echo)
strip_ansi(buf, buf, STRIP_ALL);
if (prompt) {
- move(line, col);
- clrtoeol();
- outs(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);
+ }
}
if (!echo) {
@@ -805,17 +813,40 @@ oldgetdata(int line, int col, const char *prompt, char *buf, int len, int echo)
int cmdpos = 0;
int currchar = 0;
- standout();
- for(i=0; i<len; i++)
- outc(' ');
- standend();
len--;
buf[len] = '\0';
- move(y, x);
- edit_outs(buf);
clen = currchar = strlen(buf);
- while (move(y, x + currchar), (ch = igetch()) != '\r') {
+ if(!dirty_line)
+ {
+ standout();
+ for(i=0; i<=len; i++)
+ outc(' ');
+ standend();
+ move(y, x);
+ edit_outs(buf);
+ }
+
+ while (1) {
+ 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);
+
+ if ((ch = igetch()) == '\r')
+ break;
switch (ch) {
case KEY_DOWN: case Ctrl('N'):
case KEY_UP: case Ctrl('P'):
@@ -827,11 +858,14 @@ oldgetdata(int line, int col, const char *prompt, char *buf, int len, int echo)
cmdpos %= MAXLASTCMD;
strlcpy(buf, lastcmd[cmdpos], len+1);
- move(y, x); /* clrtoeof */
- for (i = 0; i <= clen; i++)
- outc(' ');
- move(y, x);
- edit_outs(buf);
+ if(!dirty_line)
+ {
+ move(y, x); /* clrtoeof */
+ for (i = 0; i <= clen; i++)
+ outc(' ');
+ move(y, x);
+ edit_outs(buf);
+ }
clen = currchar = strlen(buf);
break;
case KEY_LEFT:
@@ -871,13 +905,17 @@ oldgetdata(int line, int col, const char *prompt, char *buf, int len, int echo)
clen -= dbcs_off;
for (i = currchar; i <= clen; i++)
buf[i] = buf[i + dbcs_off];
- move(y, x + clen);
- outc(' ');
+
+ if(!dirty_line)
+ {
+ move(y, x + clen);
+ outc(' ');
#ifdef DBCSAWARE_GETDATA
- while(--dbcs_off > 0) outc(' ');
+ while(--dbcs_off > 0) outc(' ');
#endif
- move(y, x);
- edit_outs(buf);
+ move(y, x);
+ edit_outs(buf);
+ }
}
break;
case Ctrl('Y'):
@@ -885,9 +923,12 @@ oldgetdata(int line, int col, const char *prompt, char *buf, int len, int echo)
case Ctrl('K'):
/* we shoud be able to avoid DBCS issues in ^K mode */
buf[currchar] = '\0';
- move(y, x + currchar);
- for (i = currchar; i < clen; i++)
- outc(' ');
+ if(!dirty_line)
+ {
+ move(y, x + currchar);
+ for (i = currchar; i < clen; i++)
+ outc(' ');
+ }
clen = currchar;
break;
case Ctrl('D'):
@@ -902,13 +943,16 @@ oldgetdata(int line, int col, const char *prompt, char *buf, int len, int echo)
clen -= dbcs_off;
for (i = currchar; i <= clen; i++)
buf[i] = buf[i + dbcs_off];
- move(y, x + clen);
- outc(' ');
+ if(!dirty_line)
+ {
+ move(y, x + clen);
+ outc(' ');
#ifdef DBCSAWARE_GETDATA
- while(--dbcs_off > 0) outc(' ');
+ while(--dbcs_off > 0) outc(' ');
#endif
- move(y, x);
- edit_outs(buf);
+ move(y, x);
+ edit_outs(buf);
+ }
}
break;
case Ctrl('A'):
@@ -947,8 +991,11 @@ 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;
- move(y, x + currchar);
- edit_outs(buf + currchar);
+ if(!dirty_line)
+ {
+ move(y, x + currchar);
+ edit_outs(buf + currchar);
+ }
currchar++;
clen++;
}