repl: Support cross-session history (#301)

This commit is contained in:
Tyler Wilding
2021-03-02 21:05:13 -08:00
committed by GitHub
parent 3e0e370343
commit 2eca9ab801
9 changed files with 81 additions and 5 deletions
+5 -4
View File
@@ -10,9 +10,10 @@
*/
#include "Reader.h"
#include "third-party/linenoise.h"
#include "common/util/FileUtil.h"
#include "third-party/fmt/core.h"
#include <filesystem>
#include "ReplHistory.h"
namespace goos {
@@ -103,7 +104,7 @@ void TextStream::seek_past_whitespace_and_comments() {
Reader::Reader() {
// third-party library used for a fancy line in
linenoise::SetHistoryMaxLen(400);
ReplHistory::repl_set_history_max_size(5000);
// add default macros
add_reader_macro("'", "quote");
@@ -142,8 +143,8 @@ Object Reader::read_from_stdin(const std::string& prompt_name) {
std::string line;
// escape code will make sure that we remove any color
std::string prompt_full = "\033[0m" + prompt_name + "> ";
linenoise::Readline(prompt_full.c_str(), line);
linenoise::AddHistory(line.c_str());
ReplHistory::repl_readline(prompt_full.c_str(), line);
ReplHistory::repl_add_to_history(line.c_str());
// todo, decide if we should keep reading or not.
// create text fragment and add to the DB