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 <string.h> |
31 #include <ctype.h> |
32 #include <ctype.h> |
32 |
33 |
33 void init_colorpairs() { |
34 void init_colorpairs() { |
34 init_pair(COL_YB, COLOR_YELLOW, COLOR_BLUE); |
35 init_pair(COL_YB, COLOR_YELLOW, COLOR_BLUE); |
35 init_pair(COL_BW, COLOR_BLACK, COLOR_WHITE); |
36 init_pair(COL_BW, COLOR_BLACK, COLOR_WHITE); |
47 echo(); |
48 echo(); |
48 |
49 |
49 return ch == 'y'; |
50 return ch == 'y'; |
50 } |
51 } |
51 |
52 |
52 /** |
53 int mvwasyncgetnstr(WINDOW* w,int y,int x,char *str,size_t *pos,size_t len) { |
53 * Asynchronous variant of getnstr(). |
54 mvwaddnstr(w, y, x, str, *pos); |
54 * |
|
55 * Needs halfdelay mode enabled! |
|
56 * |
|
57 * Warning: you must not call this function for reading into two separate |
|
58 * buffers at the same time. |
|
59 * |
|
60 * Attention: the first byte of the buffer must be zero at the first call, so |
|
61 * the buffer pointer is initialized correctly. |
|
62 * |
|
63 * @param w the window |
|
64 * @param y the window y position |
|
65 * @param x the window x position |
|
66 * @param str the buffer for the read string |
|
67 * @param len the length of the buffer |
|
68 * @return 0 if reading is in progress and 1 when a complete line is read |
|
69 */ |
|
70 int mvwasyncgetnstr(WINDOW* w, int y, int x, char *str, size_t len) { |
|
71 static size_t pos = 0; |
|
72 |
|
73 if (*str == '\0') { |
|
74 memset(str, 0, len); |
|
75 pos = 0; |
|
76 } |
|
77 |
|
78 mvwaddstr(w,y, x, str); |
|
79 wrefresh(w); |
55 wrefresh(w); |
80 int c = wgetch(w); |
56 int c = wgetch(w); |
81 |
57 |
82 if (c != ERR) { |
58 if (c != ERR) { |
83 switch (c) { |
59 switch (c) { |
|
60 case KEY_DOWN: |
84 case '\n': |
61 case '\n': |
85 str[pos] = '\0'; |
62 str[*pos] = '\0'; |
86 pos = 0; |
63 *pos = 0; |
87 return 1; |
64 return 1; |
88 case KEY_BACKSPACE: |
65 case KEY_BACKSPACE: |
89 case KEY_LEFT: |
66 case KEY_LEFT: |
90 str[--pos] = '\0'; |
67 str[--(*pos)] = '\0'; |
91 break; |
68 break; |
92 default: |
69 default: |
93 if (isprint(c) && pos < len-1) { |
70 if (isprint(c) && *pos < len-1) { |
94 str[pos++] = (char) c; |
71 str[(*pos)++] = (char) c; |
95 } |
72 } |
96 } |
73 } |
97 } |
74 } |
98 |
75 |
99 return 0; |
76 return 0; |