diff options
author | Minghui Liu <minghui.liu.95@gmail.com> | 2018-03-12 16:54:56 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2018-03-13 10:58:02 -0500 |
commit | 028f9bbb65c4211866c69b5e5255aecd5254b18d (patch) | |
tree | 845fb808aa8cd38c24448134f8718886edb5ce86 | |
parent | 9477d6497f3eab08cbb1f7f929be059a3722ef9b (diff) | |
download | toybox-028f9bbb65c4211866c69b5e5255aecd5254b18d.tar.gz |
Add beep feature to watch
-rw-r--r-- | toys/pending/watch.c | 13 |
1 files changed, 8 insertions, 5 deletions
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 <sandeep.jack2756@gmail.com> * Copyright 2013 Kyungwan Han <asura321@gmail.com> * -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; |