1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-10 06:47:55 -08:00

allow q to exit the program.

ok cheloha deraadt schwarze
This commit is contained in:
tedu 2019-01-06 18:27:14 +00:00
parent 62d6c181a0
commit 8ca82b0009
2 changed files with 23 additions and 6 deletions

View File

@ -1,8 +1,8 @@
.\" $OpenBSD: grdc.6,v 1.10 2014/11/17 22:14:25 schwarze Exp $
.\" $OpenBSD: grdc.6,v 1.11 2019/01/06 18:27:14 tedu Exp $
.\"
.\" Copyright 2002 Amos Shapir. Public domain.
.\"
.Dd $Mdocdate: November 17 2014 $
.Dd $Mdocdate: January 6 2019 $
.Dt GRDC 6
.Os
.Sh NAME
@ -26,7 +26,10 @@ The optional
flag makes digits scroll as they change.
If the terminal is too slow to keep up,
.Nm
will skip seconds.
skips seconds.
Pressing the
.Sq q
exits the program.
.Sh AUTHORS
.An -nosplit
.An Amos Shapir ,

View File

@ -1,4 +1,4 @@
/* $OpenBSD: grdc.c,v 1.29 2018/08/23 06:25:01 mestre Exp $ */
/* $OpenBSD: grdc.c,v 1.30 2019/01/06 18:27:14 tedu Exp $ */
/*
*
* Copyright 2002 Amos Shapir. Public domain.
@ -18,7 +18,9 @@
#include <limits.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <poll.h>
#include <unistd.h>
#define XLENGTH 58
@ -59,10 +61,11 @@ int
main(int argc, char *argv[])
{
long t, a;
int i, j, s, k;
int i, j, s, k, rv;
int scrol;
int n = 0;
struct timespec delay, end;
struct pollfd pfd;
const char *errstr;
long scroldelay = 50000000;
int xbase;
@ -106,6 +109,9 @@ main(int argc, char *argv[])
signal(SIGWINCH, sigresize);
signal(SIGCONT, sigresize); /* for resizes during suspend */
pfd.fd = STDIN_FILENO;
pfd.events = POLLIN;
cbreak();
noecho();
@ -224,7 +230,15 @@ main(int argc, char *argv[])
/* want scrolling to END on the second */
if (scrol && !wintoosmall)
delay.tv_nsec -= 5 * scroldelay;
nanosleep(&delay, NULL);
rv = ppoll(&pfd, 1, &delay, NULL);
if (rv == 1) {
char q = 0;
read(STDIN_FILENO, &q, 1);
if (q == 'q') {
n = 1;
end.tv_sec = now.tv_sec;
}
}
now.tv_sec++;
if (sigtermed) {