diff --git a/src/readline.cpp b/src/readline.cpp index a210b66..f3a1cef 100644 --- a/src/readline.cpp +++ b/src/readline.cpp @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include "ruc/format/color.h" @@ -18,7 +20,7 @@ namespace blaze { Readline::Readline(bool pretty_print, std::string_view history_path) : m_pretty_print(pretty_print) - , m_history_path(history_path) + , m_history_path(tilde_expand(history_path.data())) { if (!pretty_print) { m_prompt = "user> "; @@ -28,9 +30,16 @@ Readline::Readline(bool pretty_print, std::string_view history_path) m_prompt += format(" \033[1m"); } - read_history(tilde_expand(history_path.data())); + read_history(m_history_path); } +Readline::~Readline() +{ + std::free(m_history_path); +} + +// ----------------------------------------- + bool Readline::get(std::string& output) { char* line = readline(m_prompt.c_str()); @@ -40,7 +49,7 @@ bool Readline::get(std::string& output) // Add input to in-memory history add_history(line); - append_history(1, m_history_path.data()); + append_history(1, m_history_path); output = line; std::free(line); diff --git a/src/readline.h b/src/readline.h index da2d4d0..79effb0 100644 --- a/src/readline.h +++ b/src/readline.h @@ -16,14 +16,14 @@ namespace blaze { class Readline { public: Readline(bool pretty_print, std::string_view history_path); - virtual ~Readline() {} + virtual ~Readline(); bool get(std::string& output); private: bool m_pretty_print { false }; std::string m_prompt; - std::string_view m_history_path; + char* m_history_path; }; } // namespace blaze diff --git a/src/step2_eval.cpp b/src/step2_eval.cpp index 4efffa1..8a896ac 100644 --- a/src/step2_eval.cpp +++ b/src/step2_eval.cpp @@ -104,5 +104,3 @@ auto main(int argc, char* argv[]) -> int return 0; } #endif - -// - Add AST node printing support to ruc::format