From 188261ceaa271da8d37ff22c9a41576e839b87ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Balzarotti?= Date: Mon, 26 Dec 2016 18:14:20 +0100 Subject: [PATCH] Colored selection (if terminal supports it) --- Roofus.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/Roofus.c b/Roofus.c index 4391f2c..513dfba 100644 --- a/Roofus.c +++ b/Roofus.c @@ -1,4 +1,4 @@ -#define VERSION "1.01" +#define VERSION "1.02" #define N 9 #define USERNAME_LENGTH 10 @@ -36,6 +36,10 @@ int main () { cbreak(); keypad(stdscr, true); + if (has_colors() == TRUE) { + start_color(); + init_pair(1, COLOR_BLACK, COLOR_WHITE); + } srand (time(NULL)); fp = fopen ("roofus.txt", "a+"); if (fp == NULL) { @@ -343,12 +347,26 @@ void printm () { printw ("\n\n"); for (i = 0; i < grid; i++) { for (j = 0;j < grid; j++) { - if (i == my_y && j == my_x) - printw ("> "); + if (i == my_y && j == my_x) { + if (has_colors() == TRUE) { + attron(COLOR_PAIR(1)); + } else { + printw ("> "); + } + } if (matrix[i][j] != 0) - printw ("%d\t", matrix[i][j]); - else - printw (" \t"); + printw ("%d", matrix[i][j]); + else { + if (has_colors() == FALSE) { + printw (" "); + } else { + printw("."); + } + } + if (has_colors() == TRUE) { + attroff(COLOR_PAIR(1)); + } + printw("\t"); } printw ("\n\n"); }