forked from lix-project/lix
refactor: repl prompts are now the job of the interacter
Change-Id: I17c2873dfbbff303cdbdc7a8903deb8409ce3026
This commit is contained in:
parent
95a87f2c2a
commit
1758a6ef25
|
@ -124,7 +124,18 @@ ReadlineLikeInteracter::Guard ReadlineLikeInteracter::init(detail::ReplCompleter
|
||||||
return restoreRepl;
|
return restoreRepl;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReadlineLikeInteracter::getLine(std::string & input, const std::string & prompt)
|
static constexpr const char * promptForType(ReplPromptType promptType)
|
||||||
|
{
|
||||||
|
switch (promptType) {
|
||||||
|
case ReplPromptType::ReplPrompt:
|
||||||
|
return "nix-repl> ";
|
||||||
|
case ReplPromptType::ContinuationPrompt:
|
||||||
|
return " ";
|
||||||
|
}
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ReadlineLikeInteracter::getLine(std::string & input, ReplPromptType promptType)
|
||||||
{
|
{
|
||||||
struct sigaction act, old;
|
struct sigaction act, old;
|
||||||
sigset_t savedSignalMask, set;
|
sigset_t savedSignalMask, set;
|
||||||
|
@ -150,7 +161,7 @@ bool ReadlineLikeInteracter::getLine(std::string & input, const std::string & pr
|
||||||
};
|
};
|
||||||
|
|
||||||
setupSignals();
|
setupSignals();
|
||||||
char * s = readline(prompt.c_str());
|
char * s = readline(promptForType(promptType));
|
||||||
Finally doFree([&]() { free(s); });
|
Finally doFree([&]() { free(s); });
|
||||||
restoreSignals();
|
restoreSignals();
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ public:
|
||||||
|
|
||||||
virtual Guard init(detail::ReplCompleterMixin * repl) = 0;
|
virtual Guard init(detail::ReplCompleterMixin * repl) = 0;
|
||||||
/** Returns a boolean of whether the interacter got EOF */
|
/** Returns a boolean of whether the interacter got EOF */
|
||||||
virtual bool getLine(std::string & input, const std::string & prompt) = 0;
|
virtual bool getLine(std::string & input, ReplPromptType promptType) = 0;
|
||||||
virtual ~ReplInteracter(){};
|
virtual ~ReplInteracter(){};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
virtual Guard init(detail::ReplCompleterMixin * repl) override;
|
virtual Guard init(detail::ReplCompleterMixin * repl) override;
|
||||||
virtual bool getLine(std::string & input, const std::string & prompt) override;
|
virtual bool getLine(std::string & input, ReplPromptType promptType) override;
|
||||||
virtual ~ReadlineLikeInteracter() override;
|
virtual ~ReadlineLikeInteracter() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -196,7 +196,7 @@ ReplExitStatus NixRepl::mainLoop()
|
||||||
logger->pause();
|
logger->pause();
|
||||||
// When continuing input from previous lines, don't print a prompt, just align to the same
|
// When continuing input from previous lines, don't print a prompt, just align to the same
|
||||||
// number of chars as the prompt.
|
// number of chars as the prompt.
|
||||||
if (!interacter->getLine(input, input.empty() ? "nix-repl> " : " ")) {
|
if (!interacter->getLine(input, input.empty() ? ReplPromptType::ReplPrompt : ReplPromptType::ContinuationPrompt)) {
|
||||||
// Ctrl-D should exit the debugger.
|
// Ctrl-D should exit the debugger.
|
||||||
state->debugStop = false;
|
state->debugStop = false;
|
||||||
logger->cout("");
|
logger->cout("");
|
||||||
|
|
Loading…
Reference in a new issue