diff options
author | Jiří Klimeš <jklimes@redhat.com> | 2014-06-17 16:38:08 +0200 |
---|---|---|
committer | Jiří Klimeš <jklimes@redhat.com> | 2014-06-24 10:52:15 +0200 |
commit | dbf2d0855966a90abaf38f4d6ec4678502bd84b8 (patch) | |
tree | e8331adc28d1ff6e38c85ffc4b0fd333c88cf51a | |
parent | 433c067522ff4aca921dbcaf0c326dc6f57b6e53 (diff) | |
download | NetworkManager-dbf2d0855966a90abaf38f4d6ec4678502bd84b8.tar.gz |
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.
-rw-r--r-- | cli/src/common.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/cli/src/common.c b/cli/src/common.c index 9296bd12bd..a676077e36 100644 --- a/cli/src/common.c +++ b/cli/src/common.c @@ -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 (); |