add prompt whether PGN should be exported with comments

Wed, 29 Apr 2026 17:28:03 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 29 Apr 2026 17:28:03 +0200
changeset 117
ee539a9691f0
parent 116
4bf18d42e7ee
child 118
0f2ffbc408ce

add prompt whether PGN should be exported with comments

resolves #825

src/chess/pgn.c file | annotate | diff | comparison | revisions
src/chess/pgn.h file | annotate | diff | comparison | revisions
src/game.c file | annotate | diff | comparison | revisions
src/input.c file | annotate | diff | comparison | revisions
--- a/src/chess/pgn.c	Tue Apr 28 12:33:22 2026 +0200
+++ b/src/chess/pgn.c	Wed Apr 29 17:28:03 2026 +0200
@@ -196,7 +196,8 @@
     }
 }
 
-void write_pgn(FILE* stream, GameState *gamestate, GameInfo *gameinfo) {
+void write_pgn(FILE* stream, GameState *gamestate, GameInfo *gameinfo,
+        bool export_comments) {
     // TODO: tag pairs
 
     /* Result */
@@ -250,6 +251,11 @@
         }
         moveblkptr += snpr;
 
+        if (!export_comments) {
+            *(moveblkptr++) = ' ';
+            continue;
+        }
+
         /* add clock times when the game was under time control */
         if (gameinfo->timecontrol) {
             memcpy(moveblkptr, " {[%clk ", 8);
--- a/src/chess/pgn.h	Tue Apr 28 12:33:22 2026 +0200
+++ b/src/chess/pgn.h	Wed Apr 29 17:28:03 2026 +0200
@@ -39,7 +39,8 @@
 #endif
     
 int read_pgn(FILE *stream, GameState *gamestate, GameInfo *gameinfo);
-void write_pgn(FILE* stream, GameState *gamestate, GameInfo *gameinfo);
+void write_pgn(FILE* stream, GameState *gamestate, GameInfo *gameinfo,
+        bool export_comments);
 void compute_fen(char *str, GameState *gamestate);
 
 const char* pgn_error_str(int code);
--- a/src/game.c	Tue Apr 28 12:33:22 2026 +0200
+++ b/src/game.c	Wed Apr 29 17:28:03 2026 +0200
@@ -181,7 +181,9 @@
 }
 
 static void save_pgn(GameState *gamestate, GameInfo *gameinfo) {
-    printw("Filename: ");
+    bool export_comments = prompt_yesno("Export with comments");
+
+    printw("\rFilename: ");
     clrtoeol();
     refresh();
     
@@ -191,7 +193,7 @@
         move(y, 0);
         FILE *file = fopen(filename, "w");
         if (file) {
-            write_pgn(file, gamestate, gameinfo);
+            write_pgn(file, gamestate, gameinfo, export_comments);
             fclose(file);
             printw("File saved.");
         } else {
--- a/src/input.c	Tue Apr 28 12:33:22 2026 +0200
+++ b/src/input.c	Wed Apr 29 17:28:03 2026 +0200
@@ -32,6 +32,7 @@
 
 int prompt_yesno(char *msg) {
     printw("%s (y/n)? ", msg);
+    clrtoeol();
     refresh();
     noecho();
     int ch;

mercurial