From 1e09228b6566d733f75b150078149b0046b46e45 Mon Sep 17 00:00:00 2001 From: piaip Date: Sat, 16 Jul 2005 01:47:40 +0000 Subject: 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 --- include/ansi.h | 3 ++ mbbsd/io.c | 109 +++++++++++++++++++++++++++++++++++++++++---------------- 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 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++; } -- cgit v1.2.3