merge #958 and #984

Thu, 03 Sep 2026 11:42:53 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 03 Sep 2026 11:42:53 +0200
changeset 211
141813037e99
parent 210
7ad6c62f6bdc (diff)
parent 209
dc4f34426c66 (current diff)
child 212
16a114c84ff5

merge #958 and #984

src/main.c file | annotate | diff | comparison | revisions
--- a/src/input.c	Wed Sep 02 17:11:56 2026 +0200
+++ b/src/input.c	Thu Sep 03 11:42:53 2026 +0200
@@ -32,7 +32,8 @@
 #include <ctype.h>
 
 int prompt_yesno(char *msg) {
-    printw("%s (y/n)? ", msg);
+    addstr(msg);
+    addstr(" (y/n)? ");
     clrtoeol();
     refresh();
     noecho();
--- a/src/main.c	Wed Sep 02 17:11:56 2026 +0200
+++ b/src/main.c	Thu Sep 03 11:42:53 2026 +0200
@@ -260,20 +260,22 @@
         char clkstr[16];
         bool always_hours = gamestate->info.time >= 3600;
         print_clk(white, clkstr, always_hours);
-        mvprintw(boardy+4, boardx-1, "White time: %s", clkstr);
+        mvaddstr(boardy+4, boardx-1, "White time: ");
+        addstr(clkstr);
         print_clk(black, clkstr, always_hours);
-        mvprintw(boardy+5, boardx-1, "Black time: %s", clkstr);
+        mvaddstr(boardy+5, boardx-1, "Black time: ");
+        addstr(clkstr);
 
         if (white == 0) {
             move(inputy, 0);
-            printw("Time is over - Black wins!");
+            addstr("Time is over - Black wins!");
             clrtobot();
             refresh();
             return 1;
         }
         if (black == 0) {
             move(inputy, 0);
-            printw("Time is over - White wins!");
+            addstr("Time is over - White wins!");
             clrtobot();
             refresh();
             return 1;
@@ -320,7 +322,9 @@
 
             int cy = perspective == WHITE ? boardy-y : boardy-7+y;
             int cx = perspective == WHITE ? boardx+x*3 : boardx+21-x*3;
-            mvprintw(cy, cx, " %s ", piecestr);
+            mvaddch(cy, cx, ' ');
+            addstr(piecestr);
+            addch(' ');
         }
     }
 
@@ -364,43 +368,43 @@
 static void eval_move_failed_msg(int code) {
     switch (code) {
     case AMBIGUOUS_MOVE:
-        printw("Ambiguous move - please specify the piece to move.");
+        addstr("Ambiguous move - please specify the piece to move.");
         break;
     case PIECE_NOT_FOUND:
-        printw("No piece can be moved this way.");
+        addstr("No piece can be moved this way.");
         break;
     case NEED_PROMOTION:
-        printw("You need to promote the pawn (append \"=Q\" e.g.)!");
+        addstr("You need to promote the pawn (append \"=Q\" e.g.)!");
         break;
     case KING_IN_CHECK:
-        printw("Your king is in check!");
+        addstr("Your king is in check!");
         break;
     case PIECE_PINNED:
-        printw("This piece is pinned!");
+        addstr("This piece is pinned!");
         break;
     case INVALID_MOVE_SYNTAX:
-        printw("Can't interpret move - please use algebraic notation.");
+        addstr("Can't interpret move - please use algebraic notation.");
         break;
     case RULES_VIOLATED:
-        printw("Move does not comply with chess rules.");
+        addstr("Move does not comply with chess rules.");
         break;
     case KING_MOVES_INTO_CHECK:
-        printw("Can't move the king into a check position.");
+        addstr("Can't move the king into a check position.");
         break;
     case MISSING_CHECK:
-        printw("Move does not indicate check.");
+        addstr("Move does not indicate check.");
         break;
     case MISSING_CHECKMATE:
-        printw("Move does not indicate checkmate.");
+        addstr("Move does not indicate checkmate.");
         break;
     case INVALID_CHECK:
-        printw("Move incorrectly indicates check.");
+        addstr("Move incorrectly indicates check.");
         break;
     case INVALID_CHECKMATE:
-        printw("Move incorrectly indicates checkmate.");
+        addstr("Move incorrectly indicates checkmate.");
         break;
     default:
-        printw("Unknown move parser error.");
+        addstr("Unknown move parser error.");
     }
 }
 
@@ -431,7 +435,7 @@
 
     bool export_comments = prompt_yesno("Export with comments");
 
-    printw("\rFilename: ");
+    addstr("\rFilename: ");
     clrtoeol();
 
     char filename[64];
@@ -441,7 +445,7 @@
         if (file) {
             write_pgn(file, gamestate, export_comments);
             fclose(file);
-            printw("File saved.");
+            addstr("File saved.");
         } else {
             printw("Can't write to file (%s).", strerror(errno));
         }
@@ -587,23 +591,23 @@
         }
 
         move(inputy, 0);
-        printw("Use chess notation to enter your move.\n");
+        addstr("Use chess notation to enter your move.\n");
         if (resign_suggested) {
             if (remis_suggested) {
-                printw("The opponent asks you to resign or accept remis. \n\n");
+                addstr("The opponent asks you to resign or accept remis. \n\n");
             } else {
-                printw("The opponent asks you to resign.                 \n\n");
+                addstr("The opponent asks you to resign.                 \n\n");
             }
         } else if (remis_suggested) {
-            printw("The opponent offers remis. Type remis to accept. \n\n");
+            addstr("The opponent offers remis. Type remis to accept. \n\n");
         } else if (remis_rejected) {
-            printw("Remis offer rejected.                            \n\n");
+            addstr("Remis offer rejected.                            \n\n");
         } else if (remis_offered) {
-            printw("Remis offer sent.                                \n\n");
+            addstr("Remis offer sent.                                \n\n");
         } else {
-            printw("Or use a command: remis, resign, savepgn         \n\n");
+            addstr("Or use a command: remis, resign, savepgn         \n\n");
         }
-        printw("Type your move: ");
+        addstr("Type your move: ");
         clrtoeol();
 
         /* check if the opponent sent us something */
@@ -630,14 +634,14 @@
                 gamestate->ragequit = true;
                 return 1;
             case NETCODE_ERROR:
-                printw("\rCannot perform asynchronous network IO");
+                addstr("\rCannot perform asynchronous network IO");
                 cbreak(); getch();
                 exit(EXIT_FAILURE);
             case NETCODE_AGAIN:
                 /* try again */
                 break;
             default:
-                printw("\nThe opponent sent an invalid network pacakge.");
+                addstr("\nThe opponent sent an invalid network pacakge.");
         }
 
         /* read move */
@@ -687,14 +691,14 @@
                          */
                         return 0;
                     } else if (code == NETCODE_CONNLOST) {
-                        printw("Your opponent left the game.");
+                        addstr("Your opponent left the game.");
                         return 1;
                     } else {
-                        printw("Invalid network response.");
+                        addstr("Invalid network response.");
                     }
                 } else {
                     if (was_premove) {
-                        printw("\nThe prepared move could not be executed.");
+                        addstr("\nThe prepared move could not be executed.");
                     } else {
                         eval_move_failed_msg(eval_result);
                     }
@@ -716,27 +720,27 @@
         timecontrol(gamestate);
 
         move(inputy, 0);
-        printw("Waiting for opponent. Use chess notation to prepare a move.\n");
+        addstr("Waiting for opponent. Use chess notation to prepare a move.\n");
         if (*gamestate->premove) {
             printw("Current pre-move: %s                             \n",
                 gamestate->premove);
         } else if (remis_suggested && !resign_suggested) {
-            printw("Suggested remis.                                 \n");
+            addstr("Suggested remis.                                 \n");
         } else if (resign_suggested) {
             if (remis_suggested) {
-                printw("Suggested to resign or at least to accept remis. \n");
+                addstr("Suggested to resign or at least to accept remis. \n");
             } else {
-                printw("Suggested to resign.                             \n");
+                addstr("Suggested to resign.                             \n");
             }
         } else {
-            printw("Or use a command: remis, resign, taunt, savepgn  \n");
+            addstr("Or use a command: remis, resign, taunt, savepgn  \n");
         }
         if (remis_offered) {
-            printw("Opponent offered remis. Type 'remis' to accept.\n");
+            addstr("Opponent offered remis. Type 'remis' to accept.\n");
         } else {
-            printw("\n");
+            addch('\n');
         }
-        printw("Prepare your next move: ");
+        addstr("Prepare your next move: ");
         clrtoeol();
         refresh();
 
@@ -872,14 +876,14 @@
             break;
         }
         case NETCODE_ERROR:
-            printw("\rCannot perform asynchronous network IO");
+            addstr("\rCannot perform asynchronous network IO");
             cbreak(); getch();
             exit(EXIT_FAILURE);
         case NETCODE_AGAIN:
             /* try again */
             break;
         default:
-            printw("\nInvalid network request.");
+            addstr("\nInvalid network request.");
         }
     }
 }
@@ -915,10 +919,10 @@
             } else if (gamestate->nomaterial) {
                 addstr("The game is drawn due to insufficient material.\n");
             } else if (gamestate->checkmate) {
-                printw("%s was checkmated.\n",
-                    gamestate->movecount % 2 == 0 ? "White" : "Black");
+                addstr(gamestate->movecount % 2 == 0 ? "White" : "Black");
+                addstr(" was checkmated.\n");
             } else if (gamestate->ragequit) {
-                printw("Your opponent disconnected.\n");
+                addstr("Your opponent disconnected.\n");
             }
             addstr("\nPress 'q' to quit, 's' to save the position as PGN, or\n"
                 "arrow keys, home/end, page up/down to review the game.\n");
@@ -1009,7 +1013,7 @@
     GameInfo *gameinfo = &gamestate->info;
     int serverwhite = gameinfo->servercolor == WHITE;
     attron(A_UNDERLINE);
-    printw("Game details\n");
+    addstr("Game details\n");
     attroff(A_UNDERLINE);
     printw("  Server:     %s\n  Client:     %s\n",
         serverwhite?"White":"Black", serverwhite?"Black":"White"
@@ -1027,7 +1031,7 @@
         }
         addch('\n');
     } else {
-        printw("  No time limit\n");
+        addstr("  No time limit\n");
     }
     addch('\n');
     for (unsigned i = 0 ; i < gamestate->movecount ; i++) {
@@ -1056,7 +1060,7 @@
 }
 
 static int server_open(Server *server) {
-    printw("\nListening for client...\n");
+    addstr("\nListening for client...\n");
     refresh();
     if (settings.usedomainsocket
             ? net_create_sock(server, settings.serverhost)
@@ -1182,7 +1186,7 @@
         return 1;
     }
 
-    printw("Connection established!\n\n");
+    addstr("Connection established!\n\n");
     refresh();
 
     return 0;

mercurial