Add -q (quiet) option to disable unnecessary output

This commit is contained in:
Marc André Tanner 2018-03-17 11:06:02 +01:00
parent 3e3308d4e3
commit 5a46912d62
2 changed files with 11 additions and 5 deletions

View File

@ -114,6 +114,9 @@ Attach to an existing session.
.TP .TP
.BI \-l .BI \-l
Attach with the lowest priority, meaning this client will be the last to control the size. 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 .SH EXAMPLE
Start a new session (assuming Start a new session (assuming
.BR dvtm(1) .BR dvtm(1)

View File

@ -120,7 +120,7 @@ typedef struct {
static Server server = { .running = true, .exit_status = -1, .host = "@localhost" }; static Server server = { .running = true, .exit_status = -1, .host = "@localhost" };
static Client client; static Client client;
static struct termios orig_term, cur_term; 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 = { static struct sockaddr_un sockaddr = {
.sun_family = AF_UNIX, .sun_family = AF_UNIX,
@ -207,12 +207,12 @@ static bool recv_packet(int socket, Packet *pkt) {
static void info(const char *str, ...) { static void info(const char *str, ...) {
va_list ap; va_list ap;
va_start(ap, str); va_start(ap, str);
if (str) { if (str && !quiet) {
fprintf(stderr, "%s: %s: ", server.name, server.session_name); fprintf(stderr, "%s: %s: ", server.name, server.session_name);
vfprintf(stderr, str, ap); vfprintf(stderr, str, ap);
fprintf(stderr, "\r\n"); fprintf(stderr, "\r\n");
fflush(stderr);
} }
fflush(stderr);
va_end(ap); va_end(ap);
} }
@ -222,7 +222,7 @@ static void die(const char *s) {
} }
static void usage(void) { 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); exit(EXIT_FAILURE);
} }
@ -588,7 +588,7 @@ int main(int argc, char *argv[]) {
server.name = basename(argv[0]); server.name = basename(argv[0]);
gethostname(server.host+1, sizeof(server.host) - 1); 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) { switch (opt) {
case 'a': case 'a':
case 'A': case 'A':
@ -606,6 +606,9 @@ int main(int argc, char *argv[]) {
case 'f': case 'f':
force = true; force = true;
break; break;
case 'q':
quiet = true;
break;
case 'r': case 'r':
client.flags |= CLIENT_READONLY; client.flags |= CLIENT_READONLY;
break; break;