| 246 } else { |
245 } else { |
| 247 settings.ishost = !settings.serverhost; |
246 settings.ishost = !settings.serverhost; |
| 248 } |
247 } |
| 249 |
248 |
| 250 return 0; |
249 return 0; |
| |
250 } |
| |
251 |
| |
252 #ifdef USE_POSIX_CURSES |
| |
253 #define COL_APP 0 |
| |
254 #else |
| |
255 #define COL_APP 1 |
| |
256 #endif |
| |
257 #define COL_BW 2 |
| |
258 #define COL_WB 3 |
| |
259 #define COL_BB 4 |
| |
260 #define COL_WW 5 |
| |
261 |
| |
262 static void init_colorpairs(void) { |
| |
263 #ifndef USE_POSIX_CURSES |
| |
264 use_default_colors(); |
| |
265 init_pair(COL_APP, -1, -1); |
| |
266 #endif |
| |
267 init_pair(COL_BW, COLOR_BLACK, COLOR_CYAN); |
| |
268 init_pair(COL_BB, COLOR_BLACK, COLOR_BLUE); |
| |
269 init_pair(COL_WB, COLOR_WHITE, COLOR_BLUE); |
| |
270 init_pair(COL_WW, COLOR_WHITE, COLOR_CYAN); |
| |
271 } |
| |
272 |
| |
273 static int prompt_yesno(const char *msg) { |
| |
274 addstr(msg); |
| |
275 addstr(" (y/n)? "); |
| |
276 clrtoeol(); |
| |
277 refresh(); |
| |
278 noecho(); |
| |
279 int ch; |
| |
280 do { |
| |
281 ch = getch(); |
| |
282 } while (ch != 'y' && ch != 'n'); |
| |
283 echo(); |
| |
284 |
| |
285 return ch == 'y'; |
| |
286 } |
| |
287 |
| |
288 static int asyncgetnstr(char *str, size_t *pos, size_t len) { |
| |
289 WINDOW* w = stdscr; |
| |
290 int y, x; |
| |
291 getyx(w, y, x); |
| |
292 mvwaddnstr(w, y, x, str, *pos); |
| |
293 wrefresh(w); |
| |
294 int c = wgetch(w); |
| |
295 |
| |
296 if (c != ERR) { |
| |
297 switch (c) { |
| |
298 case KEY_DOWN: |
| |
299 case '\n': |
| |
300 str[*pos] = '\0'; |
| |
301 *pos = 0; |
| |
302 waddch(w,'\n'); |
| |
303 return 1; |
| |
304 case 127: /* ASCII DEL (important for macOS) */ |
| |
305 case KEY_DC: /* DEL key (for other OS) */ |
| |
306 case KEY_BACKSPACE: |
| |
307 case KEY_LEFT: |
| |
308 if ((*pos) > 0) { |
| |
309 str[--(*pos)] = '\0'; |
| |
310 } |
| |
311 break; |
| |
312 default: |
| |
313 if (isprint(c) && *pos < len-1) { |
| |
314 str[(*pos)++] = (char) c; |
| |
315 } |
| |
316 } |
| |
317 } |
| |
318 |
| |
319 return 0; |
| |
320 } |
| |
321 |
| |
322 static int input_getmaxy(void) { |
| |
323 /* POSIX-curses-compliant wrapper for getmaxy() */ |
| |
324 int x, y; |
| |
325 getmaxyx(stdscr, y, x); |
| |
326 (void)x; |
| |
327 return y; |
| 251 } |
328 } |
| 252 |
329 |
| 253 static const uint8_t boardx = 4, boardy = 10; |
330 static const uint8_t boardx = 4, boardy = 10; |
| 254 static int inputy = 21; /* should be overridden on game startup */ |
331 static int inputy = 21; /* should be overridden on game startup */ |
| 255 |
332 |