aboutsummaryrefslogtreecommitdiff
path: root/frontend/rl.cpp
blob: 1c0df0e8b3a376326fe2a4bd117763924b43aac9 (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
#include <cstdlib>
#include <cstdio>

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

#include "rl.h"
#include "print.h"

using namespace std;

string rl() {
	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;
}