From a64a2f85f44231b1c740413202769e59b3eab677 Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 8 Jun 2019 08:55:44 -0700 Subject: [PATCH] fix github pull request #197 - curses CR handling Fixes #197 Fixes #195 Add a call to nonl() to tell curses not to convert carriage return (^M) to newline. Line input accepts both ^J and ^M as end of line/end of input, but the core's command processing treats ^M as "unknown command" (by default; someone could use the BIND option to assign some command to that character). The end result is that accidentally pressing the or key (or Ctrl+M key combination) won't make the hero run towards the bottom of the screen as if the user had typed ^J. The curses docs also claim that it allows more optimization during screen updating by making ^J work as plain linefeed rather than ^M^J newline. The tty interface can achieve this (the 'do not convert ^M to ^J part', not the 'more optimization' part) by issuing the command 'stty -icrnl' (on Unix or sufficiently Unix-like system) prior to running nethack, but that has no effect when using the curses interface (at least with ncurses on OSX where I've tested it). A better fix would be to look up the current terminal settings at program startup and only call nonl() if -crnl was in effect so that curses and tty would behave the same in this regard, but curses is supposed to let us avoid those sorts of messy details.... --- doc/fixes36.3 | 7 ++++++- win/curses/cursmain.c | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/fixes36.3 b/doc/fixes36.3 index 2a267fe74..6c858a823 100644 --- a/doc/fixes36.3 +++ b/doc/fixes36.3 @@ -1,4 +1,4 @@ -$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.44 $ $NHDT-Date: 1559998716 2019/06/08 12:58:36 $ +$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.45 $ $NHDT-Date: 1560009340 2019/06/08 15:55:40 $ This fixes36.3 file is here to capture information about updates in the 3.6.x lineage following the release of 3.6.2 in May 2019. Please note, however, @@ -98,6 +98,11 @@ curses: when display windows get reconfigured (after setting align_status, curses: plug memory leak when getting a line of input is cancelled by ESC curses: after requesting a line of input from player, next line of message window could end up being skipped +curses: don't convert ^M (or or key) into ^J; both ^J and ^M + indicate end of input when typing a line of text but as nethack + commands, ^J means run toward bottom of screen (when number_pad is + off) and ^M is not bound to any command, so accidental won't + cause the hero to try to move tty: re-do one optimization used when status conditions have all been removed and remove another that tried to check whether condition text to be displayed next was the same as the existing value; sometimes new diff --git a/win/curses/cursmain.c b/win/curses/cursmain.c index 931de9569..0b36d5622 100644 --- a/win/curses/cursmain.c +++ b/win/curses/cursmain.c @@ -143,6 +143,8 @@ curses_init_nhwindows(int *argcp UNUSED, #endif noecho(); raw(); + nonl(); /* don't force ^M into newline (^J); input accepts them both + * but as a command, accidental won't run South */ meta(stdscr, TRUE); orig_cursor = curs_set(0); keypad(stdscr, TRUE);