Add source code.
This commit is contained in:
1 parent
dab19ace02
commit
0b8a7b3cdc
31 files changed
+2809
No files matched your search
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Completion.h"
|
||||
|
||||
// Reads one line with cursor editing, history (up/down) and tab completion.
|
||||
// Falls back to plain std::getline when stdin/stdout are not a terminal.
|
||||
class LineEditor {
|
||||
public:
|
||||
using CompletionFn = std::function<Completion(const std::string& textBeforeCursor)>;
|
||||
|
||||
LineEditor();
|
||||
|
||||
void setCompleter(const CompletionFn& completer);
|
||||
void setHistoryFile(const std::string& path); // loads it and appends new entries
|
||||
void addHistory(const std::string& line);
|
||||
|
||||
// Returns false on end of input (Ctrl-D on an empty line, or closed stdin).
|
||||
bool readLine(const std::string& prompt, std::string& line);
|
||||
|
||||
private:
|
||||
bool readPlain(const std::string& prompt, std::string& line);
|
||||
bool readInteractive(const std::string& prompt, std::string& line);
|
||||
|
||||
CompletionFn completer_;
|
||||
std::vector<std::string> history_;
|
||||
std::string historyFile_;
|
||||
};
|
||||
Reference in new issue
Block a user