--- a/src/main.c Tue Sep 08 14:34:48 2026 +0200 +++ b/src/main.c Tue Sep 08 22:22:01 2026 +0200 @@ -33,6 +33,7 @@ #include <string.h> #include <time.h> #include <locale.h> +#include <ctype.h> #include <sys/stat.h> #include <signal.h> #include <errno.h> @@ -41,9 +42,7 @@ #include "chess/rules.h" #include "chess/pgn.h" -#include "input.h" #include "network.h" -#include "colors.h" typedef struct { /** @@ -250,6 +249,84 @@ return 0; } +#ifdef USE_POSIX_CURSES +#define COL_APP 0 +#else +#define COL_APP 1 +#endif +#define COL_BW 2 +#define COL_WB 3 +#define COL_BB 4 +#define COL_WW 5 + +static void init_colorpairs(void) { +#ifndef USE_POSIX_CURSES + use_default_colors(); + init_pair(COL_APP, -1, -1); +#endif + init_pair(COL_BW, COLOR_BLACK, COLOR_CYAN); + init_pair(COL_BB, COLOR_BLACK, COLOR_BLUE); + init_pair(COL_WB, COLOR_WHITE, COLOR_BLUE); + init_pair(COL_WW, COLOR_WHITE, COLOR_CYAN); +} + +static int prompt_yesno(const char *msg) { + addstr(msg); + addstr(" (y/n)? "); + clrtoeol(); + refresh(); + noecho(); + int ch; + do { + ch = getch(); + } while (ch != 'y' && ch != 'n'); + echo(); + + return ch == 'y'; +} + +static int asyncgetnstr(char *str, size_t *pos, size_t len) { + WINDOW* w = stdscr; + int y, x; + getyx(w, y, x); + mvwaddnstr(w, y, x, str, *pos); + wrefresh(w); + int c = wgetch(w); + + if (c != ERR) { + switch (c) { + case KEY_DOWN: + case '\n': + str[*pos] = '\0'; + *pos = 0; + waddch(w,'\n'); + return 1; + case 127: /* ASCII DEL (important for macOS) */ + case KEY_DC: /* DEL key (for other OS) */ + case KEY_BACKSPACE: + case KEY_LEFT: + if ((*pos) > 0) { + str[--(*pos)] = '\0'; + } + break; + default: + if (isprint(c) && *pos < len-1) { + str[(*pos)++] = (char) c; + } + } + } + + return 0; +} + +static int input_getmaxy(void) { + /* POSIX-curses-compliant wrapper for getmaxy() */ + int x, y; + getmaxyx(stdscr, y, x); + (void)x; + return y; +} + static const uint8_t boardx = 4, boardy = 10; static int inputy = 21; /* should be overridden on game startup */