mirror of https://gitee.com/bigwinds/arangodb
removed readline
This commit is contained in:
parent
07aa9a7daf
commit
b7de227138
|
@ -691,7 +691,7 @@ if (OPENSSL_LIB_PATH)
|
|||
endif ()
|
||||
|
||||
################################################################################
|
||||
### @brief READLINE or LINENOISE
|
||||
### @brief LINENOISE
|
||||
################################################################################
|
||||
|
||||
if (MSVC)
|
||||
|
|
10
Makefile.am
10
Makefile.am
|
@ -118,7 +118,6 @@ AM_CPPFLAGS = \
|
|||
@LIBEV_CPPFLAGS@ \
|
||||
@MATH_CPPFLAGS@ \
|
||||
@OPENSSL_CPPFLAGS@ \
|
||||
@READLINE_CPPFLAGS@ \
|
||||
@ICU_CPPFLAGS@ \
|
||||
@ZLIB_CPPFLAGS@ \
|
||||
@V8_CPPFLAGS@
|
||||
|
@ -131,7 +130,6 @@ AM_LDFLAGS = \
|
|||
@LIBEV_LDFLAGS@ \
|
||||
@MATH_LDFLAGS@ \
|
||||
@OPENSSL_LDFLAGS@ \
|
||||
@READLINE_LDFLAGS@ \
|
||||
@ICU_LDFLAGS@ \
|
||||
@ZLIB_LDFLAGS@ \
|
||||
@V8_LDFLAGS@
|
||||
|
@ -147,8 +145,7 @@ LIBS = \
|
|||
@MATH_LIBS@ \
|
||||
@OPENSSL_LIBS@ \
|
||||
@ICU_LIBS@ \
|
||||
@ZLIB_LIBS@ \
|
||||
@READLINE_LIBS@
|
||||
@ZLIB_LIBS@
|
||||
|
||||
## -----------------------------------------------------------------------------
|
||||
## --SECTION-- LIBRARIES & PROGRAMS
|
||||
|
@ -528,11 +525,6 @@ cmake-setup:
|
|||
-D OPENSSL_LIBS= \
|
||||
-D OPENSSL_VERSION= \
|
||||
\
|
||||
-D READLINE_INCLUDE= \
|
||||
-D READLINE_LIB_PATH= \
|
||||
-D READLINE_LIBS= \
|
||||
-D READLINE_VERSION= \
|
||||
\
|
||||
-D V8_INCLUDE= \
|
||||
-D V8_LIB_PATH= \
|
||||
-D V8_LIBS= \
|
||||
|
|
|
@ -279,7 +279,6 @@ target_link_libraries(
|
|||
${ICU_LIBS}
|
||||
${BT_LIBS}
|
||||
${ZLIB_LIBS}
|
||||
${READLINE_LIBS}
|
||||
${OPENSSL_LIBS}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${MSVC_LIBS}
|
||||
|
|
|
@ -98,7 +98,6 @@ namespace triagens {
|
|||
///
|
||||
/// This sequence must be used before any non-visible characters in the prompt.
|
||||
///
|
||||
/// From readline/display.c:
|
||||
/// \\001 (^A) start non-visible characters
|
||||
/// \\002 (^B) end non-visible characters
|
||||
///
|
||||
|
|
|
@ -48,7 +48,6 @@ target_link_libraries(
|
|||
${ICU_LIBS}
|
||||
${BT_LIBS}
|
||||
${ZLIB_LIBS}
|
||||
${READLINE_LIBS}
|
||||
${OPENSSL_LIBS}
|
||||
${MSVC_LIBS}
|
||||
)
|
||||
|
@ -98,7 +97,6 @@ target_link_libraries(
|
|||
${ICU_LIBS}
|
||||
${BT_LIBS}
|
||||
${ZLIB_LIBS}
|
||||
${READLINE_LIBS}
|
||||
${OPENSSL_LIBS}
|
||||
${MSVC_LIBS}
|
||||
)
|
||||
|
@ -149,7 +147,6 @@ target_link_libraries(
|
|||
${ICU_LIBS}
|
||||
${BT_LIBS}
|
||||
${ZLIB_LIBS}
|
||||
${READLINE_LIBS}
|
||||
${OPENSSL_LIBS}
|
||||
${MSVC_LIBS}
|
||||
)
|
||||
|
@ -198,7 +195,6 @@ target_link_libraries(
|
|||
${ICU_LIBS}
|
||||
${BT_LIBS}
|
||||
${ZLIB_LIBS}
|
||||
${READLINE_LIBS}
|
||||
${OPENSSL_LIBS}
|
||||
${MSVC_LIBS}
|
||||
)
|
||||
|
@ -251,7 +247,6 @@ target_link_libraries(
|
|||
${BT_LIBS}
|
||||
${ICU_LIBS}
|
||||
${ZLIB_LIBS}
|
||||
${READLINE_LIBS}
|
||||
${OPENSSL_LIBS}
|
||||
${MSVC_LIBS}
|
||||
)
|
||||
|
|
|
@ -1548,20 +1548,10 @@ static void RunShell (v8::Isolate* isolate, v8::Handle<v8::Context> context, boo
|
|||
#ifdef TRI_HAVE_LINENOISE
|
||||
|
||||
// linenoise doesn't need escape sequences for escape sequences
|
||||
// TODO: this should be a function defined in "console"
|
||||
goodPrompt = TRI_SHELL_COLOR_BOLD_GREEN + dynamicPrompt + TRI_SHELL_COLOR_RESET;
|
||||
badPrompt = TRI_SHELL_COLOR_BOLD_RED + dynamicPrompt + TRI_SHELL_COLOR_RESET;
|
||||
|
||||
#else
|
||||
// readline does...
|
||||
goodPrompt = string()
|
||||
+ ArangoClient::PROMPT_IGNORE_START + TRI_SHELL_COLOR_BOLD_GREEN + ArangoClient::PROMPT_IGNORE_END
|
||||
+ dynamicPrompt
|
||||
+ ArangoClient::PROMPT_IGNORE_START + TRI_SHELL_COLOR_RESET + ArangoClient::PROMPT_IGNORE_END;
|
||||
|
||||
badPrompt = string()
|
||||
+ ArangoClient::PROMPT_IGNORE_START + TRI_SHELL_COLOR_BOLD_RED + ArangoClient::PROMPT_IGNORE_END
|
||||
+ dynamicPrompt
|
||||
+ ArangoClient::PROMPT_IGNORE_START + TRI_SHELL_COLOR_RESET + ArangoClient::PROMPT_IGNORE_END;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
|
|
161
configure.ac
161
configure.ac
|
@ -207,168 +207,9 @@ dnl ----------------------------------------------------------------------------
|
|||
m4_include([m4/external.math])
|
||||
|
||||
dnl ----------------------------------------------------------------------------
|
||||
dnl READLINE
|
||||
dnl REPL
|
||||
dnl ----------------------------------------------------------------------------
|
||||
|
||||
AC_MSG_NOTICE([--------------------------------------------------------------------------------])
|
||||
AC_MSG_NOTICE([CHECKING FOR READLINE])
|
||||
AC_MSG_NOTICE([--------------------------------------------------------------------------------])
|
||||
|
||||
AC_LANG(C)
|
||||
|
||||
AC_ARG_ENABLE(readline,
|
||||
AS_HELP_STRING([--enable-readline], [enable readline support (default: yes)]),
|
||||
tr_READLINE="$enableval",
|
||||
tr_READLINE="maybe"
|
||||
)
|
||||
|
||||
if test "x$tr_DARWIN" = xyes; then
|
||||
READLINE=/usr/local/opt/readline
|
||||
READLINE_CPPFLAGS="-I$READLINE/include"
|
||||
READLINE_INCLUDE="$READLINE/include"
|
||||
READLINE_LDFLAGS="-L$READLINE/lib"
|
||||
READLINE_LIB_PATH="$READLINE/lib"
|
||||
fi
|
||||
|
||||
AC_ARG_WITH(readline,
|
||||
AS_HELP_STRING([--with-readline=DIR], [where the readline library and includes are located]),
|
||||
[READLINE_CPPFLAGS="-I$withval/include"
|
||||
READLINE_INCLUDE="$withval/include"
|
||||
READLINE_LDFLAGS="-L$withval/lib"
|
||||
READLINE_LIB_PATH="$withval/lib"
|
||||
READLINE="$withval"]
|
||||
)
|
||||
|
||||
AC_ARG_WITH(readline-lib,
|
||||
AS_HELP_STRING([--with-readline-lib=DIR], [where the readline library is located]),
|
||||
[READLINE_LDFLAGS="-L$withval"
|
||||
READLINE_LIB_PATH="$withval"]
|
||||
)
|
||||
|
||||
dnl checks for the READLINE library
|
||||
|
||||
if test "x$READLINE_CPPFLAGS" != x; then
|
||||
TR_INCLUDE([READLINE_CPPFLAGS])
|
||||
fi
|
||||
|
||||
dnl save flags
|
||||
|
||||
SAVE_CPPFLAGS="$CPPFLAGS"
|
||||
CPPFLAGS="$CPPFLAGS $READLINE_CPPFLAGS"
|
||||
|
||||
SAVE_LDFLAGS="$LDFLAGS"
|
||||
LDFLAGS="$LDFLAGS $READLINE_LDFLAGS"
|
||||
|
||||
SAVE_LIBS="$LIBS"
|
||||
|
||||
dnl check for header and library
|
||||
|
||||
if test "x$tr_READLINE" = xyes -o "x$tr_READLINE" = xmaybe; then
|
||||
ch_READLINE="$tr_READLINE"
|
||||
|
||||
AC_CHECK_HEADERS(readline/readline.h, [tr_READLINE="yes"], [tr_READLINE="no"])
|
||||
|
||||
if test "x$tr_READLINE" = xyes; then
|
||||
AC_CHECK_LIB([readline], [readline], [READLINE_LIBS="-lreadline" tr_READLINE="yes"], [tr_READLINE="no"])
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING([READLINE support])
|
||||
|
||||
if test "x$tr_READLINE" != xyes; then
|
||||
AC_MSG_RESULT([not found])
|
||||
|
||||
if test "x$ch_READLINE" = xyes; then
|
||||
AC_MSG_ERROR([Please install readline support])
|
||||
fi
|
||||
else
|
||||
AC_MSG_RESULT([readline])
|
||||
fi
|
||||
else
|
||||
AC_MSG_CHECKING([READLINE support])
|
||||
AC_MSG_RESULT([disabled])
|
||||
fi
|
||||
|
||||
dnl grep readline version number
|
||||
|
||||
if test "x$tr_READLINE" = xyes; then
|
||||
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
#include <readline/readline.h>
|
||||
|
||||
main () {
|
||||
#if defined(RL_VERSION_MAJOR) && defined(RL_VERSION_MINOR)
|
||||
long sdnhg36ed = RL_VERSION_MAJOR RL_VERSION_MINOR ;
|
||||
#else
|
||||
long sdnhg36ed = RL_READLINE_VERSION hex ;
|
||||
#endif
|
||||
}
|
||||
|
||||
_ACEOF
|
||||
|
||||
AC_MSG_CHECKING([READLINE version])
|
||||
eval "$ac_cpp conftest.$ac_ext" | fgrep "long sdnhg36ed" | awk '{print $4 "." $5}' > conftest.output
|
||||
READLINE_VERSION=`cat conftest.output`
|
||||
|
||||
if test -z "$READLINE_VERSION"; then
|
||||
AC_MSG_ERROR([Readline support is not working. Please re-install readline support])
|
||||
fi
|
||||
|
||||
AC_MSG_RESULT([$READLINE_VERSION])
|
||||
rm -f conftest*
|
||||
|
||||
if test "x$tr_DARWIN" = xyes; then
|
||||
case "$READLINE_VERSION" in
|
||||
6.*|5.*)
|
||||
;;
|
||||
|
||||
*)
|
||||
AC_MSG_ERROR([Please install readline 6 from brew. If you have a non-standard brew location, use "--with-readline".])
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
|
||||
dnl restore flags and set readline flags
|
||||
|
||||
LIBS="$SAVE_LIBS"
|
||||
LDFLAGS="$SAVE_LDFLAGS"
|
||||
CPPFLAGS="$SAVE_CPPFLAGS"
|
||||
|
||||
if test "x$tr_READLINE" = xyes; then
|
||||
CPPFLAGS="$CPPFLAGS -DHAVE_READLINE=1"
|
||||
READLINE_CPPFLAGS="${READLINE_CPPFLAGS} -DTRI_READLINE_VERSION='\"${READLINE_VERSION}\"'"
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(ENABLE_READLINE, test "x$tr_READLINE" = xyes)
|
||||
|
||||
if test "x$tr_READLINE" = xyes; then
|
||||
AC_DEFINE_UNQUOTED(TRI_HAVE_READLINE, 1, [true if readline is used])
|
||||
fi
|
||||
|
||||
dnl add substitutions
|
||||
|
||||
AC_SUBST(READLINE_VERSION)
|
||||
AC_SUBST(READLINE_CPPFLAGS)
|
||||
AC_SUBST(READLINE_INCLUDE)
|
||||
AC_SUBST(READLINE_LDFLAGS)
|
||||
AC_SUBST(READLINE_LIB_PATH)
|
||||
AC_SUBST(READLINE_LIBS)
|
||||
|
||||
dnl informational output
|
||||
|
||||
if test "x$tr_READLINE" = xyes; then
|
||||
LIB_INFO="$LIB_INFO|READLINE VERSION: ${READLINE_VERSION}"
|
||||
|
||||
LIB_INFO="$LIB_INFO|READLINE_CPPFLAGS: ${READLINE_CPPFLAGS}"
|
||||
LIB_INFO="$LIB_INFO|READLINE_LDFLAGS: ${READLINE_LDFLAGS}"
|
||||
LIB_INFO="$LIB_INFO|READLINE_LIBS: ${READLINE_LIBS}"
|
||||
else
|
||||
LIB_INFO="$LIB_INFO|READLINE VERSION: disabled"
|
||||
fi
|
||||
|
||||
LIB_INFO="$LIB_INFO|."
|
||||
|
||||
dnl ----------------------------------------------------------------------------
|
||||
dnl OPENSSL
|
||||
dnl ----------------------------------------------------------------------------
|
||||
|
|
|
@ -66,12 +66,6 @@
|
|||
|
||||
#undef TRI_ENABLE_FAILURE_TESTS
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief enable readline
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#undef TRI_HAVE_READLINE
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief enable linenoise
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -35,7 +35,6 @@ else ()
|
|||
Basics/terminal-utils-posix.cpp
|
||||
Basics/threads-posix.cpp
|
||||
Rest/EndpointUnixDomain.cpp
|
||||
Utilities/ReadlineShell.cpp
|
||||
)
|
||||
endif ()
|
||||
|
||||
|
|
|
@ -97,13 +97,6 @@ lib_libarango_a_SOURCES = \
|
|||
lib/Zip/unzip.cpp \
|
||||
lib/Zip/zip.cpp
|
||||
|
||||
if ENABLE_READLINE
|
||||
|
||||
lib_libarango_a_SOURCES += \
|
||||
lib/Utilities/ReadlineShell.cpp
|
||||
|
||||
endif
|
||||
|
||||
################################################################################
|
||||
### @brief library "libarango.a", client part
|
||||
################################################################################
|
||||
|
|
|
@ -79,10 +79,6 @@ void Version::initialize () {
|
|||
Values["maintainer-mode"] = "false";
|
||||
#endif
|
||||
|
||||
#ifdef TRI_READLINE_VERSION
|
||||
Values["readline-version"] = getReadlineVersion();
|
||||
#endif
|
||||
|
||||
#ifdef TRI_HAVE_TCMALLOC
|
||||
Values["tcmalloc"] = "true";
|
||||
#else
|
||||
|
@ -182,19 +178,11 @@ std::string Version::getZLibVersion () {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get readline version
|
||||
/// @brief get REPL version
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string Version::getReadlineVersion () {
|
||||
#ifdef TRI_READLINE_VERSION
|
||||
std::string const value(TRI_READLINE_VERSION);
|
||||
|
||||
if (value.size() >= 2) {
|
||||
return value;
|
||||
}
|
||||
// fallthrough
|
||||
#endif
|
||||
return std::string("unknown version");
|
||||
std::string Version::getReplVersion () {
|
||||
return std::string("dummy shell");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -282,9 +270,7 @@ std::string Version::getVerboseVersionString () {
|
|||
#endif
|
||||
<< "ICU " << getICUVersion() << ", "
|
||||
<< "V8 " << getV8Version() << ", "
|
||||
#ifdef TRI_READLINE_VERSION
|
||||
<< "Readline " << getReadlineVersion() << ", "
|
||||
#endif
|
||||
<< "REPL " << getReplVersion() << ", "
|
||||
<< getOpenSSLVersion();
|
||||
|
||||
return version.str();
|
||||
|
|
|
@ -112,10 +112,10 @@ namespace triagens {
|
|||
static std::string getZLibVersion ();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get readline version
|
||||
/// @brief get repl version
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static std::string getReadlineVersion ();
|
||||
static std::string getReplVersion ();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get ICU version
|
||||
|
|
|
@ -1,382 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief line editor using readline
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2014-2015 ArangoDB GmbH, Cologne, Germany
|
||||
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Jan Steemann
|
||||
/// @author Copyright 2014-2015, ArangoDB GmbH, Cologne, Germany
|
||||
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "ReadlineShell.h"
|
||||
|
||||
#include "Basics/tri-strings.h"
|
||||
#include "Utilities/Completer.h"
|
||||
#include "Utilities/LineEditor.h"
|
||||
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
#include <v8.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace triagens;
|
||||
using namespace arangodb;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private functions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace {
|
||||
Completer* COMPLETER;
|
||||
}
|
||||
|
||||
static char WordBreakCharacters[] = {
|
||||
' ', '\t', '\n', '"', '\\', '\'', '`', '@',
|
||||
'<', '>', '=', ';', '|', '&', '{', '}', '(', ')',
|
||||
'\0'
|
||||
};
|
||||
|
||||
static char* CompletionGenerator (char const* text, int state) {
|
||||
static size_t currentIndex;
|
||||
static vector<string> result;
|
||||
|
||||
// compute the possible completion
|
||||
if (state == 0) {
|
||||
result = COMPLETER->alternatives(text);
|
||||
LineEditor::sortAlternatives(result);
|
||||
}
|
||||
|
||||
if (currentIndex < result.size()) {
|
||||
return TRI_SystemDuplicateString(result[currentIndex++].c_str());
|
||||
}
|
||||
|
||||
currentIndex = 0;
|
||||
result.clear();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static char** AttemptedCompletion (char const* text, int start, int end) {
|
||||
char** result = rl_completion_matches(text, CompletionGenerator);
|
||||
rl_attempted_completion_over = true;
|
||||
|
||||
if (result != nullptr && result[0] != nullptr && result[1] == nullptr) {
|
||||
size_t n = strlen(result[0]);
|
||||
|
||||
if (result[0][n - 1] == ')') {
|
||||
result[0][n - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
#if RL_READLINE_VERSION >= 0x0500
|
||||
// issue #289
|
||||
rl_completion_suppress_append = 1;
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief callback function that readline calls periodically while waiting
|
||||
/// for input and being idle
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int ReadlineIdle () {
|
||||
auto instance = ReadlineShell::instance();
|
||||
|
||||
if (instance != nullptr && instance->getLoopState() == 2) {
|
||||
rl_done = 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief callback function that readline calls when the input is completed
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void ReadlineInputCompleted (char* value) {
|
||||
// if we don't clear the prompt here, readline will display it instantly
|
||||
// the user pressed the return key. this is not desired because when we
|
||||
// wait for input afterwards, readline will display the prompt again
|
||||
rl_set_prompt("");
|
||||
|
||||
auto instance = ReadlineShell::instance();
|
||||
|
||||
if (instance != nullptr) {
|
||||
if (instance->getLoopState() == 2) {
|
||||
|
||||
// CTRL-C received
|
||||
rl_done = 1;
|
||||
|
||||
// replace current input with nothing
|
||||
rl_replace_line("", 0);
|
||||
|
||||
instance->setLastInput("");
|
||||
}
|
||||
else if (value == nullptr) {
|
||||
rl_done = 1;
|
||||
rl_replace_line("", 0);
|
||||
instance->setLoopState(3);
|
||||
instance->setLastInput("");
|
||||
}
|
||||
else {
|
||||
instance->setLoopState(1);
|
||||
instance->setLastInput(value == 0 ? "" : value);
|
||||
}
|
||||
}
|
||||
|
||||
if (value != nullptr) {
|
||||
// avoid memleak
|
||||
TRI_SystemFree(value);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- class ReadlineShell
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private variables
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief (sole) instance of a ReadlineShell
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::atomic<ReadlineShell*> ReadlineShell::_instance(nullptr);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- constructors and destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief constructs a new editor
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ReadlineShell::ReadlineShell (std::string const& history, Completer* completer)
|
||||
: ShellImplementation(history, completer),
|
||||
_loopState(0),
|
||||
_lastInput(),
|
||||
_lastInputWasEmpty(false) {
|
||||
|
||||
COMPLETER = completer;
|
||||
|
||||
rl_initialize();
|
||||
|
||||
rl_attempted_completion_function = AttemptedCompletion;
|
||||
rl_completer_word_break_characters = WordBreakCharacters;
|
||||
|
||||
// register ourselves
|
||||
TRI_ASSERT(_instance == nullptr);
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief destructor
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ReadlineShell::~ReadlineShell () {
|
||||
// unregister ourselves
|
||||
_instance = nullptr;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- ShellImplementation methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief handle a signal
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ReadlineShell::signal () {
|
||||
// set the global state, so the readline input loop can react on it
|
||||
setLoopState(2);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief line editor open
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool ReadlineShell::open (bool autoComplete) {
|
||||
if (autoComplete) {
|
||||
|
||||
// issue #289: do not append a space after completion
|
||||
rl_completion_append_character = '\0';
|
||||
|
||||
// works only in Readline 4.2+
|
||||
#if RL_READLINE_VERSION >= 0x0500
|
||||
// enable this to turn on the visual bell - evil!
|
||||
// rl_variable_bind("prefer-visible-bell", "1");
|
||||
|
||||
// use this for single-line editing as in mongodb shell
|
||||
// rl_variable_bind("horizontal-scroll-mode", "1");
|
||||
|
||||
// show matching parentheses
|
||||
rl_set_paren_blink_timeout(300 * 1000);
|
||||
rl_variable_bind("blink-matching-paren", "1");
|
||||
|
||||
// show selection list when completion is ambiguous. not setting this
|
||||
// variable will turn the selection list off at least on Ubuntu
|
||||
rl_variable_bind("show-all-if-ambiguous", "1");
|
||||
|
||||
// use readline's built-in page-wise completer
|
||||
rl_variable_bind("page-completions", "1");
|
||||
#endif
|
||||
|
||||
rl_bind_key('\t', rl_complete);
|
||||
}
|
||||
|
||||
using_history();
|
||||
//stifle_history(MAX_HISTORY_ENTRIES);
|
||||
stifle_history(1000);
|
||||
|
||||
_state = STATE_OPENED;
|
||||
return read_history(historyPath().c_str()) == 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief line editor shutdown
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool ReadlineShell::close () {
|
||||
if (_state != STATE_OPENED) {
|
||||
// avoid duplicate saving of history
|
||||
return true;
|
||||
}
|
||||
|
||||
_state = STATE_CLOSED;
|
||||
|
||||
bool res = writeHistory();
|
||||
|
||||
clear_history();
|
||||
|
||||
HIST_ENTRY** hist = history_list();
|
||||
|
||||
if (hist != nullptr) {
|
||||
TRI_SystemFree(hist);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get the history file path
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
string ReadlineShell::historyPath () {
|
||||
string path;
|
||||
|
||||
if (getenv("HOME")) {
|
||||
path.append(getenv("HOME"));
|
||||
path += '/';
|
||||
}
|
||||
|
||||
path.append(_historyFilename);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief add to history
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ReadlineShell::addHistory (const string& str) {
|
||||
if (str.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
history_set_pos(history_length - 1);
|
||||
|
||||
if (current_history()) {
|
||||
do {
|
||||
if (strcmp(current_history()->line, str.c_str()) == 0) {
|
||||
HIST_ENTRY* e = remove_history(where_history());
|
||||
|
||||
if (e != nullptr) {
|
||||
free_history_entry(e);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (previous_history());
|
||||
}
|
||||
|
||||
add_history(str.c_str());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief save history
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool ReadlineShell::writeHistory () {
|
||||
return (write_history(historyPath().c_str()) == 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief read a line from the input
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
string ReadlineShell::getLine (const string& prompt, bool& eof) {
|
||||
setLoopState(0);
|
||||
|
||||
rl_event_hook = ReadlineIdle;
|
||||
rl_callback_handler_install(prompt.c_str(), ReadlineInputCompleted);
|
||||
|
||||
int state;
|
||||
|
||||
eof = false;
|
||||
|
||||
do {
|
||||
rl_callback_read_char();
|
||||
state = getLoopState();
|
||||
}
|
||||
while (state == 0);
|
||||
|
||||
rl_callback_handler_remove();
|
||||
|
||||
if (state == 2) {
|
||||
setLastInput("");
|
||||
|
||||
if (_lastInputWasEmpty) {
|
||||
eof = true;
|
||||
}
|
||||
else {
|
||||
_lastInputWasEmpty = true;
|
||||
}
|
||||
}
|
||||
else if (state == 3) {
|
||||
setLastInput("");
|
||||
eof = true;
|
||||
_lastInputWasEmpty = false;
|
||||
}
|
||||
else {
|
||||
_lastInputWasEmpty = false;
|
||||
}
|
||||
|
||||
return _lastInput;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- END-OF-FILE
|
||||
// -----------------------------------------------------------------------------
|
|
@ -1,210 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief a basis class for concrete implementations for a shell
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2014-2015 ArangoDB GmbH, Cologne, Germany
|
||||
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Esteban Lombeyda
|
||||
/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany
|
||||
/// @author Copyright 2011-2014, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef ARANGODB_UTILITIES_READLINE_SHELL_H
|
||||
#define ARANGODB_UTILITIES_READLINE_SHELL_H 1
|
||||
|
||||
#include "Utilities/ShellImplementation.h"
|
||||
|
||||
#include "Utilities/Completer.h"
|
||||
|
||||
namespace arangodb {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- class ReadlineShell
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class ReadlineShell : public ShellImplementation {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- static public methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief return the currently active shell instance
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static ReadlineShell* instance () {
|
||||
return _instance.load();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- constructors and destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief constructor
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ReadlineShell (std::string const& history, Completer*);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief destructor
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
~ReadlineShell ();
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- ShellImplementation methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief line editor open
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool open (bool autoComplete) override final;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief line editor shutdown
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool close () override final;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get the history file path
|
||||
///
|
||||
/// The path is "$HOME" plus _historyFilename, if $HOME is set. Else
|
||||
/// the local file _historyFilename.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string historyPath () override final;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief add to history
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void addHistory (const std::string&) override final;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief save the history
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool writeHistory () override final;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief read a line from the input
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string getLine (const std::string& prompt, bool& eof) override final;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief handle a signal
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void signal () override final;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief whether or not the shell implementation supports colors
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool supportsColors () override final {
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief whether or not the shell supports a CTRL-C handler
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool supportsCtrlCHandler () override final {
|
||||
return true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- public methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief set the last input value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void setLastInput (const std::string& input) {
|
||||
_lastInput = input;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get the current input loop state
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int getLoopState () const {
|
||||
return _loopState;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief set the current input loop state
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void setLoopState (int state) {
|
||||
_loopState = state;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private variables
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief current state of input loop (may be affected by out-of-band signals)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::atomic<int> _loopState;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief last value entered by user.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string _lastInput;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief whether or not the input from the previous invocation was a CTRL-C
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool _lastInputWasEmpty;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief system-wide instance of the ReadlineShell
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static std::atomic<ReadlineShell*> _instance;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- END-OF-FILE
|
||||
// -----------------------------------------------------------------------------
|
|
@ -33,8 +33,6 @@
|
|||
#include "LinenoiseShell.h"
|
||||
#elif defined TRI_HAVE_LINENOISE
|
||||
#include "LinenoiseShell.h"
|
||||
#elif defined TRI_HAVE_READLINE
|
||||
#include "ReadlineShell.h"
|
||||
#endif
|
||||
#include "DummyShell.h"
|
||||
|
||||
|
@ -63,12 +61,9 @@ ShellImplementation* ShellImplFactory::buildShell (std::string const& history,
|
|||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
// under Windows the readline is not compilable
|
||||
return new LinenoiseShell(history, completer);
|
||||
#elif defined TRI_HAVE_LINENOISE
|
||||
return new LinenoiseShell(history, completer);
|
||||
#elif defined TRI_HAVE_READLINE
|
||||
return new ReadlineShell(history, completer);
|
||||
#else
|
||||
// last resort!
|
||||
return new DummyShell(history, completer);
|
||||
|
@ -85,12 +80,9 @@ bool ShellImplFactory::hasCtrlCHandler () {
|
|||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
// under Windows the readline is not compilable
|
||||
return false;
|
||||
#elif defined TRI_HAVE_LINENOISE
|
||||
return false;
|
||||
#elif defined TRI_HAVE_READLINE
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue