input2 added
This commit is contained in:
32
ml_util.cpp
32
ml_util.cpp
@@ -1,13 +1,14 @@
|
||||
|
||||
#include "ml_util.h"
|
||||
#include "string.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
// #include <filesystem>
|
||||
|
||||
std::vector<std::string> commands {};
|
||||
std::string history_file;
|
||||
|
||||
// kryplove z applu a jejich problemy s filesystemem
|
||||
/*
|
||||
@@ -20,8 +21,7 @@ std::string get_history_file_dir() {
|
||||
}
|
||||
*/
|
||||
|
||||
std::string get_history_file_dir() {
|
||||
std::string file{"/.ml_history.txt"};
|
||||
std::string get_history_filepath(const std::string &file) {
|
||||
const char *t = std::getenv("HOME");
|
||||
|
||||
if (t == nullptr) return "/tmp/" + file;
|
||||
@@ -30,33 +30,37 @@ std::string get_history_file_dir() {
|
||||
|
||||
MlEnvironment * repl_env = nullptr;
|
||||
|
||||
void setup_linenoise(const MlEnvironment &env, const std::map<const std::string, Builtin> &builtins) {
|
||||
repl_env = (MlEnvironment*) &env;
|
||||
|
||||
std::string history_file = get_history_file_dir();
|
||||
void setup_linenoise() {
|
||||
history_file = get_history_filepath("/.ml_history.txt");
|
||||
linenoiseHistoryLoad(history_file.c_str());
|
||||
|
||||
linenoiseHistorySetMaxLen(500);
|
||||
linenoiseSetMultiLine(1);
|
||||
}
|
||||
|
||||
void setup_linenoise_repl(const MlEnvironment &env, const std::map<const std::string, Builtin> &builtins) {
|
||||
// basic linenoise setup must be already set
|
||||
|
||||
repl_env = (MlEnvironment*) &env;
|
||||
|
||||
linenoiseSetCompletionCallback(completion);
|
||||
linenoiseSetHintsCallback(hints);
|
||||
linenoiseSetMultiLine(1);
|
||||
linenoiseHistoryLoad(history_file.c_str());
|
||||
|
||||
commands.reserve(builtins.size());
|
||||
for(auto it = builtins.begin(); it != builtins.end(); ++it)
|
||||
commands.push_back(it->first);
|
||||
}
|
||||
|
||||
void linenoise_line_read(char *line) {
|
||||
linenoiseHistoryAdd(line);
|
||||
void linenoise_add_to_history(const std::string &line) {
|
||||
if (!line.empty())
|
||||
linenoiseHistoryAdd(line.c_str());
|
||||
}
|
||||
|
||||
void close_linenoise() {
|
||||
std::string history_file = get_history_file_dir();
|
||||
|
||||
linenoiseHistorySave(history_file.c_str());
|
||||
}
|
||||
|
||||
size_t last_token_index( std::string str ) {
|
||||
size_t last_token_index(std::string str) {
|
||||
// remove trailing white space
|
||||
while( !str.empty() && std::isspace( str.back() ) ) str.pop_back() ;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user