aboutsummaryrefslogtreecommitdiff
path: root/frontend/cli.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/cli.cpp')
-rw-r--r--frontend/cli.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/frontend/cli.cpp b/frontend/cli.cpp
new file mode 100644
index 0000000..352de4a
--- /dev/null
+++ b/frontend/cli.cpp
@@ -0,0 +1,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);
+ }
+}
+