about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKai Harries <kai.harries@gmail.com>2018-11-15T20·15+0100
committerKai Harries <kai.harries@gmail.com>2018-11-20T14·43+0100
commitde5997332d0f9b1347978ea0d4e7ead2b59d2dd6 (patch)
tree47e9d47e54819bebe79d7a773ce3c12222e192df
parentb289d86cd1ef5a8df0ce177dfc04b4e5fec3fa14 (diff)
repl: give user the choice between libeditline and libreadline
The goal is to support libeditline AND libreadline and let the user
decide at compile time which one to use.

Add a compile time option to use libreadline instead of
libeditline. If compiled against libreadline completion functionality
is lost because of a incompatibility between libeditlines and
libreadlines completion function. Completion with libreadline is
possible and can be added later.

To use libreadline instead of libeditline the environment
variables 'EDITLINE_LIBS' and 'EDITLINE_CFLAGS' have to been set
during the ./configure step.

Example:

  EDITLINE_LIBS="/usr/lib/x86_64-linux-gnu/libhistory.so /usr/lib/x86_64-linux-gnu/libreadline.so"
  EDITLINE_CFLAGS="-DREADLINE"

The reason for this change is that for example on Debian already three
different editline libraries exist but none of those is compatible the
flavor used by nix. My hope is that with this change it would be
easier to port nix to systems that have already libreadline available.
-rw-r--r--src/nix/repl.cc9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/nix/repl.cc b/src/nix/repl.cc
index 39c6520999c0..d93fd770e807 100644
--- a/src/nix/repl.cc
+++ b/src/nix/repl.cc
@@ -5,7 +5,12 @@
 
 #include <setjmp.h>
 
+#ifdef READLINE
+#include <readline/history.h>
+#include <readline/readline.h>
+#else
 #include <editline.h>
+#endif
 
 #include "shared.hh"
 #include "eval.hh"
@@ -202,11 +207,15 @@ void NixRepl::mainLoop(const std::vector<std::string> & files)
     // Allow nix-repl specific settings in .inputrc
     rl_readline_name = "nix-repl";
     createDirs(dirOf(historyFile));
+#ifndef READLINE
     el_hist_size = 1000;
+#endif
     read_history(historyFile.c_str());
     curRepl = this;
+#ifndef READLINE
     rl_set_complete_func(completionCallback);
     rl_set_list_possib_func(listPossibleCallback);
+#endif
 
     std::string input;