use pa_cli instance to store quiet flag (i.e. do not show prompt) include PA version in welcome message Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net> --- src/pulsecore/cli-command.c | 22 ++++++++++++++++++++++ src/pulsecore/cli.c | 4 ++-- src/pulsecore/cli.h | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c index 0440543..5dbaca7 100644 --- a/src/pulsecore/cli-command.c +++ b/src/pulsecore/cli-command.c @@ -84,6 +84,7 @@ enum { /* Prototypes for all available commands */ static int pa_cli_command_exit(pa_cli *c, pa_tokenizer *t, pa_strbuf *buf, bool *fail); static int pa_cli_command_help(pa_cli *c, pa_tokenizer *t, pa_strbuf *buf, bool *fail); +static int pa_cli_command_hello(pa_cli *c, pa_tokenizer *t, pa_strbuf *buf, bool *fail); static int pa_cli_command_modules(pa_cli *c, pa_tokenizer *t, pa_strbuf *buf, bool *fail); static int pa_cli_command_clients(pa_cli *c, pa_tokenizer *t, pa_strbuf *buf, bool *fail); static int pa_cli_command_cards(pa_cli *c, pa_tokenizer *t, pa_strbuf *buf, bool *fail); @@ -142,6 +143,7 @@ static int pa_cli_command_dump_volumes(pa_cli *c, pa_tokenizer *t, pa_strbuf *bu static const struct command commands[] = { { "help", pa_cli_command_help, "Show this help", 1 }, + { "hello", pa_cli_command_hello, "Show welcome message", 2 }, { "list-modules", pa_cli_command_modules, "List loaded modules", 1 }, { "list-cards", pa_cli_command_cards, "List cards", 1 }, { "list-sinks", pa_cli_command_sinks, "List loaded sinks", 1 }, @@ -242,6 +244,26 @@ static int pa_cli_command_help(pa_cli *c, pa_tokenizer *t, pa_strbuf *buf, bool return 0; } +static int pa_cli_command_hello(pa_cli *c, pa_tokenizer *t, pa_strbuf *buf, bool *fail) { + const char *option; + + pa_assert(c); + pa_assert(t); + pa_assert(buf); + pa_assert(fail); + + c->quiet = false; + if ((option = pa_tokenizer_get(t, 1))) { + if (pa_streq(option, "quiet")) { + c->quiet = true; + } + } + + if (!c->quiet) + pa_strbuf_printf(buf, "Welcome to PulseAudio %s! Use \"help\" for usage information.\n", PACKAGE_VERSION); + return 0; +} + static int pa_cli_command_modules(pa_cli *c, pa_tokenizer *t, pa_strbuf *buf, bool *fail) { char *s; diff --git a/src/pulsecore/cli.c b/src/pulsecore/cli.c index 4a9dabc..c355015 100644 --- a/src/pulsecore/cli.c +++ b/src/pulsecore/cli.c @@ -84,10 +84,10 @@ pa_cli* pa_cli_new(pa_core *core, pa_iochannel *io, pa_module *m) { c->client->userdata = c; pa_ioline_set_callback(c->line, line_callback, c); - pa_ioline_puts(c->line, "Welcome to PulseAudio! Use \"help\" for usage information.\n"PROMPT); c->fail = c->kill_requested = false; c->defer_kill = 0; + c->quiet = false; c->last_line = NULL; @@ -159,7 +159,7 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) { if (c->eof_callback) c->eof_callback(c, c->userdata); } else - pa_ioline_puts(line, PROMPT); + if (!c->quiet) pa_ioline_puts(line, PROMPT); } void pa_cli_set_eof_callback(pa_cli *c, pa_cli_eof_cb_t cb, void *userdata) { diff --git a/src/pulsecore/cli.h b/src/pulsecore/cli.h index c50e065..dd36a8a 100644 --- a/src/pulsecore/cli.h +++ b/src/pulsecore/cli.h @@ -42,6 +42,7 @@ struct pa_cli { bool fail, kill_requested; int defer_kill; + bool quiet; char *last_line; }; -- 1.8.3.2