mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-03 19:30:41 +01:00
cli: make Ctrl-C exit nmcli when line is empty *and* we are not in the editor
This commit is contained in:
parent
7e75ccea7f
commit
12f284dee3
4 changed files with 25 additions and 5 deletions
|
|
@ -1124,6 +1124,9 @@ nmc_set_in_readline (gboolean in_readline)
|
|||
pthread_mutex_unlock (&readline_mutex);
|
||||
}
|
||||
|
||||
/* Global variable defined in nmcli.c */
|
||||
extern NmCli nm_cli;
|
||||
|
||||
/**
|
||||
* nmc_readline:
|
||||
* @prompt_fmt: prompt to print (telling user what to enter). It is standard
|
||||
|
|
@ -1131,7 +1134,8 @@ nmc_set_in_readline (gboolean in_readline)
|
|||
* @...: a list of arguments according to the @prompt_fmt format string
|
||||
*
|
||||
* Wrapper around libreadline's readline() function.
|
||||
* If user pressed Ctrl-C, readline() is called again.
|
||||
* If user pressed Ctrl-C, readline() is called again (if not in editor and
|
||||
* line is empty, nmcli will quit).
|
||||
* If user pressed Ctrl-D on empty line, nmcli will quit.
|
||||
*
|
||||
* Returns: the user provided string. In case the user entered empty string,
|
||||
|
|
@ -1168,11 +1172,23 @@ readline_mark:
|
|||
for (;;)
|
||||
sleep (3);
|
||||
}
|
||||
/* In case of Ctrl-C we call readline again to get new prompt (repeat) */
|
||||
/* Ctrl-C */
|
||||
if (nmc_seen_sigint ()) {
|
||||
nmc_clear_sigint ();
|
||||
g_free (str);
|
||||
goto readline_mark;
|
||||
if (nm_cli.in_editor || *str) {
|
||||
/* In editor, or the line is not empty */
|
||||
/* Call readline again to get new prompt (repeat) */
|
||||
g_free (str);
|
||||
goto readline_mark;
|
||||
} else {
|
||||
/* Not in editor and line is empty */
|
||||
/* Send SIGQUIT to itself */
|
||||
nmc_set_sigquit_internal ();
|
||||
kill (getpid (), SIGQUIT);
|
||||
/* Sleep in this thread so that we don't do anything else until exit */
|
||||
for (;;)
|
||||
sleep (3);
|
||||
}
|
||||
}
|
||||
g_free (prompt);
|
||||
|
||||
|
|
|
|||
|
|
@ -7982,6 +7982,9 @@ do_connection_edit (NmCli *nmc, int argc, char **argv)
|
|||
editor_init_new_connection (nmc, connection);
|
||||
}
|
||||
|
||||
/* nmcli runs the editor */
|
||||
nmc->in_editor = TRUE;
|
||||
|
||||
printf ("\n");
|
||||
printf (_("===| nmcli interactive connection editor |==="));
|
||||
printf ("\n\n");
|
||||
|
|
|
|||
|
|
@ -307,7 +307,6 @@ event_hook_for_readline (void)
|
|||
/* Make readline() exit on SIGINT */
|
||||
if (nmc_seen_sigint ()) {
|
||||
rl_echo_signal_char (SIGINT);
|
||||
rl_delete_text (0, rl_end);
|
||||
rl_stuff_char ('\n');
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -433,6 +432,7 @@ nmc_init (NmCli *nmc)
|
|||
memset (&nmc->print_fields, '\0', sizeof (NmcPrintFields));
|
||||
nmc->nocheck_ver = FALSE;
|
||||
nmc->ask = FALSE;
|
||||
nmc->in_editor = FALSE;
|
||||
nmc->editor_status_line = FALSE;
|
||||
nmc->editor_save_confirmation = TRUE;
|
||||
nmc->editor_prompt_color = NMC_TERM_COLOR_NORMAL;
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@ typedef struct _NmCli {
|
|||
NmcPrintFields print_fields; /* Structure with field indices to print */
|
||||
gboolean nocheck_ver; /* Don't check nmcli and NM versions: option '--nocheck' */
|
||||
gboolean ask; /* Ask for missing parameters: option '--ask' */
|
||||
gboolean in_editor; /* Whether running the editor - nmcli con edit' */
|
||||
gboolean editor_status_line; /* Whether to display status line in connection editor */
|
||||
gboolean editor_save_confirmation; /* Whether to ask for confirmation on saving connections with 'autoconnect=yes' */
|
||||
NmcTermColor editor_prompt_color; /* Color of prompt in connection editor */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue