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