+static void do_move_cursor(struct app_state *state, int c)
+{
+ uint_fast32_t mask = 1ul << state->cursor;
+
+ if (state->cursor < 0) {
+ /* Reset keyboard cursor to the empty position */
+ state->cursor = 5*state->board.y + state->board.x;
+ }
+
+ switch (c) {
+ case KEY_UP:
+ if ((state->cursor -= 5) < 0)
+ state->cursor += 25;
+ break;
+ case KEY_DOWN:
+ if ((state->cursor += 5) >= 25)
+ state->cursor -= 25;
+ break;
+ case KEY_LEFT:
+ if ((state->cursor -= 1) % 5 == 4 || state->cursor < 0)
+ state->cursor += 5;
+ break;
+ case KEY_RIGHT:
+ if ((state->cursor += 1) % 5 == 0)
+ state->cursor -= 5;
+ break;
+ }
+
+ curs_redraw_game(state, mask | 1ul << state->cursor);
+ refresh();
+}
+
+static void do_keystroke(struct app_state *state, int c)
+{
+ switch (c) {
+ case KEY_DOWN: case KEY_UP: case KEY_LEFT: case KEY_RIGHT:
+ do_move_cursor(state, c);
+ break;
+ case ' ':
+ if (state->cursor >= 0)
+ do_move(state, state->cursor%5, state->cursor/5);
+ break;
+ }
+}
+