/****************************************************************************
- * Copyright (c) 2002 Free Software Foundation, Inc. *
+ * Copyright (c) 2002,2003 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
#include <curses.priv.h>
#include <term.h>
-MODULE_ID("$Id: lib_get_wstr.c,v 1.4 2002/07/20 19:28:29 tom Exp $")
+MODULE_ID("$Id: lib_get_wstr.c,v 1.6 2003/05/17 21:33:03 tom Exp $")
/*
* This wipes out the last character, no matter whether it was a tab, control
wrefresh(win);
while ((code = wget_wch(win, &ch)) != ERR) {
+ /*
+ * Map special characters into key-codes.
+ */
+ if (ch == '\r')
+ ch = '\n';
+ if (ch == '\n') {
+ code = KEY_CODE_YES;
+ ch = KEY_ENTER;
+ }
+ if (ch < KEY_MIN) {
+ if (ch == erasec) {
+ ch = KEY_BACKSPACE;
+ code = KEY_CODE_YES;
+ }
+ if (ch == killc) {
+ ch = KEY_EOL;
+ code = KEY_CODE_YES;
+ }
+ }
if (code == KEY_CODE_YES) {
/*
* Some terminals (the Wyse-50 is the most common) generate a \n
* choice whether to set kcud=\n for wget_wch(); terminating
* *getn_wstr() with \n should work either way.
*/
- if (ch == '\n'
- || ch == '\r'
- || ch == KEY_DOWN
- || ch == KEY_ENTER) {
+ if (ch == KEY_DOWN || ch == KEY_ENTER) {
if (oldecho == TRUE
&& win->_cury == win->_maxy
&& win->_scroll)
wechochar(win, (chtype) '\n');
break;
}
- if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) {
+ if (ch == KEY_LEFT || ch == KEY_BACKSPACE) {
if (tmpstr > oldstr) {
tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
}
- } else if (ch == killc) {
+ } else if (ch == KEY_EOL) {
while (tmpstr > oldstr) {
tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
}
beep();
} else {
*tmpstr++ = ch;
+ *tmpstr = 0;
if (oldecho == TRUE) {
int oldy = win->_cury;
cchar_t tmp;
*tmpstr = 0;
if (code == ERR) {
if (tmpstr == oldstr) {
- *tmpstr++ = (wchar_t)WEOF;
+ *tmpstr++ = (wchar_t) WEOF;
*tmpstr = 0;
}
returnCode(ERR);