cli: allow quitting on Ctrl-D while in readline()

Ctrl-D is mapped as a delete key in readline. When some input is on the line,
Ctrl-D behaves like 'Delete' key. When the line is empty, EOF is generated.
We quit on this EOF. It is the same behaviour many other interactive programs
exhibit, like bash, python, irb, etc.

Users can also quit unconditionally with Ctrl-\ that traditionally generates
SIGQUIT.
This commit is contained in:
Jiří Klimeš
2014-06-17 16:38:08 +02:00
parent 433c067522
commit dbf2d08559

View File

@@ -1132,6 +1132,7 @@ nmc_set_in_readline (gboolean in_readline)
*
* Wrapper around libreadline's readline() function.
* If user pressed Ctrl-C, readline() is called again.
* If user pressed Ctrl-D on empty line, nmcli will quit.
*
* Returns: the user provided string. In case the user entered empty string,
* this function returns NULL.
@@ -1157,6 +1158,12 @@ readline_mark:
if (str && *str)
add_history (str);
/*-- React on Ctrl-C and Ctrl-D --*/
/* We quit on Ctrl-D when line is empty */
if (str == NULL) {
/* Send SIGQUIT to itself */
kill (getpid (), SIGQUIT);
}
/* In case of Ctrl-C we call readline again to get new prompt (repeat) */
if (nmc_seen_sigint ()) {
nmc_clear_sigint ();