Commit Graph

91 Commits

Author SHA1 Message Date
Joachim Nilsson
2ce0be942e Minor, reorder functions
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-03-22 08:38:04 +01:00
Joachim Nilsson
bc7fc7e5c0 Fix #15: Alternate interface to plain readline(), for event loops
This rather big patch adds support for the GNU Readline alternate
interface, for use with event loops:

    void rl_callback_handler_install (const char *prompt, rl_vcpfunc_t *lhandler);
    void rl_callback_read_char       (void);
    void rl_callback_handler_remove  (void);

The code has been tested using the testit and excallback examples.
Both regular editing and searching works as intended.

Also, the problem with lingering artefacts on screen when scrolling
through the history has been fixed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-11 08:43:43 +01:00
Joachim Nilsson
2ec55cc9f1 Minor, simplify
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-11 08:42:33 +01:00
Joachim Nilsson
7f7bb5b45c Minor, use NULL not 0, and -1 not NULL
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-11 01:45:25 +01:00
Joachim Nilsson
779db8817e rl_refresh_line(): new (undocumented) readline compat fn
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-02 21:14:14 +01:00
Joachim Nilsson
29a71a53d0 rl_insert_text(): new readline compat fn
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-02 21:13:39 +01:00
Joachim Nilsson
a9d4247c09 Minor, header cleanup, whitespace fixes, comments
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-30 18:20:29 +01:00
Joachim Nilsson
ea79fe70f9 write_history(), read_history(): Check fclose() return value
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-29 21:40:38 +01:00
Joachim Nilsson
2075dedc80 Remove leading (superfluous) comment
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-29 17:22:08 +01:00
Joachim Nilsson
54714631e2 Move All rights reserved to next line
All BSD style licenses put this text on a separate line, immediately
following the Copyright line.  The C-News license is confusing enough
to most people, so let's align at least a bit with the norm.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-29 17:20:21 +01:00
Joachim Nilsson
b613db2afb Whitespace + coding style cleanup
- Use Emacs K&R style
- Add missing braces to for() loops
- Fix coding style issues in cli.c example
- Add empty lines to separate sections
- Simplify and de-indent code, check error case first + continue

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-29 16:40:10 +01:00
Joachim Nilsson
1ace811722 rl_uninitialize(): also free old_search from previous i-search
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-29 15:32:59 +01:00
Claus Fischer
4b8333ad39 Remove duplicate unique history check
Signed-off-by: Claus Fischer <claus.fischer@clausfischer.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-29 15:03:01 +01:00
Joachim Nilsson
ed37cef412 Minor whitespace fixes/cleanup
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-29 15:01:22 +01:00
Joachim Nilsson
2a3b422137 Fix negative array index triggered by i-search
This is a fix to a bug reported by Claus Fischer.  When doing a reversed
i-search on the history, clear_line() sets rl_point to a negative value,
which is later used by ceol().  The intention is to clear the whole line
for the new Search: prompt, but indexing an array with a negative value
is strongly discouraged.

To prevent this negative indexing from happening we check in ceol() for
rl_point < 0, but we quickly notice another side effect: one lingering
character at the end of line when returning from i-search.  The problem
manifests itself more cleary when having a looooo000ooonong prompt.

The fix is to rub out the extra space, insert the i-search string, and
*then* call ceol() again.

Thanks to Claus for pointing this out!

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-29 14:53:14 +01:00
Claus Fischer
317b43e488 rl_unintialize(): New function, free all memory after use
Free all allocated internal memory and reset variables so
rl_initialize() or readline() may be called again later.

Signed-off-by: Claus Fischer <claus.fischer@clausfischer.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-29 14:44:24 +01:00
Claus Fischer
ed87f37409 Initialize global variables and reset to NULL on free()
Signed-off-by: Claus Fischer <claus.fischer@clausfischer.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-29 14:41:50 +01:00
Joachim Nilsson
059d97d7a9 Remove Emacs version-control handling
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-05-07 22:42:24 +02:00
Jakub Pawlowski
edc38768ff Add tty_flush() to rl_forced_update_display()
Forcing update should flush, otherwise weird stuff happen when writing
to console asynchronously (cursor is moved, text is not displayed).

Signed-off-by: Jakub Pawlowski <jakubpawlo@gmail.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-28 19:46:53 +01:00
Joachim Nilsson
7abfadd7e6 Attempt to work around slightly bogus Coverity warnings.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-10 13:06:39 +02:00
C0deH4cker
a1ca0d46ac Include <sys/ioctl.h> before calling ioctl() for Clang on OX X
At least when building with Clang on OS X, there is an error on
[line 1120 of editline.c][err] caused by using the `ioctl()` function
without first declaring it by including its header `<sys/ioctl.h>`.
Adding this line makes the build complete without error.

[err]: https://github.com/troglobit/editline/blob/master/src/editline.c#L1120

Signed-off-by: C0deH4cker <c0deh4cker@gmail.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-08 08:23:59 +02:00
Joachim Nilsson
9c163ff72b Rename define CONFIG_ANNOYING_NOISE --> CONFIG_TERMINAL_BELL
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-04-06 15:24:28 +02:00
Joachim Nilsson
6a8556733a Add support for disabling default SIGINT and EOF behavior.
This patch adds support for `--disable-eof` and `--disable-sigint` to
the Editline configure script.  With either of these two switches the
`tty_special()` function bypasses the special TTY checks making it
possible to bind Ctrl-C and Ctrl-D to custom callbacks.  This can be
useful if you want to emulate a Cisco style CLI rather than traditional
UNIX.

The user can of course also redefine the VINTR and VEOF special terminal
control characters, but these configure script switches may be easier to
use for some.

Also, the CLI example has been updated to bind Ctrl-D, Ctrl-C and Ctrl-Z
for testing purposes.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-04-06 14:53:47 +02:00
Toby Goodwin
a2bc89db64 Allow Ctrl-D to return EOF
This commit reverts parts of 111fc5e, which originally was intended to
add support for custom key bindings at pos 0, or more specifically, to
be able to change the behavior of Ctrl-D.  However this completely broke
compatibility with the original EOF behavior.

Signed-off-by: Toby Goodwin <toby@paccrat.org>
Signed-off-by: Joachim Nilsson <joachim.nilsson@westermo.se>
2015-04-06 14:46:57 +02:00
Joachim Nilsson
c497555bec editline.c:find_key_in_map() -- Add check to prevent out of bounds access.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-01 15:03:19 +01:00
Joachim Nilsson
8fbc87707e Fix out-of-bounds access in user key binding routines.
Coverity CID #56737, #56738

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-11-04 23:50:48 +01:00
Joachim Nilsson
394c4f82a9 Fix suspicious use of sizeof(char **), same as sizeof(char *) but not portable.
Coverity CID #56740, #56741, #56742

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-11-04 23:42:39 +01:00
Joachim Nilsson
e53ccf61f2 Refactor: replace variables named 'new' with non-reserved word.
The word 'new' is a reserved keyword in C++ and C#, replacing it
with something else is one step further to making it possible to
build editline with a C++ compiler.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-11-04 23:19:48 +01:00
Joachim Nilsson
cd50714e29 Fix memory leak in completion handler.
Coverty CID #56739

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-11-04 23:03:32 +01:00
Mattias Walström
7cd7fc4b61 Add support for el_no_hist to disable access to and auto-save of history.
This commit adds a new global variable 'el_no_hist' which can be used
to disable auto-save of history as well as access to history using prev
and next keybindings (up/down arrows).

Signed-off-by: Mattias Walström <lazzer@gmail.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-11-04 22:47:55 +01:00
Joachim Nilsson
bd9c8ddda6 Add some GNU readline compat functions for prompt handling and redisplay
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-09-17 05:49:06 +02:00
Joachim Nilsson
29b7f91165 Fix el_no_echo bug leaking secrets to screen and history
This patch makes el_no_echo actually work:

- Don't echo to screen
- Don't save to history

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-06-25 03:06:07 +02:00
Joachim Nilsson
4bc12834fe Only clear ScreenCount if write() succeeded. 2013-07-08 16:34:32 +02:00
Joachim Nilsson
c7a6ff9317 Return el_status_t from el_bind_key() and el_bind_key_in_metamap()
The two functions el_bind_key() and el_bind_key_in_metamap() should
not print status message on stderr, but rather return the status of
the key binding operation.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2013-07-08 16:27:57 +02:00
Joachim Nilsson
897a98be55 Export el_del_char() 2013-07-08 16:21:54 +02:00
Joachim Nilsson
111fc5e1fb readline(): Check custom key bindings as well.
Make sure to also check custom key bindings.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2013-07-08 16:21:29 +02:00
Joachim Nilsson
8e81add050 readline(): Check common signals first.
Make sure to check common signals first to prevent other interpretations.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2013-07-08 16:20:01 +02:00
Joachim Nilsson
088dc1d1b2 Move handy macros to global header file, useful when binding keys. 2011-01-06 10:41:07 +01:00
Joachim Nilsson
4f134f1025 Reduce tgetent() buffer size from 2048 to 1024. 2010-08-12 16:27:10 +02:00
Joachim Nilsson
850e36f9db Fix SIGFPE regression in tty_info() introduced in rl_reset_terminal() commit.
When adding support for rl_reset_termial() the tty_info() code was also
refactored.  This however led to the introduction of a bug that caused
tty_cols to be set to zero.  This in turn caused c_possible() to fail
with SIGFPE in el_print_columns().

Regression was introduced in 1c89c9886c
2010-08-12 16:20:29 +02:00
Joachim Nilsson
d72069144e Minor cleanup of unnecessary explicit casts. 2010-08-11 21:19:41 +02:00
Joachim Nilsson
87e69be38b Add support for inhibiting completion: rl_inhibit_completion 2010-08-11 13:14:32 +02:00
Joachim Nilsson
1c89c9886c Refactor tty_info() to make rl_reset_terminal() useful. 2010-08-05 15:14:06 +02:00
Joachim Nilsson
de6ff117bb Implement compat. support for rl_instream and rl_outstream 2010-08-05 13:20:35 +02:00
Joachim Nilsson
5e9177fd18 Add support for el_bind_key() and example usage binding '?' in examples/cli.c
This changeset refactors el_bind_key_in_metamap() into two functions,
adding el_bind_key(), to provide the ability for the user to bind keys
in both the regular and the meta-key maps.

Several useful, but previously internal, functions have been made global to
facilitate the example code mentioned above. These are likely useful to the
user of this library as well:

  el_print_columns() - Display words in columns across a tty_cols wide screen.
  el_ring_bell()     - Can be used as default key binding function.
  el_find_word()     - Returns a copy of the word at rl_point.
2010-08-05 12:48:51 +02:00
Joachim Nilsson
27fcc878a1 Make sure rl_instream defaults to NULL and add rl_outstream. 2010-08-05 02:00:35 +02:00
Joachim Nilsson
5de90af58f Fix new GNU Readline compat function pointers. 2010-08-05 01:56:09 +02:00
Joachim Nilsson
0a75b182b1 Improve GNU readline compat, patch by Steve Tell in 1997 and 1998
This changeset adds support for:
   * rl_prep_terminal(),
   * rl_deprep_terminal(), both of which are only wrappers to rl_ttyset().
   * rl_getc()

and:
   * (*rl_getc_function), defaults to rl_getc()
   * (*rl_event_hook)
   * (*rl_prep_term_function), defaults to rl_prep_terminal()
   * (*rl_deprep_term_function), defaults to rl_deprep_terminal()

For further details, see http://www.cs.unc.edu/~tell/dist/magic-readline.README

Differences from Steve's commit include: signal safety in rl_getc(), restart
read() on EINTR, and make sure to support "int meta_flag" to rl_prep_terminal()
which is the GNU syntax.  To that end I reused the inverse of rl_meta_chars.
2010-08-05 01:08:30 +02:00
Joachim Nilsson
d04bdaf38f Add support for read_history(char *filename) and write_history(char *filename) 2010-08-04 02:23:05 +02:00
Joachim Nilsson
aea0d60478 Remove copyright, not big enough contribution - also, was not even in patch from Mr. Black. 2010-08-04 02:18:44 +02:00