From 7ba2c3534cc1ff223f6715e58f0da0a4212ad4d7 Mon Sep 17 00:00:00 2001 From: Adon Shapiro Date: Fri, 24 Mar 2017 14:16:10 -0400 Subject: [PATCH] Add '--quiet' comand line option to suppress some output --- NEWS | 1 + doc/ncmpcpp.1 | 3 +++ src/configuration.cpp | 10 ++++++++++ src/ncmpcpp.cpp | 7 ++++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 92ed452f..470c570b 100644 --- a/NEWS +++ b/NEWS @@ -27,6 +27,7 @@ ncmpcpp-0.8 (????-??-??) * Seek immediately after invoking appropriate action once. * Added support for locating current song in playlist editor. * Disable autocenter mode while searching and filtering. +* Added '--quiet' comand line argument that supresses messages shown at startup. ncmpcpp-0.7.7 (2016-10-31) * Fixed compilation on 32bit platforms. diff --git a/doc/ncmpcpp.1 b/doc/ncmpcpp.1 index 43db0d8e..2cefb772 100644 --- a/doc/ncmpcpp.1 +++ b/doc/ncmpcpp.1 @@ -33,6 +33,9 @@ Specify the startup screen ( may be: help, playlist, browser, search_engin .B \-S, \-\-slave-screen Specify the startup slave screen ( may be: help, playlist, browser, search_engine, media_library, playlist_editor, tag_editor, outputs, visualizer, clock) .TP +.B \-q, \-\-quiet +Suppress logs and excess output +.TP .B \-?, \-\-help Display help. .TP diff --git a/src/configuration.cpp b/src/configuration.cpp index f5c9b21a..565c50d4 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "bindings.h" #include "configuration.h" @@ -88,6 +89,7 @@ bool configure(int argc, char **argv) ("slave-screen,S", po::value()->value_name("SCREEN"), "specify the startup slave screen") ("help,?", "show help message") ("version,v", "display version information") + ("quiet,q", "suppress logs and excess output") ; po::variables_map vm; @@ -95,6 +97,14 @@ bool configure(int argc, char **argv) { po::store(po::parse_command_line(argc, argv, options), vm); + // suppress messages from std::clog + if (vm.count("quiet")) + { + std::ofstream null_stream; + null_stream.open("/dev/null"); + std::clog.rdbuf(null_stream.rdbuf()); + } + if (vm.count("help")) { cout << "Usage: " << argv[0] << " [options]...\n" << options << "\n"; diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 1e12967e..3893caba 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -54,6 +54,7 @@ namespace { std::ofstream errorlog; std::streambuf *cerr_buffer; +std::streambuf *clog_buffer; volatile bool run_resize_screen = false; @@ -69,8 +70,9 @@ void sighandler(int sig) void do_at_exit() { - // restore old cerr buffer + // restore old cerr & clog buffers std::cerr.rdbuf(cerr_buffer); + std::clog.rdbuf(clog_buffer); errorlog.close(); Mpd.Disconnect(); NC::destroyScreen(); @@ -92,6 +94,9 @@ int main(int argc, char **argv) std::setlocale(LC_ALL, ""); std::locale::global(Charset::internalLocale()); + // clog might be overriden in configure, so preserve the original buffer. + clog_buffer = std::clog.rdbuf(); + if (!configure(argc, argv)) return 0;