tweaks: use a separate function to ask ncurses for keycodes

This commit is contained in:
Benno Schulenberg 2016-08-16 10:49:55 +02:00
parent 0dd2a55284
commit c661506681
2 changed files with 18 additions and 17 deletions

View File

@ -47,10 +47,7 @@ message_type lastmessage = HUSH;
/* Messages of type HUSH should not overwrite type MILD nor ALERT. */
#ifndef NANO_TINY
int controlleft = CONTROL_LEFT;
int controlright = CONTROL_RIGHT;
int controlup = CONTROL_UP;
int controldown = CONTROL_DOWN;
int controlleft, controlright, controlup, controldown;
#endif
#ifndef DISABLE_WRAPJUSTIFY

View File

@ -1535,6 +1535,19 @@ void terminal_init(void)
#endif
}
#if !defined(NANO_TINY) && defined(HAVE_KEY_DEFINED)
/* Ask ncurses for a keycode, or assign a default one. */
int get_keycode(const char *keyname, const int standard)
{
const char *keyvalue = tigetstr(keyname);
if (keyvalue == 0 || keyvalue == (char *)-1)
return standard;
else
return key_defined(keyvalue);
}
#endif
/* Say that an unbound key was struck, and if possible which one. */
void unbound_key(int code)
{
@ -2514,20 +2527,11 @@ int main(int argc, char **argv)
#endif
#if !defined(NANO_TINY) && defined(HAVE_KEY_DEFINED)
const char *keyvalue;
/* Ask ncurses for the key codes for Control+Left/Right/Up/Down. */
keyvalue = tigetstr("kLFT5");
if (keyvalue != 0 && keyvalue != (char *)-1)
controlleft = key_defined(keyvalue);
keyvalue = tigetstr("kRIT5");
if (keyvalue != 0 && keyvalue != (char *)-1)
controlright = key_defined(keyvalue);
keyvalue = tigetstr("kUP5");
if (keyvalue != 0 && keyvalue != (char *)-1)
controlup = key_defined(keyvalue);
keyvalue = tigetstr("kDN5");
if (keyvalue != 0 && keyvalue != (char *)-1)
controldown = key_defined(keyvalue);
controlleft = get_keycode("kLFT5", CONTROL_LEFT);
controlright = get_keycode("kRIT5", CONTROL_RIGHT);
controlup = get_keycode("kUP5", CONTROL_UP);
controldown = get_keycode("kDN5", CONTROL_DOWN);
#endif
#ifndef USE_SLANG