Skip to content

Commit

Permalink
let Ctrl-C exit Y/N and menu prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandwalker authored and jonas committed Jul 4, 2017
1 parent 76700c8 commit 23c2fde
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions include/tig/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ key_to_unicode(const struct key *key)
: 0;
}

static inline char
key_to_control(const struct key *key)
{
return (key->modifiers.control && key->modifiers.multibytes && strlen(key->data.bytes) == 1)
? key->data.bytes[0]
: 0;
}

struct keymap *get_keymap(const char *name, size_t namelen);

const char *get_key_name(const struct key key[], size_t keys, bool quote_comma);
Expand Down
7 changes: 6 additions & 1 deletion src/prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ prompt_yesno_handler(struct input *input, struct key *key)

if (c == 'y' || c == 'Y')
return INPUT_STOP;
if (c == 'n' || c == 'N')
if (c == 'n' || c == 'N' || key_to_control(key) == 'C')
return INPUT_CANCEL;
return prompt_default_handler(input, key);
}
Expand Down Expand Up @@ -574,6 +574,11 @@ prompt_menu(const char *prompt, const struct menu_item *items, int *selected)
break;

default:
if (key_to_control(&key) == 'C') {
status = INPUT_CANCEL;
break;
}

for (i = 0; items[i].text; i++)
if (items[i].hotkey == key.data.bytes[0]) {
*selected = i;
Expand Down

0 comments on commit 23c2fde

Please sign in to comment.