about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWill Dietz <w@wdtz.org>2017-12-27T01·22-0600
committerWill Dietz <w@wdtz.org>2017-12-27T01·25-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 1adb816c5bf0..9216209173d9 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;
 }