diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2018-03-22 18:44:54 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2018-03-22 18:44:54 +0100 |
| commit | 10a7462e795bc88e409533fadeab012dd1859da2 (patch) | |
| tree | 0743a8fecd401db32636fd29c278ad5cc593c096 /src/extsh.cpp | |
| parent | 66f66b7818b7cf47a20eae6b940e06c2ee12fe8a (diff) | |
| download | extfs-10a7462e795bc88e409533fadeab012dd1859da2.tar.xz extfs-10a7462e795bc88e409533fadeab012dd1859da2.zip | |
extsh: add linenoise input handlingmaster
Diffstat (limited to 'src/extsh.cpp')
| -rw-r--r-- | src/extsh.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/extsh.cpp b/src/extsh.cpp index 9dfeea8..1c223d9 100644 --- a/src/extsh.cpp +++ b/src/extsh.cpp @@ -1,5 +1,7 @@ #include "fs/extfs.hpp" +#include <linenoise.h> + #include <cstdint> #include <iostream> #include <stdexcept> @@ -15,7 +17,7 @@ enum struct result : std::uint8_t result process(std::string const & command) { - if(command == "exit") + if(command == "exit" || command.empty()) { return result::exit; } @@ -25,10 +27,19 @@ result process(std::string const & command) std::string prompt(fs::extfs const & disk) { - std::cout << '[' << (disk.has_label() ? disk.label() : "No Label") << "] >>> "; - std::string command{}; - std::cin >> command; - return command; + using namespace std::string_literals; + + auto const promptText = "["s + (disk.has_label() ? disk.label() : "No Label") + "] > "; + auto const input = linenoise(promptText.c_str()); + if(input) + { + linenoiseHistoryAdd(input); + auto const inputString = std::string{input}; + linenoiseFree(input); + return inputString; + } + + return {}; } void repl(fs::extfs & disk) @@ -59,6 +70,7 @@ int main(int argc, char const * argv[]) if(disk.open()) { + linenoiseHistorySetMaxLen(1024); repl(disk); } else |
