diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/extsh.cpp | 22 |
2 files changed, 18 insertions, 5 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e09c4a2..467cf46 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,7 @@ add_subdirectory(fs) add_executable(extsh extsh.cpp + $<TARGET_OBJECTS:linenoise> ) target_link_libraries(extsh extfs 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 |
