[rfk-dev] A patch for rfk

Andras Farkas deepbluemistake at gmail.com
Tue Mar 26 22:54:57 PDT 2019


I like robotfindskitten! I've found its humor and writing style nice
ever since I found it a couple days ago.
But, because it uses ncurses and ncurses has some weird defaults, it
forces the bg of my terminal to be black and fg to be white, when I
prefer a white bg and black fg. (I find it easier on my eyes)
So I wrote a patch. If the curses being used is ncurses, rfk now
respects a user's default terminal colors unless the new -b option is
used to force a black background. This means people who use black
terminals will notice no change, but people using terminals with other
bg colors will notice a positive change when not using -b. (anyone
using -b will notice no change)
I've also updated the man page to document this, but I didn't update
the info file or changelog, since I'm unsure whether this is a big
enough change to warrant being in the changelog. (it might be!) I also
very slightly cleaned up the man page while I was updating it, and
fixed a typo.
I've attached the two diffs, one for the .c file and one for the man
page. If you'd prefer just having the whole files rather than diffs,
let me know.

I don't have a sourceforge account, so I decided to try sending an
email to the list first. :B
-------------- next part --------------
--- robotfindskitten-2.7182818.701/doc/robotfindskitten.6	2012-11-03 13:39:20.000000000 -0400
+++ newrfk/doc/robotfindskitten.6	2019-03-20 00:29:42.588850000 -0400
@@ -5,11 +5,9 @@
 .\"
 .SH SYNOPSIS
 .B robotfindskitten
-[
-.BR -n number 
-] [
-.BR -s seed
-]
+[\fB-bV\fR]
+[\fB-n\fR \fInumber\fR]
+[\fB-s\fR \fIseed\fR]
 .\"
 .SH DESCRIPTION
 In this game, you are robot
@@ -32,7 +30,12 @@
 the -s option. The default is 20.
 
 You can set the random-number seed, normally initialized from the
-system clock, with the -t option.  This may be useful for debugging.
+system clock, with the -s option.  This may be useful for debugging.
+
+You can force robotfindskitten to use a black background and white
+foreground with the -b option.
+
+You can see the version number with the -V option.
 .\"
 .SH FILES
 .BR robotfindskitten (6)
-------------- next part --------------
--- robotfindskitten-2.7182818.701/src/robotfindskitten.c	2012-11-27 02:41:21.000000000 -0500
+++ newrfk/src/robotfindskitten.c	2019-03-20 01:25:56.864233000 -0400
@@ -350,8 +350,14 @@
 	exit ( sig );
 }
 
-static void init ( unsigned int num ) {
+static void init ( unsigned int num, bool blackflag ) {
 	unsigned int i, j;
+	bool ncurses_yup;
+	#ifdef NCURSES_VERSION
+	ncurses_yup = true;
+	#else
+	ncurses_yup = false;
+	#endif
 
 	/*@-mustfreefresh -mustfreeonly@*/
 	/* allocate memory */
@@ -421,13 +427,23 @@
 	(void) start_color();
 	if ( has_colors() && ( COLOR_PAIRS > 7 ) ) {
 		state.options |= OPTION_HAS_COLOR;
-		(void) init_pair ( 1, COLOR_GREEN, COLOR_BLACK );
-		(void) init_pair ( 2, COLOR_RED	, COLOR_BLACK );
-		(void) init_pair ( 3, COLOR_YELLOW, COLOR_BLACK );
-		(void) init_pair ( 4, COLOR_BLUE, COLOR_BLACK );
-		(void) init_pair ( 5, COLOR_MAGENTA, COLOR_BLACK );
-		(void) init_pair ( 6, COLOR_CYAN, COLOR_BLACK );
-		(void) init_pair ( 7, COLOR_WHITE, COLOR_BLACK );
+		if ( ncurses_yup && ! blackflag && use_default_colors() == OK ) {
+			(void) init_pair ( 1, COLOR_GREEN, -1 );
+			(void) init_pair ( 2, COLOR_RED	, -1 );
+			(void) init_pair ( 3, COLOR_YELLOW, -1 );
+			(void) init_pair ( 4, COLOR_BLUE, -1 );
+			(void) init_pair ( 5, COLOR_MAGENTA, -1 );
+			(void) init_pair ( 6, COLOR_CYAN, -1 );
+			(void) init_pair ( 7, -1, -1 );
+		} else {
+			(void) init_pair ( 1, COLOR_GREEN, COLOR_BLACK );
+			(void) init_pair ( 2, COLOR_RED	, COLOR_BLACK );
+			(void) init_pair ( 3, COLOR_YELLOW, COLOR_BLACK );
+			(void) init_pair ( 4, COLOR_BLUE, COLOR_BLACK );
+			(void) init_pair ( 5, COLOR_MAGENTA, COLOR_BLACK );
+			(void) init_pair ( 6, COLOR_CYAN, COLOR_BLACK );
+			(void) init_pair ( 7, COLOR_WHITE, COLOR_BLACK );
+		}
 		(void) bkgd ( (chtype) COLOR_PAIR(WHITE) );
 
 		state.items[ROBOT].color = WHITE;
@@ -725,9 +741,13 @@
 
 int main ( int argc, char **argv ) {
     int option, seed = (int) time ( 0 ), nbogus = DEFAULT_NUM_BOGUS;
+    bool blackflag = false;
 
-	while ((option = getopt(argc, argv, "n:s:Vh")) != -1) {
+	while ((option = getopt(argc, argv, "bn:s:Vh")) != -1) {
 	    switch (option) {
+	    case 'b':
+		blackflag = true;
+		break;
 	    case 'n':
 		nbogus = atoi ( optarg );
 		if ( nbogus <= 0 ) {
@@ -744,7 +764,7 @@
 	    case 'h':
 	    case '?':
 	    default:
-		(void) printf("usage: %s [-n nitems] [-s seed] [-V]\n", argv[0]);
+		(void) printf("usage: %s [-n nitems] [-s seed] [-bV]\n", argv[0]);
 		exit(EXIT_SUCCESS);
 	    }
 	}
@@ -766,7 +786,7 @@
 		(void) fprintf ( stderr, "There are only %u NKIs available (user requested %d).\n", state.num_messages, nbogus );
 		exit ( EXIT_FAILURE );
 	} else {
-	    init ( (unsigned int)nbogus );
+	    init ( (unsigned int)nbogus, blackflag );
 	}
 
 	instructions();


More information about the rfk-dev mailing list