Commit Graph

119 Commits

Author SHA1 Message Date
k21971
a0d57d0a74 curses - remove unused variable in curses_str_remainder()
and remove incorrect use of 'count' which could result in messages being
repeated indefiitely.
2019-10-19 00:43:52 +11:00
PatR
6182b014ca github pull request #235 - curses symbol set init
Fixes #235

For initial options under curses, specifying 'DECgraphics' as a
boolean rather than as 'symset:DECgraphics' wasn't overriding the
new default 'symset:curses'.  Since previously DECgraphics was
rejected for curses, it's possible that no one noticed.
2019-10-17 14:38:45 -07:00
PatR
61b976e0d5 couple of curses symbol handling bits
Primary and rogue symbols were being set to default if primary hadn't
been given a value, possibly clobbering rogue symbols if those had
been given a value.  Initialize them independenly.

Return early from curses_convert_glyph() if the value doesn't have
the 8th bit set since it now deals exclusively with DECgraphics
handling.  Force a sane value for returning early on rogue level.
2019-10-17 05:07:03 -07:00
PatR
33d33fcf19 fix curses build warning and update fixes36.3
Move a declaration that became mid-block when a preceding 'if () {'
got removed to top of block suppress warning about C99 feature.

Add new entry for the curses symset change to fixes36.3.
2019-10-16 16:19:51 -07:00
PatR
d0c4d27a50 githib pull request #232 - curses symset
This time I'm putting things in as-is before making a few tweaks.

The pull request was three or four separate changes.  I used the
patch instead so they've been collected into one commit.
2019-10-16 15:52:00 -07:00
PatR
7c53077eb7 comment typo 2019-10-14 16:02:30 -07:00
PatR
d550a33167 curses decgraphics bit
Array bounds error; thinko rather than typo.
2019-10-14 02:53:19 -07:00
PatR
32e2d7cfc5 fix use_inverse (aka wc_inverse) for curses
Highlighting for monsters shown due to extended monster detection and
for lava shown in black and white didn't work because that keys off
of 'iflags.use_inverse' (actually a macro for 'iflags.wc_inverse') and
curses wasn't enabling that window-capability option.  To be fair, it
was probably unconditional at the time the curses interface was first
developed.  It checked for whether a monster was supposed to be drawn
with inverse highlighting but wouldn't draw it that way because the
flag was always false.  Inverse b&w lava is relatively new and curses
hadn't been taught about it.

Various other things such as pets (if hilite_pet is on) and object
piles (if hilite_pile is on) get highlighted with inverse video when
use_color is off, regardless of whether use_inverse is on or off.
That's probably a bug.
2019-10-14 02:28:27 -07:00
PatR
027ce7c8b9 pull request 229/#H9299 - DECgraphics for curses
Fixes #230

Incorporate github pull request #230, support for DECgraphics-style
line drawing in the curses interface.  I've rewritten the
curses_convert_glyph() part so that it doesn't require C99 and
doesn't reinitialize its pair of arrays for every character written
to the map.  The DECgraphics conversion is now a straight char for
char one, DEC line drawing code to ACS, without regard to what map
symbol is intended or what 'cursesgraphics' uses for that symbol.
2019-10-13 17:41:24 -07:00
nhmall
bab05ea680 remove one band from a recent attempted warning correction 2019-10-08 20:17:01 -04:00
nhmall
193f8c39bd clear up some reported curses warnings 2019-10-06 09:07:49 -04:00
PatR
301a558a9c curses menu coloring
Have the 'menucolors' option control menu color pattern matching
(instead of curses-specific 'guicolor') for all menus, not just for
the persistent inventory window.
2019-08-31 23:51:59 -07:00
PatR
e9aac25922 fix #H9164 - menu colors for curses perm_invent
Commit e3af33c9db in June changed
curses handling for perm_invent to strip off doname()'s "a ", "an ",
or "the " prefix in order to shorten inventory entries and get a
couple of significant extra characters before end-of-line truncation.
That had an unintended impact on menu colors pattern matching for
patterns which expected the article prefix.  Do the matching before
stripping off the prefix instead of after so that the matching gives
the same results as when used on a normal inventory menu (even though
this means that from the user's perspective most perm_invent entries
will have invisible text at the start).

Also for menu colors, don't require curses-specific 'guicolor' option
be enabled when the general, more-specific 'menucolors' option exists
to control menu coloring.  (curses was requiring that both be True.)
2019-08-31 10:46:35 -07:00
nhmall
8a328ff7eb quite some Xcode warnings 2019-08-17 12:55:48 -04:00
PatR
188eedc654 curses: #extended command vs erase/kill chars
Support erase char and kill char when getting an extended command.

Also, show the cursor so that it's obvious where input focus is.
2019-07-11 01:02:34 -07:00
PatR
0e8163e341 curses: ncurses vs Ctrl+Click
Asking curses to report whether the Ctrl key was being pressed during
a mouse click was sending mouse position reports--even those aren't
being requested--and actual Ctrl+Left_click was reporting a pair of
duplicate Ctrl+Mouse_position_report events when a click was actually
performed.  So turn off Ctrl key reporting.

Mac with one-button mouse can be configured to send "secondary click"
for Ctrl+Click.  A laptop trackpad handles that differently (press the
button while two fingers are on the touchpad to send secondary click)
and doesn't support Ctrl+Click as an alternate way to do that.  If this
would work within curses then they could operate the same regardless
of how the user set the mouse or trackpad configuraiton.  But I wasn't
able to make it work right.
2019-07-09 18:55:10 -07:00
PatR
e84a0625dc curses moving left with ^H
Typing ^H actually passed a 16-bit value back to the core which got
interpreted as ^G after the extra bits were discarded.  I don't think
any previous changes to the curses interface caused this.  It's
astonishing that no one ever noticed; the world must be full of numpad
users.
2019-07-06 16:41:04 -07:00
PatR
7b1c38499d curses prompting tweak
With 'popup_dialog' On, a prompt which exactly fills the available
width would start the next line with a space (to separate the prompt
from user's answer) and then have the cursor waiting after it.  That's
unlike other behavior in the curses interface where the line split
would be instead of the separating space rather than in addition to it.

Old:
|long prompt?|
| X__________|
New:
|long prompt?|
|X___________|
where the X represents the cursor sitting over the start of blank space
waiting for user's answer.
2019-07-04 15:56:08 -07:00
nhmall
1ac321eadc test and adjust for curses with msdos 2019-07-02 14:01:44 -04:00
PatR
18ae35ef39 curses message history vs dumplog message history
When I implemented getmsghistory()/putmsghistory() for curses I was
assuming that DUMPLOG would only be used with tty, but it is interface
neutral and can be used with curses (or others).  So curses message
history needs to behave like tty message history and be sure to pass
along messages that bypass pline() and the normal message window.
(Mainly one-line summaries of long quest messages, but also old
messages fetched from a save file and available to be re-saved without
having been shown if new session doesn't generate enough new messages
to flush them.)
2019-06-30 11:50:08 -07:00
PatR
8d0edeb4ff curses+EDIT_GETLIN again
Turns the "fix" in commit 319dcf4746
handled removing the default answer for single-line-prompt plus
multi-line-answer but not for multi-line-prompt plus long-enough-
answer-to-reach-another-line.  The logic wasn't quite right and I
misunderstood what is stored in linestarts[] so even correct logic
wouldn't have solved things.
2019-06-28 17:00:20 -07:00
PatR
bed5570e3b curses popup single char input
With 'popup_dialog' On, a one line popup with question and likely
responses and default answer was shown, but without having the
cursor displayed at the end of emphasize that it was waiting for an
answer.  Make the popup be one character wider so that there is room
to show the cursor.  No effect when 'popup_dialog' is Off and prompts
are shown at the bottom of the message window; those already have the
cursor sitting at the end.
2019-06-28 12:28:40 -07:00
PatR
2145387ac8 curses menu and text window size
Make final inventory disclosure use a full width menu instead of
the default 38-column width with lots of wrapping.  Also, increase
that default from 38 to 40 for the rest of the time.  Commit
9f6588af49 made the 38 vs 40 portion
matter much less but I decided to keep it in anyway.

When a menu or 'things that are here' popup has only a couple of
lines and they happen to be narrow, a sized-to-fit window isn't
always easy to spot when it is shown over the ends of old messages
rather than over the map, even with a border box around it.  Give
such windows a minimum size of 5x25 so that they always stand out
enough to be immediately seen.  This will cause more message text to
be rewritten occasionally (after dismissing the menu or text window)
but the curses interface seems to discount that as something to be
concerned about.
2019-06-28 11:59:14 -07:00
PatR
80374d46b5 Merge 'curses-mouse_support' into NetHack-3.6
Fully support the mouse_support option for curses, via 'O' as well as
via config file.  At the moment, mouse_support:1 and mouse_support:2
are equivalent.

Also, fix the screen-to-map coordinate translation.  When the mouse
is active and over the map, the pointer's cursor becomes a cross-hair
(may very by platform) and the character cell chosen for a click
seems to be a few pixels to the right of the center of the '+'.
2019-06-28 03:08:30 -07:00
nhmall
39eed81aa2 PDCurses behaves the same as ncurses 2019-06-27 23:22:34 -04:00
PatR
df8eac79b5 curses erase char and kill char
Support user's terminal settings for erase char and for kill char.
Erase char is typically <delete> or <backspace>, both of which are
already explicitly handled so probably no effect there.  Kill char
(generally ^U these days) will be honored unless it is a printable
character (don't know whether there are any troglodytes out there
who still use '@' for that...).  The current handling for ESC works
the same if there is any input to kill, but yields 'cancelled' when
there isn't.

That's for message window getline(), which operates char-by-char.
The popup getline() uses a curses routine to get an entire string
and already honors kill char but treats ESC as input of ^[.
2019-06-27 17:18:07 -07:00
PatR
56387dccb6 curses mouse right-click
Right button is button3 rather than button2.  Accept either and treat
both as "not left" to pass CLICK_2 back to the core.

Treat <Ctrl>+left-click as "not left" too, to simplify usage with Mac
one-button mouse (where <Ctrl>+left-click can be configured to send
"secondary click" but might not be set do so) or one-button laptop
trackpad (where having two fingers on the scrolling portion of the pad
while clicking the button is necessary to send "secondary click").
2019-06-27 15:02:49 -07:00
PatR
aada9e2706 mouse_support for win/curses using ncurses 2019-06-26 15:46:44 -07:00
PatR
4f0b1262c5 curses clipped map 'scrollbars'
The position bars shown by curses when the map is clipped weren't
being drawn as intended (integer arithmetic).  Changing parentheses
was enough to get it working, but it didn't handle the edge case
where non-zero got rounded to 0 (so when map was panned down, the
uppermost character of the vertical position bar still showed '*',
falsely indicating that top of map was currently within view.
2019-06-25 03:17:47 -07:00
PatR
3bd46a3536 curses cursor
Followup to 1c03d0970115c776d1c4791fea3c33f70b0b5378; that had been
too easy.  When map was clipped and panned to the side, the highlight
for hero's spot was shown next to the '@' instead of on it.
2019-06-25 02:30:27 -07:00
PatR
6506f769a6 fix #H7840 - curses ':' menu search+toggle
Using ':' to have search string matching toggle items chosen for
selection would show selection highlighting on the current page for
items matched off-page.
2019-06-24 19:28:50 -07:00
PatR
e3af33c9db curses 'perm_invent' fixes
I noticed the wrapping issue while testing out the 'bad fruit' fix,
then the other things while fixing it.

1) inventory entries too wide for narrow persistent inventory window
   wrapped without any control; normally can't be seen except for the
   last entry when the list is short enough to leave at least one line
   available; it looked fairly reasonable with window borders Off, but
   when On the last char of the first line and first char of second
   line were clobbered by the border box;
2) when there were too many entries to fit within the height, those
   after the last one which fit were appended to it for borders Off
   (or written on bottom line and then overwritten by the border box
   for borders On); noticed because the selector letter is highlighted
   with inverse video, even when written at an unexpected place;
3) suppress the inverse video hightlighting of inventory letters since
   they can't be selected from that 'menu';
4) for borders Off, the top line was left blank as if a border was
   going to be drawn there;
5) since the entries are truncated due to the narrow window (on a
   modest sized display), strip off leading "a", "an", or "the" prefix
   for inventory entries (written to curses perm_invent window only);
   lets a couple more characters of more interesting stuff be seen.
2019-06-24 18:39:24 -07:00
PatR
9f6588af49 curses text windows
Most of the entries for '?' looked awful because curses was using
((terminal_width / 2) - 2) for the window width ('- 2' was to make
for for a border around the popup window, regardless of what the
'windowborder' option was set to).  Splitting text that has been
manually formatted for 80 columns "worked" but looked bad when not
required.

Some of the help files are using 79 characters on a few lines,
producing wrapped text when displayed.  Those would look better if
limited them to 78 or if curses can be modified to suppress the
window border when the entire display is being covered by a popup.
2019-06-20 01:14:50 -07:00
PatR
1c03d09701 curses map window
tty ignores map column #0 (0-based index), like the core, and draws
the map in screen columns 1 (1-based index) through 79, leaving screen
column 80 blank.  curses was drawing all 80 map columns and since #0
was always unused, screen column 1 was blank and the map was shown in
2 through 80.  Change curses to work like tty.

This was too easy; there may be problems lurking.  One known issue: it
should be made smarter about when clipping/panning is necessary since
it thinks that a full 80 columns are needed but 79 suffice.
2019-06-18 03:52:28 -07:00
PatR
319dcf4746 curses EDIT_GETLIN - discarding preloaded answer
EDIT_GETLIN is more complicated on curses than on tty due to way that
long lines are handled....

Using ESC to get rid of the default response removed it from the
answer buffer but didn't erase back to the end of actual prompt,
making it look as if it was still there.  Fixing that for a one-line
prompt+answer was needed and would have been easy but it also needs to
be prepared to go back to prior lines.  Both the prompt and the answer
could conceivably span lines although in practice it will usually just
be one line or else prompt+answer combined spanning to a second line.

This hasn't been exhaustively tested been seems to be working correctly.
2019-06-09 07:07:34 -07:00
PatR
a64a2f85f4 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
<return> or <enter> 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....
2019-06-08 08:55:44 -07:00
PatR
cdb4a9e8b3 fix github issue #193 - curses: menu search
Fixes #193

Under curses interface, make characters which are both entry selectors
and menu commands function as a selector.  Needed to support using ':'
to look inside a container when applying/looting it via menu, instead
of performing a menu search operation.  (There was another case like
this but I can't remember what the circumstances are.  The fix is
general enough to cover it, whatever it is.)

For menus which don't have ':' as a choice, make sure search prompt
doesn't offer garbage default input when built with EDIT_GETLIN.

Bug?  If player has 'popup_dialog' option On, EDIT_GETLIN is ignored.
Plain curses I/O doesn't seem to offer a way to implement it.
2019-05-31 10:11:45 -07:00
PatR
f478b4ec95 curses getline()
After going back and forth between prompts causing message lines
to be overwritten and to be skipped, this yoyo might have finally
run out of string.  Fingers crossed....
2019-05-28 02:27:40 -07:00
PatR
c61d3d6403 curses message window
Fix a 'FIXME': don't follow a message with two spaces in anticipation
of combining with the next one, precede the next one with two spaces
when they're being combined.  Keeps nethack's message window <mx,my>
coordinates in sync with curses' internal coordinates.
2019-05-28 01:52:37 -07:00
PatR
6bd2f4979c curses memory leak
Back in February, my e991dd1b0c added
ESC (when there's no input) as an early return for curses' getline,
but it neglected to clean up some allocated memory.
2019-05-25 07:37:08 -07:00
PatR
ba5efe7f61 curses message window vs prompting
Fix a problem introduced by f218e3f15e
and/or a19e64e470.  Sometimes the line
after a prompt would be empty and the next message get shown on the
line after that.  a19e64e470 was intended to fix the opposite problem
so probably overshot the mark....
2019-05-24 01:33:45 -07:00
PatR
5de1666f9c curses message window refresh
Sometimes curses tears down and recreates all its windows (when the
display is resized, for instance) and after doing that it repopulates
the message window with data saved for use by ^P.  But it was showing
the oldest messages available rather than the most recent ones.

There is still room for improvement.  That process combines short
messages but the refresh is based on the available number of lines;
combining messages can result in lines at the bottom of the message
window being left blank.  This could be fixed by reverse-scrolling the
window and inserting more messages at the top, or by combining short
messages in history data instead of at refresh time.  The second seems
easier but won't handle changing the message window's width sensibly,
and neither method handles wrapped, long lines well.  A More>> prompt
(possibly more than one) is issued if the refresh shows too many lines
(either because long messages already took multiple lines or because
the window has become narrower and ones which used to fit now need to
be wrapped).
2019-05-23 18:56:20 -07:00
PatR
3863b17384 curses: remove duplicate wincap2 bit
WC2_HITPOINTBAR was OR'd into wincap2 bitmask twice.
2019-05-23 17:54:37 -07:00
PatR
d1ce0aac89 fixes github issue #190 - EDIT_GETLIN for curses
Fixes #190

Add EDIT_GETLIN support for curses.  It remains disabled by default.
2019-05-18 23:52:04 -07:00
PatR
a19e64e470 curses followup
Some prompts were being overwritten by the message that followed.

And clear_nhwindow(WIN_MESSAGE) gets called for just about every
keystroke so try to reduce the overhead I unwittingly added.  The
"scroll up one line earlier than the next message" mentioned in
the prior commit is much more obvious that I realized and prompt
erasure might need to be redone.
2019-05-18 08:12:43 -07:00
PatR
f218e3f15e fix #H8753 - curses message window anomalies
Autodescribe feedback and multi-digit count prompts are always shown
on the last line of the message window and are suppressed from message
history (both ^P and DUMPLOG).  When the message window is using all
available lines, the last one was being overwritten (until the count
or the feedback was completed or dismissed, then last line returned).
Adopt the suggestion that it be scrolled up a line instead of being
overwritten.  [I haven't been able to reproduce the reported problem
where shorter overlaid text left some of longer underlying text visible
but that should now become moot.]

Bonus fix:  while testing, I noticed that if your screen only has room
for a one-line message window and you used ESC to cancel 'pick a spot
with cursor' prompting before moving the cursor, the prompt was left
intact on the message line.  tty erases it in that situation, but the
clear_nhwindow(WIN_MESSAGE) was a no-op for curses because it usually
doesn't erase old messages.  This changes the curses behavior when the
core asks it to erase the message window:  now it forces one blank line
of fake autodesribe feedback (causing the prompt or other most recent
message to scroll off top), then removes that fake feedback (leaving
a blank message line).  For multi-line message window, the old messages
scroll up by one line sooner than they would when waiting for the next
real message but are otherwise unaffected.
2019-05-18 02:25:48 -07:00
PatR
4a1f1292d9 fix #H8712 - curses menu selector overflow
The curses interface would assign menu selector characters a-z, A-Z,
and then 0-9, but trying to type 0-9 would start a count rather than
select an entry, and if the display was tall enough for more than 62
entries, the ones after '9' were ASCII punctuation characters.
Limit the number of entries per page to 52 + number_of_'$'_entries
(which should be 0 or 1) so that it won't run out of normal letters.

The perm_invent window, if enabled, ought to allow more than that
because it isn't used to make selections and might have an arbtirary
number of '#' overflow entries.  But I'll leave that for somebody
else to tackle.

Tested by temporarily setting the limit to 26 instead of 52 since
I'm not able to display anything tall enough to exercise the latter.
2019-05-11 03:04:53 -07:00
PatR
fcd38bdbef couple of interface comments 2019-05-05 13:38:58 -07:00
PatR
6c84ccc241 status 'fieldorder'
DEC C in one of its non-ANSI modes didn't like
 fieldorder = test ? &array1 : &array2;
It first complained that '&' applied to an array has no effect (which
was typically true in pre-ANSI environments) and once those '&'s are
ignored, the attempted assignment didn't match the variable's type.
That code was actually more complicated that it needed to be; slightly
simpler code works as intended.
2019-04-19 12:28:14 -07:00
nhmall
5258bb0ed4 adjust for recently released MS Visual Studio 2019
win\curses\cursstat.c(886) : error C4703: potentially uninitialized local pointer variable 'p' used
2019-04-09 00:35:02 -04:00