aboutsummaryrefslogtreecommitdiff
path: root/src/libcmd/repl-interacter.cc
diff options
context:
space:
mode:
authorJade Lovelace <lix@jade.fyi>2024-03-09 23:59:50 -0800
committerJade Lovelace <lix@jade.fyi>2024-03-11 14:14:43 -0700
commitbe2b87ed4dda865406096196804b784f4c293687 (patch)
treec4793e79fcbb4e3c29ad27931a072969c75b054d /src/libcmd/repl-interacter.cc
parentb06a39211460033305c5264a456161c75ed88425 (diff)
add automated usage mode to the repl
This is definitely not a stable thing, but it does feel slightly crimes to put it as an experimental feature. Shrug, up for bikeshedding. Change-Id: I6ef176e3dee6fb1cac9c0a7a60d553a2c63ea728
Diffstat (limited to 'src/libcmd/repl-interacter.cc')
-rw-r--r--src/libcmd/repl-interacter.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libcmd/repl-interacter.cc b/src/libcmd/repl-interacter.cc
index 18c1cad0f..829383add 100644
--- a/src/libcmd/repl-interacter.cc
+++ b/src/libcmd/repl-interacter.cc
@@ -1,4 +1,6 @@
#include <cstdio>
+#include <iostream>
+#include <string>
#ifdef READLINE
#include <readline/history.h>
@@ -183,4 +185,24 @@ ReadlineLikeInteracter::~ReadlineLikeInteracter()
write_history(historyFile.c_str());
}
+AutomationInteracter::Guard AutomationInteracter::init(detail::ReplCompleterMixin *)
+{
+ return Guard([] {});
+}
+
+// ASCII ENQ character
+constexpr const char * automationPrompt = "\x05";
+
+bool AutomationInteracter::getLine(std::string & input, ReplPromptType promptType)
+{
+ std::cout << std::unitbuf;
+ std::cout << automationPrompt;
+ if (!std::getline(std::cin, input)) {
+ // reset failure bits on EOF
+ std::cin.clear();
+ return false;
+ }
+ return true;
+}
+
};