slightly improve ascii output for colored squares and highlighted squares - chess-puzzles - chess puzzle book generator
 (HTM) git clone git://git.codemadness.org/chess-puzzles
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit b55e73ad95fbbe333cdac344ca25a84dc61151b0
 (DIR) parent 64c4e3aaecf348c2cb7c61f5569cae1a820d20db
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Wed, 20 Dec 2023 21:07:30 +0100
       
       slightly improve ascii output for colored squares and highlighted squares
       
       Diffstat:
         M fen_to_svg.c                        |      29 +++++++++++++++++++++--------
       
       1 file changed, 21 insertions(+), 8 deletions(-)
       ---
 (DIR) diff --git a/fen_to_svg.c b/fen_to_svg.c
       @@ -5,6 +5,7 @@
        #include <stdlib.h>
        #include <string.h>
        
       +/* macro for truecolor RGB output to tty */
        #define SETFGCOLOR(r,g,b)    printf("\x1b[38;2;%d;%d;%dm", r, g, b)
        #define SETBGCOLOR(r,g,b)    printf("\x1b[48;2;%d;%d;%dm", r, g, b)
        
       @@ -352,12 +353,13 @@ fen_showboard(void)
        }
        
        /* show board */
       -/* TODO: show fancier, unicode and background square color */
       -/* TODO: use the output format similar to stockfish "d" command */
        void
        ascii_showboard(void)
        {
       -        int x, y, piece;
       +        int hi[3] = { '>', ' ', '<' };
       +        int dark[3] = { '.', '.', '.' };
       +        int light[3] = { ' ', ' ', ' ' };
       +        int *color, x, y, piece;
        
                printf("Board FEN:\n");
                showboardfen();
       @@ -366,15 +368,28 @@ ascii_showboard(void)
                for (y = 0; y < 8; y++) {
                        fputs("+---+---+---+---+---+---+---+---+\n", stdout);
                        for (x = 0; x < 8; x++) {
       +                        if (x % 2 == 0) {
       +                                if (y % 2 == 0)
       +                                        color = highlight[y][x] ? hi : light;
       +                                else
       +                                        color = highlight[y][x] ? hi : dark;
       +                        } else {
       +                                if (y % 2 == 0)
       +                                        color = highlight[y][x] ? hi : dark;
       +                                else
       +                                        color = highlight[y][x] ? hi : light;
       +                        }
       +                
                                if (x == 0)
                                        putchar('|');
       -                        fputs(" ", stdout);
       +                        putchar(color[0]);
                                piece = getpiece(x, y);
                                if (piece)
                                        ascii_showpiece(piece);
                                else
       -                                fputs(" ", stdout);
       -                        fputs(" |", stdout);
       +                                putchar(color[1]);
       +                        putchar(color[2]);
       +                        putchar('|');
                        }
                        if (showcoords) {
                                putchar(' ');
       @@ -496,8 +511,6 @@ main(int argc, char *argv[])
                        if (!*s)
                                break;
        
       -                /* TODO: parse which side to move, en-passant, etc */
       -
                        /* next field, fields are: piece placement data, active color,
                           Castling availability, En passant target square,
                           Halfmove clock, Fullmove number */