aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2016-09-04 04:29:56 +0300
committerZyX <kp-pav@yandex.ru>2017-03-29 10:08:06 +0300
commit6cc3d59ec8e4d6f32c8c3d9755c625e32512b8e2 (patch)
treee2b0a6b90acb0ae7f88d2c18b764944e05970a33
parent31a3158d0b574385186ab55c074edf85356d1d6c (diff)
downloadrneovim-6cc3d59ec8e4d6f32c8c3d9755c625e32512b8e2.tar.gz
rneovim-6cc3d59ec8e4d6f32c8c3d9755c625e32512b8e2.tar.bz2
rneovim-6cc3d59ec8e4d6f32c8c3d9755c625e32512b8e2.zip
misc1: Refactor ask_yesno()
-rw-r--r--src/nvim/misc1.c49
1 files changed, 27 insertions, 22 deletions
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index d751f13644..0b74b4437e 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -2211,39 +2211,44 @@ change_warning (
}
}
-/*
- * Ask for a reply from the user, a 'y' or a 'n'.
- * No other characters are accepted, the message is repeated until a valid
- * reply is entered or CTRL-C is hit.
- * If direct is TRUE, don't use vgetc() but ui_inchar(), don't get characters
- * from any buffers but directly from the user.
- *
- * return the 'y' or 'n'
- */
-int ask_yesno(const char *str, bool direct)
+/// Ask for a reply from the user, 'y' or 'n'
+///
+/// No other characters are accepted, the message is repeated until a valid
+/// reply is entered or <C-c> is hit.
+///
+/// @param[in] str Prompt: question to ask user. Is always followed by
+/// " (y/n)?".
+/// @param[in] direct Determines what function to use to get user input. If
+/// true then ui_inchar() will be used, otherwise vgetc().
+/// I.e. when direct is true then characters are obtained
+/// directly from the user without buffers involved.
+///
+/// @return 'y' or 'n'. Last is also what will be returned in case of interrupt.
+int ask_yesno(const char *const str, const bool direct)
{
- int r = ' ';
- int save_State = State;
+ const int save_State = State;
no_wait_return++;
- State = CONFIRM; // mouse behaves like with :confirm
- setmouse(); // disables mouse for xterm
+ State = CONFIRM; // Mouse behaves like with :confirm.
+ setmouse(); // Disable mouse in xterm.
no_mapping++;
+ int r = ' ';
while (r != 'y' && r != 'n') {
- /* same highlighting as for wait_return */
- smsg_attr(hl_attr(HLF_R),
- "%s (y/n)?", str);
- if (direct)
+ // Same highlighting as for wait_return.
+ smsg_attr(hl_attr(HLF_R), "%s (y/n)?", str);
+ if (direct) {
r = get_keystroke();
- else
+ } else {
r = plain_vgetc();
- if (r == Ctrl_C || r == ESC)
+ }
+ if (r == Ctrl_C || r == ESC) {
r = 'n';
- msg_putchar(r); /* show what you typed */
+ }
+ msg_putchar(r); // Show what you typed.
ui_flush();
}
- --no_wait_return;
+ no_wait_return--;
State = save_State;
setmouse();
no_mapping--;