src/input.c

changeset 31
ed440bcd9740
parent 30
a285ee393860
child 32
8a0b85303ee8
equal deleted inserted replaced
30:a285ee393860 31:ed440bcd9740
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 * 27 *
28 */ 28 */
29 29
30 #include "input.h" 30 #include "input.h"
31 #include <ctype.h>
31 32
32 void init_colorpairs() { 33 void init_colorpairs() {
33 init_pair(COL_YB, COLOR_YELLOW, COLOR_BLUE); 34 init_pair(COL_YB, COLOR_YELLOW, COLOR_BLUE);
34 init_pair(COL_BW, COLOR_BLACK, COLOR_WHITE); 35 init_pair(COL_BW, COLOR_BLACK, COLOR_WHITE);
35 init_pair(COL_WB, COLOR_WHITE, COLOR_BLACK); 36 init_pair(COL_WB, COLOR_WHITE, COLOR_BLACK);
68 */ 69 */
69 int mvwasyncgetnstr(WINDOW* w, int y, int x, char *str, size_t len) { 70 int mvwasyncgetnstr(WINDOW* w, int y, int x, char *str, size_t len) {
70 static size_t pos = 0; 71 static size_t pos = 0;
71 72
72 if (*str == '\0') { 73 if (*str == '\0') {
74 memset(str, 0, len);
73 pos = 0; 75 pos = 0;
74 } 76 }
75 77
76 mvwaddstr(w,y, x, str); 78 mvwaddstr(w,y, x, str);
77 wrefresh(w); 79 wrefresh(w);
86 case KEY_BACKSPACE: 88 case KEY_BACKSPACE:
87 case KEY_LEFT: 89 case KEY_LEFT:
88 str[--pos] = '\0'; 90 str[--pos] = '\0';
89 break; 91 break;
90 default: 92 default:
91 if (c < 255 && pos < len-1) { 93 if (isprint(c) && pos < len-1) {
92 str[pos++] = (char) c; 94 str[pos++] = (char) c;
93 } 95 }
94 } 96 }
95 } 97 }
96 98

mercurial