blob: 352de4a56f73391741ac325076f7cb2df99df752 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include <cstdlib>
#include <cstdio>
#include <readline/readline.h>
#include <readline/history.h>
#include "cli.h"
using namespace std;
static void handle_line(const string & line) {
printf("CMD: %s\n", line.c_str());
}
string cli_readline() {
const char * PROMPT = "> ";
char * input = readline(PROMPT);
// ctrl-d
if (input == NULL) exit(EXIT_SUCCESS);
string out = string(input);
if (out.size() > 0) add_history(input);
free(input);
return out;
}
void cli_main() {
while (1) {
string cmd = cli_readline();
if (cmd.size() == 0) continue;
handle_line(cmd);
}
}
|