On 3/21/11, Matthieu Herrb <[email protected]> wrote:
> rain(6) is useless. but still it should provide sane defaults
> ihmo. ok?
Or use sane defaults based on terminal speed; like worms(8) does.
Index: rain.6
===================================================================
RCS file: /cvs/src/games/rain/rain.6,v
retrieving revision 1.14
diff -u -r1.14 rain.6
--- rain.6 31 May 2007 19:19:18 -0000 1.14
+++ rain.6 21 Mar 2011 07:39:02 -0000
@@ -43,11 +43,18 @@
is modeled after the
.Tn VAX/VMS
program of the same name.
-To obtain the proper effect, either the terminal must be set for 9600 baud
-or the
-.Fl d
-option must be used to specify a delay, in milliseconds, between each update.
-A reasonable delay is 120; the default is 0.
+.Pp
+The options are as follows:
+.Bl -tag -width "-l length"
+.It Fl d Ar delay
+Specifies a delay, in milliseconds, between each update.
+This is useful for fast terminals.
+Reasonable values are around 20-200.
+The default is based on the terminal speed.
+If the terminal is 9600 baud or slower no delay is used.
+Otherwise, the delay is computed via the following formula:
+.Dl delay = speed / 9600 - 1.
+.El
.Pp
As with any
.Xr curses 3
Index: rain.c
===================================================================
RCS file: /cvs/src/games/rain/rain.c,v
retrieving revision 1.15
diff -u -r1.15 rain.c
--- rain.c 27 Oct 2009 23:59:26 -0000 1.15
+++ rain.c 21 Mar 2011 07:31:37 -0000
@@ -40,6 +40,7 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
+#include <termios.h>
#include <unistd.h>
volatile sig_atomic_t sig_caught = 0;
@@ -55,6 +56,13 @@
u_int delay = 0;
int ch;
int xpos[5], ypos[5];
+ struct termios term;
+ speed_t speed;
+
+ /* set default delay based on terminal baud rate */
+ if (tcgetattr(STDOUT_FILENO, &term) == 0 &&
+ (speed = cfgetospeed(&term)) > B9600)
+ delay = (speed / B9600) - 1;
while ((ch = getopt(argc, argv, "d:h")) != -1)
switch(ch) {