address github issue #987 - curses: arrow keys
Issue reported by jeremyhetzler: left and right arrows produced unexpected characters when trying to use them to edit text that is being entered. The curses interface converts arrow keys and function keys related to the keypad into movement keys (hjkl or 4286 depending on the number_pad setting). But it was doing that all the time, not just when nethack wanted movement keys. This extends the existing program_state.getting_a_command flag to getdir() so that it can be used for controlling that in addition to 'altmeta' support. Typing an arrow when interacting with the map (actual command or getpos, now getdir too) will still work. Typing one when making a wish or naming a pet will issue a beep and be treated as if '\0' had been typed, and that normally gets treated as if ESC had been typed. [Possible room for improvement there. Losing the whole text when trying to back up a character feels a bit harsh.] Treating left arrow as escape rather than as h or 4 will probably be enough to train players not to try to edit text with it after they get burned by that a time or two. Bonus fix: curses' keystroke conversion only supported traditional number_pad behavior, not the inverted phone number pad layout. Closes #987
This commit is contained in:
11
src/cmd.c
11
src/cmd.c
@@ -5169,6 +5169,7 @@ getdir(const char *s)
|
||||
}
|
||||
|
||||
retry:
|
||||
gp.program_state.getting_a_command = 1; /* arrow key support for curses */
|
||||
if (gi.in_doagain || *readchar_queue)
|
||||
dirsym = readchar();
|
||||
else
|
||||
@@ -6199,7 +6200,7 @@ get_count(
|
||||
inkey = '\0';
|
||||
} else {
|
||||
gp.program_state.getting_a_command = 1; /* readchar altmeta
|
||||
* compatibility */
|
||||
* compatibility */
|
||||
key = readchar();
|
||||
}
|
||||
|
||||
@@ -6260,8 +6261,8 @@ parse(void)
|
||||
flush_screen(1); /* Flush screen buffer. Put the cursor on the hero. */
|
||||
|
||||
gp.program_state.getting_a_command = 1; /* affects readchar() behavior for
|
||||
* ESC iff 'altmeta' option is On;
|
||||
* reset to 0 by readchar() */
|
||||
* ESC iff 'altmeta' option is On;
|
||||
* reset to 0 by readchar() */
|
||||
if (!gc.Cmd.num_pad || (foo = readchar()) == gc.Cmd.spkeys[NHKF_COUNT]) {
|
||||
foo = get_count((char *) 0, '\0', LARGEST_INT,
|
||||
&gc.command_count, GC_NOFLAGS);
|
||||
@@ -6405,8 +6406,8 @@ readchar_core(coordxy *x, coordxy *y, int *mod)
|
||||
click_to_cmd(*x, *y, *mod);
|
||||
}
|
||||
gp.program_state.getting_a_command = 0; /* next readchar() will be for an
|
||||
* ordinary char unless parse()
|
||||
* sets this back to 1 */
|
||||
* ordinary char unless parse()
|
||||
* sets this back to 1 */
|
||||
return (char) sym;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user