Makefile: fix recursive make of compiled impls.
[jackhill/mal.git] / cpp / ReadLine.cpp
1 #include "ReadLine.h"
2 #include "String.h"
3
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <unistd.h>
7
8 #include <readline/readline.h>
9 #include <readline/history.h>
10 #include <readline/tilde.h>
11
12 ReadLine::ReadLine(const String& historyFile)
13 : m_historyPath(copyAndFree(tilde_expand(historyFile.c_str())))
14 {
15 read_history(m_historyPath.c_str());
16 }
17
18 ReadLine::~ReadLine()
19 {
20 }
21
22 bool ReadLine::get(const String& prompt, String& out)
23 {
24 char *line = readline(prompt.c_str());
25 if (line == NULL) {
26 return false;
27 }
28 add_history(line); // Add input to in-memory history
29 append_history(1, m_historyPath.c_str());
30
31 out = line;
32
33 return true;
34 }