This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository e16.
View the commit online.
commit 46f0a72ea48f28c03dc3c74460a26904e5c598dc
Author: Kim Woelders <k...@woelders.dk>
AuthorDate: Sun Dec 17 19:31:56 2023 +0100
eesh: Add possibility to use editline (--with-editline, default off)
---
configure.ac | 13 +++++++++++++
eesh/Makefile.am | 4 ++--
eesh/main.c | 55 +++++++++++++++++++++++++++++++++++++++++++++----------
3 files changed, 60 insertions(+), 12 deletions(-)
diff --git a/configure.ac b/configure.ac
index 62b4b255..04f5d6e3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -384,6 +384,18 @@ if test "x$enable_dbus" = "xyes"; then
fi
AM_CONDITIONAL(ENABLE_DBUS, test "x$enable_dbus" = "xyes")
+AC_ARG_WITH(lineedit,
+ AS_HELP_STRING([--with-lineedit], [compile eesh with line editing support (no/yes=editline/readline)@<:@default=no@:>@]),, with_lineedit="no")
+if test "x$with_lineedit" = "xyes"; then
+ PKG_CHECK_MODULES(LINEEDIT, libeditline,
+ AC_DEFINE(USE_LINEEDIT_EDITLINE, 1, [Use editline])
+ with_lineedit="editline", with_lineedit="no")
+elif test "x$with_lineedit" = "xreadline"; then
+ PKG_CHECK_MODULES(LINEEDIT, readline,
+ AC_DEFINE(USE_LINEEDIT_READLINE, 1, [Use readline])
+ with_lineedit="readline", with_lineedit="no")
+fi
+
AC_CHECK_LIB(Fridge,mass_quantities_of_bass_ale)
AC_CHECK_LIB(Fridge,mass_quantities_of_any_ale,, [
echo "Warning: No ales were found in your refrigerator."
@@ -550,6 +562,7 @@ echo
echo "Miscellaneous options"
echo " Use Modules .................. $enable_modules"
echo " Visibility hiding ............ $enable_visibility_hiding (only useful with modules)"
+echo " Line editing (eesh) .......... $with_lineedit"
echo
echo "Experimental options - DO NOT USE unless you know what you are doing"
echo " GLX .......................... $enable_glx"
diff --git a/eesh/Makefile.am b/eesh/Makefile.am
index f24f08d9..2239c385 100644
--- a/eesh/Makefile.am
+++ b/eesh/Makefile.am
@@ -3,8 +3,8 @@ bin_PROGRAMS = eesh
AM_CPPFLAGS = -I$(top_builddir) $(X_CFLAGS)
-AM_CFLAGS = $(CFLAGS_WARNINGS) $(CFLAGS_VISIBILITY) $(CFLAGS_ASAN)
+AM_CFLAGS = $(CFLAGS_WARNINGS) $(CFLAGS_VISIBILITY) $(CFLAGS_ASAN) $(LINEEDIT_CFLAGS)
eesh_SOURCES = E.h comms.c main.c
-eesh_LDADD = $(X_LIBS) -lX11
+eesh_LDADD = $(X_LIBS) -lX11 $(LINEEDIT_LIBS)
diff --git a/eesh/main.c b/eesh/main.c
index 410466d4..7587910e 100644
--- a/eesh/main.c
+++ b/eesh/main.c
@@ -31,6 +31,15 @@
#include <X11/Xlib.h>
#include "E.h"
+#if USE_LINEEDIT_EDITLINE
+#define USE_LINEEDIT 1
+#include <editline.h>
+#elif USE_LINEEDIT_READLINE
+#define USE_LINEEDIT 1
+#include <readline/readline.h>
+#include <readline/history.h>
+#endif
+
#define PROMPT "eesh> "
Display *disp;
@@ -47,12 +56,20 @@ process_line(char *line)
if (!line)
exit(0);
- if (*line == '\0')
- return;
- CommsSend(e, line);
- XSync(disp, False);
- reply_pending = true;
+ if (*line)
+ {
+ CommsSend(e, line);
+ XSync(disp, False);
+ reply_pending = true;
+ }
+
+#if USE_LINEEDIT
+ if (!use_prompt)
+ return;
+ rl_set_prompt("");
+ add_history(line);
+#endif
}
static void
@@ -63,8 +80,6 @@ stdin_read(void)
int nr;
char *p;
- input_pending = true;
-
nr = read(STDIN_FILENO, buf + nin, sizeof(buf) - 1 - nin);
if (nr <= 0)
exit(0);
@@ -93,15 +108,19 @@ stdin_read(void)
}
}
+#if USE_LINEEDIT
static void
stdin_state_setup(void)
{
+ rl_callback_handler_install("", process_line);
}
static void
stdin_state_restore(void)
{
+ rl_callback_handler_remove();
}
+#endif
int
main(int argc, char **argv)
@@ -191,8 +210,13 @@ main(int argc, char **argv)
/* Interactive */
interactive = true;
use_prompt = isatty(STDIN_FILENO);
- stdin_state_setup();
- atexit(stdin_state_restore);
+#if USE_LINEEDIT
+ if (use_prompt)
+ {
+ stdin_state_setup();
+ atexit(stdin_state_restore);
+ }
+#endif
}
memset(pfd, 0, sizeof(pfd));
@@ -232,8 +256,13 @@ main(int argc, char **argv)
if (use_prompt && !input_pending && !reply_pending)
{
+#if USE_LINEEDIT
+ rl_set_prompt(PROMPT);
+ rl_forced_update_display();
+#else
printf(PROMPT);
fflush(stdout);
+#endif
}
if (poll(pfd, nfd, timeout) < 0)
@@ -243,7 +272,13 @@ main(int argc, char **argv)
{
if (pfd[1].revents & POLLIN)
{
- stdin_read();
+ input_pending = true;
+#if USE_LINEEDIT
+ if (use_prompt)
+ rl_callback_read_char();
+ else
+#endif
+ stdin_read();
}
if (pfd[1].revents & POLLHUP)
break;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.