diff options
| author | lonkaars <loek@pipeframe.xyz> | 2024-05-20 13:47:37 +0200 |
|---|---|---|
| committer | lonkaars <loek@pipeframe.xyz> | 2024-05-20 13:47:37 +0200 |
| commit | db8906d54cd9afbc57f0b40a0d618335c552f704 (patch) | |
| tree | 86f6365f3770c02e1c9a772f338b20553dc6e454 /client/rl.c | |
| parent | 27c8d89359b8d5e97c4c23ff464d5f3de7279709 (diff) | |
back-and-forth in C++ w/o netcat
Diffstat (limited to 'client/rl.c')
| -rw-r--r-- | client/rl.c | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/client/rl.c b/client/rl.c deleted file mode 100644 index fb26057..0000000 --- a/client/rl.c +++ /dev/null @@ -1,55 +0,0 @@ -#include <stdlib.h> -#include <stdio.h> -#include <stdbool.h> -#include <stdarg.h> - -#include <readline/readline.h> -#include <readline/history.h> - -#include "rl.h" - -void rl_printf(const char *fmt, ...) { - // save line - char* saved_line = rl_copy_text(0, rl_end); - int saved_point = rl_point; - int 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 - rl_restore_prompt(); - rl_replace_line(saved_line, 0); - rl_point = saved_point; - rl_end = saved_end; - rl_redisplay(); - - free(saved_line); -} - -int cli_main() { - char* input = NULL; - while (1) { - if (input != NULL) free(input); - input = readline(CLI_PROMPT); - - // exit on ^D or ^C (EOF) - if (input == NULL) return EXIT_SUCCESS; - - // add non-empty line to history - if (*input) add_history(input); - - if (strcmp(input, "exit") == 0) return EXIT_SUCCESS; - } - - return EXIT_SUCCESS; -} - |