aboutsummaryrefslogtreecommitdiff
path: root/client/rl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'client/rl.cpp')
-rw-r--r--client/rl.cpp31
1 files changed, 20 insertions, 11 deletions
diff --git a/client/rl.cpp b/client/rl.cpp
index 2e74e5f..493f753 100644
--- a/client/rl.cpp
+++ b/client/rl.cpp
@@ -10,24 +10,22 @@
#include "cmd.h"
#include "parse.h"
-void rl_printf(const char *fmt, ...) {
+static char* saved_line;
+static int saved_point, saved_end;
+
+void _rl_printf_start() {
// save line
- char* saved_line = rl_copy_text(0, rl_end);
- int saved_point = rl_point;
- int saved_end = rl_end;
+ saved_line = rl_copy_text(0, rl_end);
+ saved_point = rl_point;
+ saved_end = rl_end;
// clear line
rl_save_prompt();
rl_replace_line("", 0);
rl_redisplay();
+}
- // printf
- va_list args;
- va_start(args, fmt);
- vprintf(fmt, args);
- va_end(args);
-
- // restore line
+void _rl_printf_stop() {
rl_restore_prompt();
rl_replace_line(saved_line, 0);
rl_point = saved_point;
@@ -37,6 +35,17 @@ void rl_printf(const char *fmt, ...) {
free(saved_line);
}
+void rl_printf(const char *fmt, ...) {
+ _rl_printf_start();
+
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+
+ _rl_printf_stop();
+}
+
static void cli_cmd(char* cmd) {
cmd += strspn(cmd, IFS); // skip leading whitespace
char* line = consume_token(cmd, IFS);