From 5a46912d6288afac8e34d24945bcba97874e8b7b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 17 Mar 2018 11:06:02 +0100 Subject: [PATCH] Add -q (quiet) option to disable unnecessary output --- abduco.1 | 3 +++ abduco.c | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/abduco.1 b/abduco.1 index 9d7e37d..ffacb09 100644 --- a/abduco.1 +++ b/abduco.1 @@ -114,6 +114,9 @@ Attach to an existing session. .TP .BI \-l Attach with the lowest priority, meaning this client will be the last to control the size. +.TP +.BI \-q +Be quiet, do not print informative messages. .SH EXAMPLE Start a new session (assuming .BR dvtm(1) diff --git a/abduco.c b/abduco.c index 071cc74..3e01ca8 100644 --- a/abduco.c +++ b/abduco.c @@ -120,7 +120,7 @@ typedef struct { static Server server = { .running = true, .exit_status = -1, .host = "@localhost" }; static Client client; static struct termios orig_term, cur_term; -static bool has_term, alternate_buffer; +static bool has_term, alternate_buffer, quiet; static struct sockaddr_un sockaddr = { .sun_family = AF_UNIX, @@ -207,12 +207,12 @@ static bool recv_packet(int socket, Packet *pkt) { static void info(const char *str, ...) { va_list ap; va_start(ap, str); - if (str) { + if (str && !quiet) { fprintf(stderr, "%s: %s: ", server.name, server.session_name); vfprintf(stderr, str, ap); fprintf(stderr, "\r\n"); + fflush(stderr); } - fflush(stderr); va_end(ap); } @@ -222,7 +222,7 @@ static void die(const char *s) { } static void usage(void) { - fprintf(stderr, "usage: abduco [-a|-A|-c|-n] [-r] [-l] [-f] [-e detachkey] name command\n"); + fprintf(stderr, "usage: abduco [-a|-A|-c|-n] [-r] [-q] [-l] [-f] [-e detachkey] name command\n"); exit(EXIT_FAILURE); } @@ -588,7 +588,7 @@ int main(int argc, char *argv[]) { server.name = basename(argv[0]); gethostname(server.host+1, sizeof(server.host) - 1); - while ((opt = getopt(argc, argv, "aAclne:frv")) != -1) { + while ((opt = getopt(argc, argv, "aAclne:fqrv")) != -1) { switch (opt) { case 'a': case 'A': @@ -606,6 +606,9 @@ int main(int argc, char *argv[]) { case 'f': force = true; break; + case 'q': + quiet = true; + break; case 'r': client.flags |= CLIENT_READONLY; break; -- 2.11.4.GIT