edit: Add basic support for input line editing
RFC 1/1 edit: Add basic support for input line editing
This allows for simple line editing with history capabilities. On purpose this has no concept of terminal input or terminal output and just allows manipulation of an internal wide character string.
The history storing and loading is currently missing, but would be easy to add. The other two items are missing completion and hints handling.
This feature is not yet complete, but good enough for a first review and a sample application using it in a curses environment will follow.
The debug option is something that might need to be removed or at least changed a little bit, but right now it is nice to see the internal states.
--- Makefile.am | 2 + ell/edit.c | 595 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ell/edit.h | 55 +++++ ell/ell.h | 1 + ell/ell.sym | 21 ++ 5 files changed, 674 insertions(+) create mode 100644 ell/edit.c create mode 100644 ell/edit.h
Makefile.am +2 -0
@@ -55,6 +55,7 @@ pkginclude_HEADERS = ell/ell.h \ ell/ecc.h \ ell/ecdh.h \ ell/time.h \ + ell/edit.h \ ell/gpio.h \ ell/path.h \ ell/icmp6.h \
@@ -145,6 +146,7 @@ ell_libell_la_SOURCES = $(linux_headers) \ ell/ecdh.c \ ell/time.c \ ell/time-private.h \ + ell/edit.c \ ell/gpio.c \ ell/path.c \ ell/icmp6.c \
ell/edit.c new file +595 -0
595 lines not on this page · raw message
ell/edit.h new file +55 -0
55 lines not on this page · raw message
ell/ell.h +1 -0
@@ -46,6 +46,7 @@#include <ell/ecc.h> #include <ell/ecdh.h> #include <ell/time.h> +#include <ell/edit.h> #include <ell/gpio.h> #include <ell/path.h> #include <ell/acd.h>
ell/ell.sym +21 -0
@@ -617,6 +617,27 @@ global: l_ecdh_generate_shared_secret; /* time */ l_time_now; + /* edit */ + l_edit_new; + l_edit_free; + l_edit_set_debug_handler; + l_edit_set_display_handler; + l_edit_set_max_display_length; + l_edit_set_max_input_length; + l_edit_set_history_size; + l_edit_refresh; + l_edit_is_empty; + l_edit_enter; + l_edit_reset; + l_edit_insert; + l_edit_delete; + l_edit_backspace; + l_edit_move_left; + l_edit_move_right; + l_edit_move_home; + l_edit_move_end; + l_edit_history_backward; + l_edit_history_forward; /* gpio */ l_gpio_chips_with_line_label; l_gpio_chip_new;
Signature · 1 line
2.43.0
Quoted 7 lines · Marcel Holtmann
This allows for simple line editing with history capabilities. On purpose this has no concept of terminal input or terminal output and just allows manipulation of an internal wide character string.
The history storing and loading is currently missing, but would be easy to add. The other two items are missing completion and hints handling.
Quoted 6 lines
This feature is not yet complete, but good enough for a first review and a sample application using it in a curses environment will follow.
The debug option is something that might need to be removed or at least changed a little bit, but right now it is nice to see the internal states.
Marcel,
Any reason not to build on / improve linenoise or to put a neutralizing wrapper around libedit / readline as ntp did / does?
Each have their deficiencies, of course. However, it seems like, at least linenoise and libedit are close enough where a delta would be smaller than a rewrite-from-scratch.
Best,
Grant
Signature · 5 lines
Principal Nuovations [email protected] http://www.nuovations.com/
Quoted 15 lines · Grant Erickson
Quoted 7 lines · Marcel Holtmann
This allows for simple line editing with history capabilities. On purpose this has no concept of terminal input or terminal output and just allows manipulation of an internal wide character string.
The history storing and loading is currently missing, but would be easy to add. The other two items are missing completion and hints handling.
Quoted 6 lines
This feature is not yet complete, but good enough for a first review and a sample application using it in a curses environment will follow.
The debug option is something that might need to be removed or at least changed a little bit, but right now it is nice to see the internal states.
Quoted 5 lines
Marcel,
Any reason not to build on / improve linenoise or to put a neutralizing wrapper around libedit / readline as ntp did / does?
Each have their deficiencies, of course. However, it seems like, at least linenoise and libedit are close enough where a delta would be smaller than a rewrite-from-scratch.
I should have added, the four most important features for the use cases I have are:
1. Run loop integration / non-blocking on input (libcurl and libcares have reasonable APIs for this that make them well adaptable to just about any run loop infrastructure, including glib or CoreFoundation).
2. Initial input buffer population.
3. Dynamic prompt generation (basically, there’s a function call every time the prompt is refreshed or displayed—the implementer can decide whether to return a static string or on-the-fly-composed buffer).
4. Passphrase mode (generate asterisks, spaces, nulls, or bullets on input of confidential information).
TUI / CLI-based network setup motivates most of the above, for example:
Running networking setup…
Setting up Ethernet...
Checking Ethernet availability...
Ethernet is available.
Enabling Ethernet networking by default...
Setting up Wi-Fi...
Checking Wi-Fi availability…
Wi-Fi is available.
Enable Wi-Fi networking (0|N-No, 1|Y-Yes) [Y]? Y
Already connected to Wi-Fi network “Northern Gaze”.
Add to, replace, or use the Wi-Fi network “Northern Gaze” (A-Add, R-Replace, U-Use) [U]? A
[ … ]
Enter the passphrase for "Robust Ground": **********
Associating with the "Robust Ground" Wi-Fi access point...done. Configuring IP addresses...done.
Confirming Internet reachability...done.
Successfully connected to Wi-Fi network "Robust Debt".
The custom, on-the-fly prompts are "Enable Wi-Fi networking (0|N-No, 1|Y-Yes) [Y]?”, "Add to, replace, or use the Wi-Fi network “Northern Gaze” (A-Add, R-Replace, U-Use) [U]?”, and “Enter the passphrase for "Robust Debt":". The pre-populated, editable input buffers are “Y” and “A”, respectively. The passphrase mode is “**********”.
libedit makes (2) and (3) very easy. linenoise makes (1) easy and (4) partially achievable. Neither can do all of those, at least easily.
Best,
Grant
Signature · 5 lines
Principal Nuovations [email protected] http://www.nuovations.com/
Hi Grant,
Quoted 49 lines
Quoted 14 lines
Quoted 7 lines
This allows for simple line editing with history capabilities. On purpose this has no concept of terminal input or terminal output and just allows manipulation of an internal wide character string.
The history storing and loading is currently missing, but would be easy to add. The other two items are missing completion and hints handling.
Quoted 6 lines
This feature is not yet complete, but good enough for a first review and a sample application using it in a curses environment will follow.
The debug option is something that might need to be removed or at least changed a little bit, but right now it is nice to see the internal states.
Quoted 5 lines
Marcel,
Any reason not to build on / improve linenoise or to put a neutralizing wrapper around libedit / readline as ntp did / does?
Each have their deficiencies, of course. However, it seems like, at least linenoise and libedit are close enough where a delta would be smaller than a rewrite-from-scratch.
I should have added, the four most important features for the use cases I have are:
1. Run loop integration / non-blocking on input (libcurl and libcares have reasonable APIs for this that make them well adaptable to just about any run loop infrastructure, including glib or CoreFoundation).
2. Initial input buffer population.
3. Dynamic prompt generation (basically, there’s a function call every time the prompt is refreshed or displayed—the implementer can decide whether to return a static string or on-the-fly-composed buffer).
4. Passphrase mode (generate asterisks, spaces, nulls, or bullets on input of confidential information).TUI / CLI-based network setup motivates most of the above, for example:
Running networking setup…
Setting up Ethernet...
Checking Ethernet availability...
Ethernet is available.
Enabling Ethernet networking by default...
Setting up Wi-Fi...
Checking Wi-Fi availability…
Wi-Fi is available.
Enable Wi-Fi networking (0|N-No, 1|Y-Yes) [Y]? Y
Already connected to Wi-Fi network “Northern Gaze”.
Add to, replace, or use the Wi-Fi network “Northern Gaze” (A-Add, R-Replace, U-Use) [U]? A[ … ]
Enter the passphrase for "Robust Ground": **********
Associating with the "Robust Ground" Wi-Fi access point...done. Configuring IP addresses...done.
Confirming Internet reachability...done.
Successfully connected to Wi-Fi network "Robust Debt".
Quoted 3 lines
The custom, on-the-fly prompts are "Enable Wi-Fi networking (0|N-No, 1|Y-Yes) [Y]?”, "Add to, replace, or use the Wi-Fi network “Northern Gaze” (A-Add, R-Replace, U-Use) [U]?”, and “Enter the passphrase for "Robust Debt":". The pre-populated, editable input buffers are “Y” and “A”, respectively. The passphrase mode is “**********”.
libedit makes (2) and (3) very easy. linenoise makes (1) easy and (4) partially achievable. Neither can do all of those, at least easily.
I really need to clean up my Curses demo to show you how I envision this. I can easily add 2) actually. I left it out since I couldn’t find a use for it, but fair enough. And 3) and 4) really belong into the caller. Especially if you go fancy with colors or other attributes. It is so much easier for the the caller to get right than for the line editing.
What you missed is a 5) that restricts the input to a certain length. And I am still debating if a minimal length is useful as well, but then I really need to implement the hints support first.
Regards
Marcel
Hi Grant,
Quoted 10 lines
Quoted 10 lines
This allows for simple line editing with history capabilities. On purpose this has no concept of terminal input or terminal output and just allows manipulation of an internal wide character string.
The history storing and loading is currently missing, but would be easy to add. The other two items are missing completion and hints handling.
This feature is not yet complete, but good enough for a first review and a sample application using it in a curses environment will follow.
Quoted 8 lines
Quoted 3 lines
The debug option is something that might need to be removed or at least changed a little bit, but right now it is nice to see the internal states.
Any reason not to build on / improve linenoise or to put a neutralizing wrapper around libedit / readline as ntp did / does?
Each have their deficiencies, of course. However, it seems like, at least linenoise and libedit are close enough where a delta would be smaller than a rewrite-from-scratch.
so funny that you asked. I actually started with linenoise and was going to just use that. While it looked promising, it did not work out. I have written a whole integration with it and was initially really happy. However the problem is that linenoise (and others like ccli etc.) are based on the concept of direct access to the TTY and sending/parsing ANSI sequences. That is all good and golden, but doesn’t fly if you want to work in a Curses application. I learned the hard way that Curses and ANSI sequences don’t go together at all. And with the Curses idea, the direct access to stdout from linenoise is also not functional. I worked out a few things and still thought that I just extend linenoise until I started to play with umlauts and Unicode and then I hit a really hard brick wall.
This caused me to re-evaluate the basic idea on how all line editing libraries are done right now. So l_edit has no direct input/output capabilities. That is up to the caller. I removed prompt handling on purpose since the caller can do that better than the line editing library. And I also removed masked support (which I had initially) since the caller again can do that way better.
I do have a Curses based demo that will show this, but it is too messy at the moment to publish. I will clean that up and then maybe this becomes a bit clearer why this approach is better.
While doing this, I also found new respect for readline, but that thing has to go since its insistence on GPLv3 is just causing long term problems.
Regards
Marcel