From c80f833a06eea51ccdeaaa50255ec3462ab0eca8 Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Sat, 22 Oct 2022 08:59:34 +0200 Subject: [PATCH] Add mute feature This will make tio go fully silent and not print anything. --- src/bash-completion/tio.in | 5 +++++ src/configfile.c | 11 +++++++++++ src/options.c | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/src/bash-completion/tio.in b/src/bash-completion/tio.in index 82cb649..9602c4f 100644 --- a/src/bash-completion/tio.in +++ b/src/bash-completion/tio.in @@ -35,6 +35,7 @@ _tio() --rs-485 \ --rs-485-config \ --alert \ + --mute \ -v --version \ -h --help" @@ -141,6 +142,10 @@ _tio() COMPREPLY=( $(compgen -W "none bell blink" -- ${cur}) ) return 0 ;; + --mute) + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + ;; -v | --version) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 diff --git a/src/configfile.c b/src/configfile.c index 96e7ea5..8e29a26 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -302,6 +302,17 @@ static int data_handler(void *user, const char *section, const char *name, { option.alert = alert_option_parse(value); } + else if (!strcmp(name, "mute")) + { + if (!strcmp(value, "enable")) + { + option.mute = true; + } + else if (!strcmp(value, "disable")) + { + option.mute = false; + } + } } return 0; diff --git a/src/options.c b/src/options.c index f02da9e..cac6222 100644 --- a/src/options.c +++ b/src/options.c @@ -51,6 +51,7 @@ enum opt_t OPT_RS485_CONFIG, OPT_ALERT, OPT_COMPLETE_SUB_CONFIGS, + OPT_MUTE, }; /* Default options */ @@ -127,6 +128,7 @@ void print_help(char *argv[]) printf(" --rs-485 Enable RS-485 mode\n"); printf(" --rs-485-config Set RS-485 configuration\n"); printf(" --alert bell|blink|none Alert on connect/disconnect (default: none)\n"); + printf(" --mute Mute tio\n"); printf(" -v, --version Display version\n"); printf(" -h, --help Display help\n"); printf("\n"); @@ -258,6 +260,7 @@ void options_parse(int argc, char *argv[]) {"rs-485", no_argument, 0, OPT_RS485 }, {"rs-485-config", required_argument, 0, OPT_RS485_CONFIG }, {"alert", required_argument, 0, OPT_ALERT }, + {"mute", no_argument, 0, OPT_MUTE }, {"version", no_argument, 0, 'v' }, {"help", no_argument, 0, 'h' }, {"complete-sub-configs", no_argument, 0, OPT_COMPLETE_SUB_CONFIGS}, @@ -413,6 +416,10 @@ void options_parse(int argc, char *argv[]) option.alert = alert_option_parse(optarg); break; + case OPT_MUTE: + option.mute = true; + break; + case 'v': printf("tio v%s\n", VERSION); exit(EXIT_SUCCESS);