Commit Graph

109 Commits

Author SHA1 Message Date
Joachim Nilsson
979f05a5eb Follow-up to a4b67d2: Ctrl-L redisplay line when not on empty line
Like Ctrl-D, when on an empty line we clear the screen, when editing a
garbled line we refresh the line.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-05-06 00:54:57 +02:00
Joachim Nilsson
c95d25731d Always use enums for el_status_t return values
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-05-06 00:54:17 +02:00
Abit
448a3dac08
Avoid continuously duplicate commands in history
When adding a command to history, if CONFIG_UNIQUE_HISTORY is defined, always compare current command with the last entry in history.
2019-05-03 16:54:25 +02:00
Will Dietz
8660aef4b7 editline: fix behavior when tty is narrower than column width
Fixes crash when dividing by the number of columns,
which was computed as zero in this situation.

Instead, always have at least one "column" even if it wraps.
2019-04-26 13:30:15 -05:00
Daiderd Jordan
a4b67d2268
make Ctrl-L clear the screen instead of just starting a new line 2018-12-23 20:49:25 +01:00
Joachim Nilsson
2137b9df9f Revert "Merge pull request #21 from cogutvalera/issue_1171"
This reverts commit cddd8d8de0, reversing
changes made to 4ec7d26a9d.
2018-11-15 10:27:22 +01:00
Joachim Nilsson
66d8ae84e2 Revert "Coding style and const fixes to last PR"
This reverts commit fbb1f8800a.
2018-11-15 10:26:03 +01:00
Joachim Nilsson
fbb1f8800a Coding style and const fixes to last PR
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-24 08:28:34 +02:00
Valera Cogut
1db83fe6c6 Fixed inconsistent indentation 2018-10-18 16:54:16 +03:00
Valera Cogut
4784fe2491 Hide secret information 2018-10-18 11:15:35 +03:00
Joachim Nilsson
ebefa8b890 Refactor, simplify helper macro
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-21 07:12:24 +02:00
Joachim Nilsson
14b6dd37d6 Fix off-by-one in forward kill word
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-16 09:29:48 +02:00
Joachim Nilsson
89d2fefbc6 Skip leading whitespace when skipping or killing forwards
When the point is on whitespace between two words skipping forward, or
killing forward, should result in the new point being moved to the next
word:

     foo    bar fox gnu
         ^
=>
     foo    bar fox gnu
                ^

Before this patch the point moved to 'b'.  After this patch the point
moves to the first letter of the next word, 'f'.  Kill forward word now
properly kills 'bar' and moves to the first whitespace letter after
'bar'.  Both are now behaving like FSF Readline.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-16 09:29:48 +02:00
Joachim Nilsson
097fde5267 Merge branch 'master' of github.com:troglobit/editline 2018-09-11 19:57:25 +02:00
Joachim Nilsson
77d531f5b5 Refactor completion handling and add FSF Readline callbacks
Still a bit raw, but the basic building blocks are there, waiting to be
cleaned up and released.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-11 19:55:43 +02:00
jmjatlanta
d2418161ad Fix sementation violation when displaying options 2018-07-11 18:01:48 -05:00
Joachim Nilsson
41bbb304b1 Export internal el_next_hist() and el_prev_hist()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-04-01 16:10:10 +02:00
Joachim Nilsson
0bfaf351aa Add support for Ctrl+Right and Ctrl+Left, forward/back word
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-03-22 08:42:32 +01:00
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