diff options
author | James Booth <boothj5@gmail.com> | 2012-11-23 02:00:51 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-11-23 02:00:51 +0000 |
commit | 721df8ca48b8cbf0026f3a36a3d17b45cb82b850 (patch) | |
tree | 0857a6e2917bcb4b7bb917adbe720e411157536d | |
parent | 2a69f8d23f8e3e120604560818d86658ee66f088 (diff) | |
download | profani-tty-721df8ca48b8cbf0026f3a36a3d17b45cb82b850.tar.gz |
Stop ctrl-c quitting with /ctrlc off
-rw-r--r-- | src/command.c | 19 | ||||
-rw-r--r-- | src/input_win.c | 22 | ||||
-rw-r--r-- | src/preferences.c | 13 | ||||
-rw-r--r-- | src/preferences.h | 2 | ||||
-rw-r--r-- | src/windows.c | 7 |
5 files changed, 59 insertions, 4 deletions
diff --git a/src/command.c b/src/command.c index 52f7fac9..93f4e4fa 100644 --- a/src/command.c +++ b/src/command.c @@ -116,6 +116,7 @@ static gboolean _cmd_set_chlog(gchar **args, struct cmd_help_t help); static gboolean _cmd_set_history(gchar **args, struct cmd_help_t help); static gboolean _cmd_set_states(gchar **args, struct cmd_help_t help); static gboolean _cmd_set_outtype(gchar **args, struct cmd_help_t help); +static gboolean _cmd_set_ctrlc(gchar **args, struct cmd_help_t help); static gboolean _cmd_vercheck(gchar **args, struct cmd_help_t help); static gboolean _cmd_away(gchar **args, struct cmd_help_t help); static gboolean _cmd_online(gchar **args, struct cmd_help_t help); @@ -485,6 +486,15 @@ static struct cmd_t setting_commands[] = "Config file value : maxsize=bytes", NULL } } }, + { "/ctrlc", + _cmd_set_ctrlc, parse_args, 1, 1, + { "/ctrlc on|off", "Set ctrl-c to quit profanity.", + { "/ctrlc on|off", + "---------------", + "Setting this option will allow you to quit using ctrl-c.", + NULL } } }, + + { "/priority", _cmd_set_priority, parse_args, 1, 1, { "/priority <value>", "Set priority for connection.", @@ -855,6 +865,8 @@ _cmd_complete_parameters(char *input, int *size) prefs_autocomplete_boolean_choice); _parameter_autocomplete(input, size, "/states", prefs_autocomplete_boolean_choice); + _parameter_autocomplete(input, size, "/ctrlc", + prefs_autocomplete_boolean_choice); _parameter_autocomplete(input, size, "/outtype", prefs_autocomplete_boolean_choice); _parameter_autocomplete(input, size, "/flash", @@ -1390,6 +1402,13 @@ _cmd_set_states(gchar **args, struct cmd_help_t help) } static gboolean +_cmd_set_ctrlc(gchar **args, struct cmd_help_t help) +{ + return _cmd_set_boolean_preference(args, help, "/ctrlc", + "Ctrl-C quit", prefs_set_ctrlc); +} + +static gboolean _cmd_set_outtype(gchar **args, struct cmd_help_t help) { return _cmd_set_boolean_preference(args, help, "/outtype", diff --git a/src/input_win.c b/src/input_win.c index 5ad64d80..ee6317ac 100644 --- a/src/input_win.c +++ b/src/input_win.c @@ -241,17 +241,33 @@ _handle_edit(const int ch, char *input, int *size) char *next = NULL; int inp_y = 0; int inp_x = 0; + int next_ch; getmaxyx(stdscr, rows, cols); getyx(inp_win, inp_y, inp_x); switch(ch) { - case 27: // ESC - *size = 0; - inp_clear(); + case 3: // CTRL-C + if (prefs_get_ctrlc()) { + exit(0); + } return 1; + case 27: + next_ch = wgetch(inp_win); + + // ESC + if (next_ch == ERR) { + *size = 0; + inp_clear(); + return 1; + + // ALT-<next_ch> + } else { + return 1; + } + case 127: case KEY_BACKSPACE: contact_list_reset_search_attempts(); diff --git a/src/preferences.c b/src/preferences.c index a44af242..d7626655 100644 --- a/src/preferences.c +++ b/src/preferences.c @@ -132,6 +132,19 @@ prefs_set_beep(gboolean value) _save_prefs(); } +gboolean +prefs_get_ctrlc(void) +{ + return g_key_file_get_boolean(prefs, "ui", "ctrlc", NULL); +} + +void +prefs_set_ctrlc(gboolean value) +{ + g_key_file_set_boolean(prefs, "ui", "ctrlc", value); + _save_prefs(); +} + gchar * prefs_get_theme(void) { diff --git a/src/preferences.h b/src/preferences.h index f4547b07..84eadd1c 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -65,6 +65,8 @@ gboolean prefs_get_outtype(void); void prefs_set_outtype(gboolean value); gchar * prefs_get_theme(void); void prefs_set_theme(gchar *value); +gboolean prefs_get_ctrlc(void); +void prefs_set_ctrlc(gboolean value); void prefs_set_notify_message(gboolean value); gboolean prefs_get_notify_message(void); diff --git a/src/windows.c b/src/windows.c index 75154b64..7d92a419 100644 --- a/src/windows.c +++ b/src/windows.c @@ -106,7 +106,7 @@ gui_init(void) { log_info("Initialising UI"); initscr(); - cbreak(); + raw(); keypad(stdscr, TRUE); win_load_colours(); @@ -1050,6 +1050,11 @@ cons_prefs(void) else cons_show("Version checking : OFF"); + if (prefs_get_ctrlc()) + cons_show("Ctrl-c quits : ON"); + else + cons_show("Ctrl-c quits : OFF"); + if (prefs_get_notify_message()) cons_show("Message notifications : ON"); else |