aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Dietz <w@wdtz.org>2017-12-26 19:22:28 -0600
committerWill Dietz <w@wdtz.org>2017-12-26 19:25:50 -0600
commitbd17ccf1d822ba76cdd58e9547bc18db35189c55 (patch)
tree5de613f02d56ac526e3015afcb04481cfbc2bfd3
parentaa43cbb7646e880f871df4280f8a1909520136f0 (diff)
nix repl: use linenoiseKeyType to differentiate ^C and ^D
Fixes #1757.
-rw-r--r--src/nix/repl.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/nix/repl.cc b/src/nix/repl.cc
index 1adb816c5..921620917 100644
--- a/src/nix/repl.cc
+++ b/src/nix/repl.cc
@@ -186,7 +186,16 @@ bool NixRepl::getLine(string & input, const std::string &prompt)
{
char * s = linenoise(prompt.c_str());
Finally doFree([&]() { free(s); });
- if (!s) return false;
+ if (!s) {
+ switch (auto type = linenoiseKeyType()) {
+ case 1: // ctrl-C
+ return true;
+ case 2: // ctrl-D
+ return false;
+ default:
+ throw Error(format("Unexpected linenoise keytype: %1%") % type);
+ }
+ }
input += s;
return true;
}