From ebce3185ef8064ab42106d2fd24aba21a159905d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 25 May 2009 23:56:38 +0200 Subject: [PATCH] cli: allow easy repeating of commands with '/' --- src/pulsecore/cli.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/pulsecore/cli.c b/src/pulsecore/cli.c index a784f58..54514e7 100644 --- a/src/pulsecore/cli.c +++ b/src/pulsecore/cli.c @@ -59,6 +59,8 @@ struct pa_cli { pa_bool_t fail, kill_requested; int defer_kill; + + char *last_line; }; static void line_callback(pa_ioline *line, const char *s, void *userdata); @@ -101,6 +103,8 @@ pa_cli* pa_cli_new(pa_core *core, pa_iochannel *io, pa_module *m) { c->fail = c->kill_requested = FALSE; c->defer_kill = 0; + c->last_line = NULL; + return c; } @@ -110,6 +114,7 @@ void pa_cli_free(pa_cli *c) { pa_ioline_close(c->line); pa_ioline_unref(c->line); pa_client_free(c->client); + pa_xfree(c->last_line); pa_xfree(c); } @@ -144,6 +149,14 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) { return; } + /* Magic command, like they had in AT Hayes Modems! Those were the good days! */ + if (pa_streq(s, "/")) + s = c->last_line; + else if (s[0]) { + pa_xfree(c->last_line); + c->last_line = pa_xstrdup(s); + } + pa_assert_se(buf = pa_strbuf_new()); c->defer_kill++; pa_cli_command_execute_line(c->core, s, buf, &c->fail); -- 2.7.4