summaryrefslogtreecommitdiff
path: root/src/keys.c
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2011-10-04 00:13:09 +0000
committerLukas Fleischer <calcurse@cryptocrack.de>2011-10-06 12:37:06 +0200
commit98651a549f6fc43d96207734fb0f02b240354a4c (patch)
tree1a89355f2f0ddf3aa543fe8c01b21d37a13cd664 /src/keys.c
parentba2aa5167b2157c99f3be4861c11717cd1b4cc6f (diff)
downloadcalcurse-98651a549f6fc43d96207734fb0f02b240354a4c.zip
Add count buffer to keys_getch()
Key commands can be prefixed with a natural number - keys_getch() will store this number in the buffer pointed to by the second parameter. Set this parameter to NULL to disable count prefixes. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src/keys.c')
-rw-r--r--src/keys.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/keys.c b/src/keys.c
index 1a46530..180b80d 100644
--- a/src/keys.c
+++ b/src/keys.c
@@ -194,11 +194,26 @@ keys_get_action (int pressed)
}
enum key
-keys_getch (WINDOW *win)
+keys_getch (WINDOW *win, int *count)
{
- int ch;
+ int ch = '0';
+
+ if (count)
+ {
+ *count = 0;
+ do
+ {
+ *count = *count * 10 + ch - '0';
+ ch = wgetch (win);
+ }
+ while ((ch == '0' && *count > 0) || (ch >= '1' && ch <= '9'));
+
+ if (*count == 0)
+ *count = 1;
+ }
+ else
+ ch = wgetch (win);
- ch = wgetch (win);
switch (ch)
{
case KEY_RESIZE:
@@ -586,7 +601,7 @@ keys_popup_info (enum key key)
#define WINCOL (col - 4)
infowin = popup (WINROW, WINCOL, (row - WINROW) / 2, (col - WINCOL) / 2,
keydef[key].label, info[key], 1);
- (void)keys_getch (infowin);
+ (void)keys_getch (infowin, NULL);
delwin (infowin);
#undef WINROW
#undef WINCOL