aboutsummaryrefslogtreecommitdiff
path: root/frontend/cli.cpp
blob: de78bc1b7d45cd14723a11cf4d7ea6e9e26b2e4d (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
36
37
38
#include <cstdlib>
#include <cstdio>

#include <readline/readline.h>
#include <readline/history.h>

#include "cli.h"
#include "frontend/print.h"
#include "strings.h"
#include "cmd.h"

using namespace std;

string cli_readline() {
	const char * PROMPT = "> ";

	char * input = readline(PROMPT);
	SessionLog::get().append(PROMPT);
	if (input == NULL) exit(EXIT_SUCCESS); // ctrl-d
	string out = string(input);
	if (out.size() > 0) add_history(input);
	free(input);

	SessionLog::get().append(out);
	SessionLog::get().append("\n");

	return out;
}

void cli_main() {
	while (1) {
		string line = cli_readline();
		if (line.length() == 0) continue;
		vector<string> argv = split_string(line, " ");
		cmd_handle(argv);
	}
}