From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Thu, 14 Sep 2006 09:23:55 +0400 From: Alexey Tourbin To: devel@lists.altlinux.org Message-ID: <20060914052355.GF17693@localhost.localdomain> Mail-Followup-To: devel@lists.altlinux.org References: <20060914005144.GZ17693@localhost.localdomain> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="qL6YN2OI1pnKQLYZ" Content-Disposition: inline In-Reply-To: <20060914005144.GZ17693@localhost.localdomain> Subject: [devel] watch(1) X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.7 Precedence: list Reply-To: ALT Devel discussion list List-Id: ALT Devel discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Sep 2006 05:23:57 -0000 Archived-At: List-Archive: List-Post: --qL6YN2OI1pnKQLYZ Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Sep 14, 2006 at 04:51:44AM +0400, Alexey Tourbin wrote: > Implement the following behaviour: > =20 > 1) execute a program also when a key is pressed; > 2) but if that key is 'q' then exit instead. > =20 > This makes watch look more like an interactive program. >=20 > diff --git a/procps/watch.c b/procps/watch.c > index 18ded5e..4abad74 100644 > --- a/procps/watch.c > +++ b/procps/watch.c > @@ -20,6 +20,7 @@ #include > #include > #include > #include > +#include > #include > #include > #include > @@ -227,6 +228,7 @@ main(int argc, char *argv[]) > nonl(); > noecho(); > cbreak(); > + nodelay(stdscr, TRUE); > =20 > for (;;) { > time_t t =3D time(NULL); > @@ -236,6 +238,10 @@ main(int argc, char *argv[]) > FILE *p; > int x, y; > int oldeolseen =3D 1; > + int key; > + > + if ((key =3D getch()) =3D=3D 'q')=20 > + do_exit(0); > =20 > if (screen_size_changed) { > get_terminal_size(); > @@ -314,7 +320,16 @@ main(int argc, char *argv[]) > =20 > first_screen =3D 0; > refresh(); > - usleep(interval * 1000000); > + > + /* wait until tiemout or until a key press */ > + { > + fd_set set; > + int fd =3D fileno(stdin); > + struct timeval timeout =3D { interval, 0 }; > + FD_ZERO(&set); > + FD_SET(fd, &set); > + select(fd + 1, &set, NULL, NULL, &timeout); > + } > } > =20 > endwin(); > $ =F7 =CF=C2=DD=C5=CD =DA=C1=D4=C5=D1 =CF=CB=C1=DA=C1=CC=C1=D3=D8 =CE=C5=C2= =C5=D3=D0=D2=CF=C2=CC=C5=CD=CE=C1=D1 -- select =CD=CF=D6=C5=D4 =CF=D4=D7=C1= =CC=C9=D4=D8 =C9=CC=C9 =D7=C5=D2=CE=D5=D4=D8 =D2=C1=CE=D8=DB=C5 =D7=D2=C5=CD=C5=CE=C9 =D0=CF =D3= =C1=CD=D9=CD =D2=C1=DA=CE=D9=CD =D0=D2=C9=DE=C9=CE=C1=CD, =C1 =D7=C8=CF=C4= =C9=D4=D8 =D7 =C2=C5=DA=D5=C4=C5=D2=D6=CE=D9=CA =C3=C9=CB=CC =D0=CF=D3=CC=C5=C4=CE=C5=C5 = =C4=C5=CC=CF. =ED=CF=D6=CE=CF =CB=CF=CE=C5=DE=CE=CF =D0=D2=CF=D7=C5=D2=D1= =D4=D8 =CE=C1 isatty(0), =CE=CF =CD=CE=C5 =DC=D4=C1 =C9=C4=C5=D1 =D0=CF=DE=C5=CD=D5-=D4=CF =CE=C5 = =CF=DE=C5=CE=D8 =CE=D2=C1=D7=C9=D4=D3=D1. =EB=CF=D2=CF=DE=C5 =CF=CB=CF=CE= =DE=C1=D4=C5=CC=D8=CE=D9=CA =D7=C1=D2=C9=C1=CE=D4 =D7 git.alt:/people/at/packages/procps.git =CE=C5=D3= =CB=CF=CC=D8=CB=CF =CC=D5=DE=DB=C5, =DE=C5=CD =DC=D4=CF=D4 =C9 =CE=C5=D3=CB=CF=CC=D8=CB=CF =D0=CF=D3=CC=C5=C4=D5=C0=DD=C9= =C8. --qL6YN2OI1pnKQLYZ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) iD8DBQFFCOdrfBKgtDjnu0YRAiqHAJ46BSNY62r8uzg3G4Shc0zD/HFPSwCfRUPo hFITAJly8CTE0URKD8d6KkY= =JNYc -----END PGP SIGNATURE----- --qL6YN2OI1pnKQLYZ--