1
0
mirror of https://git.zap.org.au/git/trader.git synced 2024-12-04 14:46:45 -05:00

Use chstr-style output functions in gettxline()

This commit is contained in:
John Zaitseff 2011-08-16 20:45:47 +10:00
parent de6a4e3e66
commit d20cc2b5ec

View File

@ -1484,9 +1484,12 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool *restrict modified,
const char *allowed, bool stripspc, int y, int x, int width, const char *allowed, bool stripspc, int y, int x, int width,
chtype attr) chtype attr)
{ {
int len, pos, cpos, nb, ret; int len, pos, cpos, ret;
bool done, redraw, mod; bool done, redraw, mod;
int key, key2; int key, key2;
chtype oldattr;
chtype *chbuf;
int chbufwidth;
assert(win != NULL); assert(win != NULL);
@ -1494,17 +1497,13 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool *restrict modified,
assert(bufsize > 2); assert(bufsize > 2);
assert(width > 1); assert(width > 1);
chbuf = xmalloc(BUFSIZE * sizeof(chtype));
keypad(win, true); keypad(win, true);
meta(win, true); meta(win, true);
wtimeout(win, -1); wtimeout(win, -1);
chtype oldattr = getattrs(win); oldattr = getattrs(win);
chtype oldbkgd = getbkgd(win);
/* Note that wattrset() will override parts of wbkgdset() and vice
versa: don't swap the order of these two lines! */
wbkgdset(win, (oldbkgd & A_COLOR) | A_NORMAL);
wattrset(win, attr & ~A_CHARTEXT);
curs_set(CURS_ON); curs_set(CURS_ON);
len = strlen(buf); len = strlen(buf);
@ -1522,16 +1521,11 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool *restrict modified,
Blanks at the end of the input area are replaced with Blanks at the end of the input area are replaced with
"attr", which may contain a '_' for non-colour mode. "attr", which may contain a '_' for non-colour mode.
*/ */
mvwprintw(win, y, x, "%-*.*s", width, width, buf + pos - cpos); mvwhline(win, y, x, ((attr & A_CHARTEXT) == 0) ?
' ' | attr : attr, width);
// nb = number of blanks mkchstr(chbuf, BUFSIZE, attr & ~A_CHARTEXT, 0, 0, 1, width,
nb = (len - (pos - cpos) > width) ? 0 : width - (len - (pos - cpos)); &chbufwidth, 1, "%s", buf + pos - cpos);
wmove(win, y, x + width - nb); leftch(win, y, x, chbuf, 1, &chbufwidth);
chtype ch = ((attr & A_CHARTEXT) == 0) ? attr | ' ' : attr;
for (int i = 0; i < nb; i++) {
waddch(win, ch);
}
wmove(win, y, x + cpos); wmove(win, y, x + cpos);
wrefresh(win); wrefresh(win);
@ -2107,16 +2101,17 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool *restrict modified,
curs_set(CURS_OFF); curs_set(CURS_OFF);
wattrset(win, oldattr | A_BOLD); mvwhline(win, y, x, ' ' | oldattr, width);
mvwprintw(win, y, x, "%-*.*s", width, width, buf); mkchstr(chbuf, BUFSIZE, oldattr | A_BOLD, 0, 0, 1, width,
&chbufwidth, 1, "%s", buf);
wbkgdset(win, oldbkgd); leftch(win, y, x, chbuf, 1, &chbufwidth);
wattrset(win, oldattr);
wrefresh(win); wrefresh(win);
if (modified != NULL) { if (modified != NULL) {
*modified = mod; *modified = mod;
} }
free(chbuf);
return ret; return ret;
} }