From 028f9bbb65c4211866c69b5e5255aecd5254b18d Mon Sep 17 00:00:00 2001 From: Minghui Liu Date: Mon, 12 Mar 2018 16:54:56 -0700 Subject: Add beep feature to watch --- toys/pending/watch.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'toys') diff --git a/toys/pending/watch.c b/toys/pending/watch.c index d81a0793..3c0a0858 100644 --- a/toys/pending/watch.c +++ b/toys/pending/watch.c @@ -3,7 +3,7 @@ * Copyright 2013 Sandeep Sharma * Copyright 2013 Kyungwan Han * -USE_WATCH(NEWTOY(watch, "^<1n#<0=2te", TOYFLAG_USR|TOYFLAG_BIN)) +USE_WATCH(NEWTOY(watch, "^<1n#<0=2teb", TOYFLAG_USR|TOYFLAG_BIN)) config WATCH bool "watch" @@ -16,6 +16,7 @@ config WATCH -n Loop period in seconds (default 2) -t Don't print header -e Freeze updates on command error, and exit after enter. + -b Beep on command error */ #define FOR_watch #include "toys.h" @@ -32,7 +33,7 @@ void watch_main(void) char *header, *cmd = *toys.optargs; int retval; - while(toys.optargs[++i]) + while (toys.optargs[++i]) { char * oldcmd = cmd; cmd = xmprintf("%s %s", oldcmd, toys.optargs[i]); @@ -43,19 +44,21 @@ void watch_main(void) while(1) { xprintf("\033[H\033[J"); - if(!(toys.optflags & FLAG_t)) { + if (!(toys.optflags & FLAG_t)) { terminal_size(&width, NULL); if (!width) width = 80; //on serial it may return 0. time(&t); if (width > (hlen + len)) xprintf("%s", header); - if(width >= len) + if (width >= len) xprintf("%*s\n",width + ((width > (hlen + len))?-hlen:0) + 1, ctime(&t)); else xprintf("\n\n"); } fflush(NULL); //making sure the screen is clear retval = system(cmd); - if ((toys.optflags & FLAG_e) && retval){ + if ((toys.optflags & FLAG_b) && retval) + xprintf("\007"); + if ((toys.optflags & FLAG_e) && retval) { xprintf("command exit with non-zero status, press enter to exit\n"); getchar(); break; -- cgit v1.2.3