Commit Graph

74 Commits

Author SHA1 Message Date
Pasi Kallinen
a57d0e6f4f Curses: add support for the palette config option
Depends on CHANGE_COLOR compile-time option.

Also allow multiple palette-definitions in the config file.
2024-04-13 12:01:43 +03:00
Pasi Kallinen
c4d4bafb44 Fix NO_TERMS compile, rename func
... to match others, from tty_curs_set to term_curs_set
2024-04-02 14:31:33 +03:00
Pasi Kallinen
7030b0b9fe tty: hide cursor unless waiting for user input
Use vi (cursor_invisible) and ve (cursor_normal) to hide and show
cursor, if the terminal supports those.  This way on a slower
connection the cursor doesn't jump all over the place when doing
map or menu updates.
2024-04-02 10:28:20 +03:00
PatR
dddfd66e7a undo recent DECgraphics optimizations
Unresolved display issues with rxvt-unicode after the optimizations
dealing with switching between DECgraphics line-drawing character set
and normal character set.

Effectively comment them out rather than revert the commits.
2024-03-31 15:49:16 -07:00
nhmall
7f2af9698f put wintty.c and termcap.c logic to previous 2024-03-25 09:38:54 -04:00
nhmall
ba00dc9066 sever extracolors from utf8map and ENHANCED_SYMBOLS
move the custom color data into its own field in the glyphmap
and disassociate it from the unicode/utf8 stuff.

move the glyphcache stuff during options processing and parsing
into new file glyphs.c and out of utf8map.c, and make it
general, and not part of ENHANCED_SYMBOLS.

Do the groundwork for allowing glyph color customizations to
work when any symset is loaded and not restrict it only to
the enhanced1 H_UTF8 symsets.

The customizations in effect are still affiliated with a particular
symset.

Also closes #1224, but the PR itself references a data structure
made obsolete by this commit. The curses comment from the PR was
added into the code.

The PR also made several suggestions, but only the first
one has been included in this commit (and no longer based on
the handler), that being:
"allow defining colors if other symbol handling modes are used
(possibly limited to the standard 16 colors)."

FredrIQ also wrote the following suggestions in PR#1224:

Something I was also contemplating, unrelated to implementation of this
support in curses, would be the ability for the following:

allow defining colors if other symbol handling modes are used (possibly limited to the standard 16 colors)
allow defining attributes (for example: glyph:G_pet_female_kitten:U+0066/red/underline)
allow specifying glyphs as wildcards for defining global color/attribute changes

Something I also want to see are keywords for "don't change the current defined data". If this
were to be added, you could for example do this:
OPTIONS=glyph:G_*_fox:U+0064/blue
OPTIONS=glyph:G_statue_*:basechar/gray/underline
for "make all foxes use a blue color, make all statues gray with underline" without needing
to specify the relevant character for every statue. This ("basechar", "basefg", etc)
should perhaps also be added for MENUCOLORS and statushilites, so that you can, for
example, underline all items being worn without needing to specify a bunch of
near-duplicate rules for combining BUC colors + underline worn items
as per #1064
2024-03-23 15:36:22 -04:00
RainRat
a3658f85ac fix typos 2024-02-28 20:15:56 -08:00
nhmall
688ac6ffbe remove register from variable declarations 2024-02-19 16:30:07 -05:00
PatR
5ef51a88d4 more DECgraphics tinkering 2024-02-19 11:04:29 -08:00
PatR
9226a5dea6 couple of DECgraphics optimizations
If a termcap entry for ending attributes and color also contains
the code to switch from secondary font back to primary (HE_resets_AS
hack), maybe strip the AS code out of HE (and clear the HE_resets_AS
flag) when setting up DECgraphics.  Affects whether nethack sends
extra AS sequences while rendering a run of VT line-drawing chars.
My HE doesn't reset AS so that aspect hasn't been exercized.

When switching back and forth between normal and line-drawing,
defer the switch away from line-drawing if the character will be
rendered the same in both character sets (uppercase letter, digit,
most punctuation).  That might just defer the AE, but could skip it
and next AS depending on what characters are written.  The cycle
might repeat an arbitrary number of times, avoiding sending many
AS+AE combinations rather than just one.

Both of these optimizations are pretty small but reducing the number
of characters sent from a server to a remote user is worthwhile.
2024-02-18 15:01:21 -08:00
PatR
7c20bf4afa tty: term_start_color(NO_COLOR)
Make term_start_color() more versatile.  If it gets passed NO_COLOR
then it performs term_end_color().  Should be able to streamline
some of the color handling this way although this hasn't done so.
2023-12-07 02:52:41 -08:00
nhmall
04082a2033 Remove TEXTCOLOR build option 2023-11-22 16:01:58 -05:00
PatR
284452796c redo tty resizing
Rest of 'not PR #1102'.  Resizing the terminal while getpos was in
operation recalculated the map from scratch instead of redrawing what
the core considers to already be shown.  And it was always operating
while an asynchronous signal was excuting which could potentially
clobber whatever was running at the time the signal arrived.

This uses same redrawing as the prior '^R during getpos()' fix.  It
also only performs the resize while tty_nhgetch() is waiting for
input.  If that is the situation at the time that the signal arrives
then it will resize immediately (while in the asynchronous signal
handler); if not, it will set a flag and tty_nhgetch() will do the
resize the next time it gets called.

This builds with TTY_PERM_INVENT enabled and doesn't seem to be any
worse than before, but there are bugs with that.  The only way I could
get perminv to appear was to save and restore, then perm_invent was
honored for both RC file and mO command.  And once I managed to get it
to display, moving an item from a lower case slot to slot 'A', made
that item vanish; nothing appeared in the invent's right hand panel.

Both of those misbehaviors already happen prior to this commit.  I
also saw an abort+panictrace if I resized while at the "Dump core?"
prompt when running the pre-commit code and didn't see that with the
post-commit code (although the prompt wasn't shown so I couldn't tell
that it was waiting for an answer).  The abort probably sounds scarier
than it warrants; I suspect that the pre-commit code just treated the
resize as answering 'y' for some reason, possibly a stale value in the
variable it uses.
2023-10-12 18:45:14 -07:00
nhmall
13a5d978f9 remove a non-UNIX problematic define in termcap.c 2023-05-22 14:13:22 -04:00
nhmall
826ce951e7 get rid of NetHack macro conflict with curses routine delay_output() 2023-04-21 08:25:53 -04:00
PatR
4927527493 get rid of warnings when building tty interface
My guess about NCURSES_CONST was right; it expands to nothing in the
/usr/include/term.h on my old OSX system.  There aren't any levers or
knobs available to avoid that so this adds casts of string literals
to avoid warnings about passing a literal to something that expects
non-const.

There's a lot of conditional code in termcap.c and the nhStr("foo")
(hidden cast) changes only got tested for my default configuraiton.
I tried to avoid typos but I attempt such all the time and we know
how that tends to go.

Are we sure that systems which need to install a curses development
package have term.h without that?  A tty-only build shouldn't require
that.
2023-04-06 01:18:39 -07:00
nhmall
2185d325c4 header file changes hack.h, decl.h/.c, system.h, wintty.h
- Move secondary preprocessor defines down further in config.h
so that they can be overridden via [platform]conf.h which is
included from global.h, specifically:
    LIVELOGFILE when LIVELOG is defined
    DUMPLOG_FILE when DUMPLOG is defined

- Minimize platform-specific, or compiler-specific code in hack.h and decl.h.

- reorganize src/decl.c to align with include/decl.h.

- a new header file cstd.h added, containing calls to C99
standard header files.

- hack.h, decl.h, and decl.c have been cleaned up and had code
moved so that things line up as follows:

     hack.h     defines values that are available to all
                NetHack source files, contains enums for use in all
                NetHack source files, and contains a number of
                struct definitions for use in all NetHack source files.
                It does not contain variable declarations or variable
                definitions.

     decl.h     contains the extern declarations for variables that
                are defined in decl.c. These variables are global and
                available to all NetHack source files. The location of
                the variables within decl.h was random, so give it some
                order for now.

     decl.c     contains the definition of the variables declared in
                decl.h, and initializes them where appropriate. The
                variable definitions are laid out in much the
                same order as their declarations in decl.h.

- wintty.h: There were some varying terminal-related prototypes in
system.h, and that was the only thing left that demanded that
system.h be included. Those have been replaced by an #include
<term.h> in include/wintty.h to get the more current (and hopefully
more correct) prototypes, rather than hardcoding them in NetHack
sources.

For edge-case platform compatiblity, there is no #include <term.h>
if the build defines NO_TERMCAP_HEADERS. In that case one set of
hardcoded prototypes is still used in include/wintty.h.

The added #include "term.h" is also bypassed for NO_TERMS builds (builds
that don't link to terminfo/termcap at all, but still present a tty
interface using platform or window-port specific functions to fulfill
the same role as that of terminfo/termcap).

- some scattered, unnecessary #include "integer.h" were removed from
various files, since that's always included in current NetHack-3.7
sources, either directly from config.h or indirectly from #include
"hack.h".

- system.h references removed.

- new cstd.h added; the #include "system.h" references in Makefiles
and project files (Xcode, visual studio), were replaced
with #include "cstd.h" references. A "make depends" is probably
warranted.

Also:

 - Use of <term.h>, which defines clear_screen() as a macro, conflicts
with an actual function with that name in win/tty/termcap.c. The most
straight-forward course of action was to rename the NetHack function,
and change the references to it, from clear_screen() to
term_clear_screen(), so that was done.
2023-04-05 11:49:09 -04:00
nhmall
2fc0d25d45 introduce support for coloring the frame behind a map location
Also includes support by paxed for polearm targeting using the
frame color.

Also renames USE_TILES to TILES_IN_GLYPHMAP which is a more
accurate description.

Not all window interfaces have full support for the color framing
of the background square yet.

MS-DOS needs further work (to bring it to both VESA and VGA, with
and without tiles.

Windows GUI is missing support.

X11 and Qt have been started, but may require further refinement.
2023-01-01 19:55:02 -05:00
nhmall
02a48aa8cf split g into multiple structures
The consolidation of global variables from scattered source
files into decl.c and declared in decl.h was begun in 3.7.0.
Their placement in common files was done for centralized
initialization and potential re-initialization during a
"play again" scenario.

It wasn't really necessary for all of them to be housed in a
single huge structure to meet the "play again" requirement,
and the single huge structure has been a little unwieldy when
it comes to maintenance.

Following this commit, instead of one single extremely large structure
named 'g' to house all of the relocated global variables, they
are distributed into several ga through gz.

To make things easy for the developer, each variable is placed
into the struct corresponding to the starting letter of the variable.
That way, no lookup is required in order to know which struct houses
a particular variable, it is a simple match to the starting letter
for all the centralized global variables.

A global variable named 'amulets', would be found in ga.
    ga.amulets
     ^ ^
A global varable named 'move', would be found in gm.
    gm.moves
     ^ ^
A global variable named 'val_for_n_or_more' would be found in gv.
    gv.val_for_n_or_more
     ^ ^
A global variable named 'youmonst' would be found in gy.
    gy.youmonst
     ^ ^
2022-11-29 21:53:21 -05:00
PatR
c3b007186c italic attribute on tty
If switching to italic isn't supported for tty, switch to underline
instead.  Comparable to the curses interface.
2022-09-23 23:37:02 -07:00
Patric Mueller
8bf5654eed tty and curses: support italic as text attribute 2022-09-04 22:33:25 +02:00
nhmall
cb0c21e91d ENHANCED_SYMBOLS
A new feature, enabled by default to maximize testing, but one which can
be disabled by commenting it out in config.h

With this, some additional information is added to the glyphmap entries
in a new optional substructure called u with these fields:
    ucolor          RGB color for use with truecolor terminals/platforms.
                    A ucolor value of zero means "not set." The actual
                    rgb value of 0 has the 0x1000000 bit set.
    u256coloridx    256 color index value for use with 256 color
                    terminals, the closest color match to ucolor.
    utf8str         Custom representation via utf-8 string (can be null).

There is a new symset included in the symbols file, called enhanced1.

Some initial code has been added to parse individual
OPTIONS=glyph:glyphid/R-G-B entries in the config file.

The glyphid can, in theory, either be an individual glyph (G_* glyphid)
for a single glyph, or it can be an existing symbol S_ value
(monster, object, or cmap symbol) to store the custom representation for
all the glyphs that match that symbol.

Examples:
   OPTIONS=glyph:G_fountain/U+03A8/0-150-255

(Your platform/terminal font needs to be able to include/display the
character, of course.)

The NetHack core code does parsing and storing the customized
entries, and adding them to the glyphmap data structure.

Any window port can utilize the additional information in the glyphinfo
that is passed to them, once code is added to do so.

Also, consolidate some symbol-related code into symbols.c, and remove it from
files.c and options.c
2022-05-07 10:25:13 -04:00
PatR
0e6456c9f4 tty_raw_print_bold() again
Redo the tty handling for raw_print_bold() intended to keep it working
after exit_nhwindows().  Don't assign static addresses to nh_HI and
nh_HE in case the routine to free dynamic termcap data somehow gets
called again.
2022-01-31 18:31:34 -08:00
PatR
532cddbd35 topten's so (standout) handling
This fixes the broken code that was using a boolean as an integer.
I didn't try to track down when it changed or what it looked like
before the change.  The intended effect is fairly straightforward;
just padding a bold line with spaces.  I've no idea why someone
deciced that that was useful though.

It also fixes something I broke six years ago:  tty_exit_nhwindows()
releases the termcap data needed for turning bold on and off, so
raw_print_bold() used by topten() stopped working on tty then.

Not fixed:  the code in really_done() for dealing with topten() vs
the 'toptenwin' option really ought to be redone.
2022-01-31 18:20:34 -08:00
Pasi Kallinen
9176589b59 tty: document the termcap codes
some of the termcap codes were missing document comments.
2022-01-07 17:41:39 +02:00
nhmall
3bb9f91a1e get Xcode build working 2021-12-03 15:01:22 -05:00
Patric Mueller
456e62ef1f tty: use bright colors directly on supporting terminals
Terminals supporting more than 8 colors can directly display the bright
colors (upper 8 colors of the 16 color palette).

The tty port now only uses bold for displaying bright colors as a fallback to
previous behavior for terminals with 8 colors.
2021-08-07 11:53:36 +02:00
Heinrich Kuttler
28b3902ea7 termcap.c: Don't use hilites[CLR_BLACK] = NULL for ANSI_DEFAULT
This didn't crash since xputs is defensive and checks if it got a NULL
string, but it also didn't display black entries (dragons, unicorns,
orcish arrows, ...) as black or otherwise different from gray entries.
2021-07-22 11:11:23 +03:00
nhmall
f963c5aca7 switch source tree from k&r to c99 2021-01-26 21:06:16 -05:00
PatR
db673ab791 termcap followup
A little more testing for ANSI_DEFAULT forced on has revealed
that hilites[Black] has also been left Null, a problem that
MS-DOS hid.
2020-12-31 16:09:46 -08:00
PatR
e7e07cb067 pull request #411 - freeing termcap hilite entries
(strings to switch color) for ANSI_DEFAULT.  Instead of lumping
more conditional code into tty_shutdown() I put the new code
into a separate routine and also pulled the existing setup code
out of tty_startup() into a separate routine too.

It will be a miracle if this doesn't break anything due to the
crazy amount of convoluted conditionals present in termcap.c.

On the other hand, I found and fixed a bug while trying to test.
The ANSI_DEFAULT hilites for Gray and No_Color were null instead
of an empty string.  MS-DOS stdio apparently fixes that up, but
on OSX (after #undef UNIX and TERMLIB and TERMINFO and #define
ANSI_DEFAULT in termcap.c) I started seeing instances of "(null)"
on the map (OSX stdio does a different fix up for Null pointers)
as soon as I enabled 'color'.  It was an attempt to set No_Color.

Closes #411
2020-12-31 14:49:21 -08:00
nhmall
ac9ba38449 file header bump from "NetHack 3.6" to "NetHack 3.7" 2020-08-03 22:07:36 -04:00
nhmall
26ac20503c fixup build for platforms without curses after drawing.c split
An Undefined reference to decgraphics_mode_callback was possible
if built for tty only.

drawing.c had an #include "tcap.h" which is what actually defined
TERMLIB. It isn't needed in drawing.c anymore, but it is needed
in symbols.c, in order to get the define for TERMLIB so that
decgraphics_mode_callback variable gets defined.

The undefined reference was from win/tty/termcap.h in code that
was #ifdef TERMLIB, but win/tty/termcap.h has the #include "tcap.h"
2020-05-09 18:07:56 -04:00
Pasi Kallinen
5f9714bf92 Remove workarounds for ancient compilers 2020-04-03 08:21:08 +03:00
nhmall
3a84bff7f3 Merge branch 'NetHack-3.6' 2019-11-30 15:41:52 -05:00
nhmall
0843c5d922 some dead code eliminations and a couple of documentation updates 2019-11-30 13:35:14 -05:00
nhmall
42a13a1198 has_color() performance fixes
Performance profiling showed that multiple strcmpi() calls were
occurring each and every time a character was going to the map.

This update:
- honors the WC_COLOR capability
- It allows a window-port to control individual color availability should the window-port wish to do so.
- Makes checking on the individual colors for the active window-port is a straightforward table lookup at the CLR_ offset.

iflags.use_color remains a master on/off switch for use of color, regardless of the capability
compiled into the game (default TRUE).

The has_color() routine, which is now a shared routine in src/windows.c, could likely be made
into a simple macro to eliminate the function call, but this update does not go that far.

This hits a lot of port files due to the window-port interface change, mostly cookie-cutter.
2019-11-30 11:44:07 -05:00
nhmall
fe1b2d6e82 Merge branch 'NetHack-3.6' 2019-10-06 09:16:23 -04:00
PatR
0d76f68f2c tty xputc()
Another part of github issue 227.  Casting a function pointer when
passing it to another function is iffy when lying about the return
type.  tputs() expects a routine which returns int, so give it one.
Other xputc() usage is equivalent to putchar(), so define xputc()
with the same function signature as that has.

The tputs() declarations in system.h should probably be changed
(third argument is a function which takes an int rather than
unspecified parameters) but I've left them alone.  I made that change
to tputs() in sys/share/tclib.c though.

NT and MSDOS changes are untested.  tclib.c compiles ok with clang-
as-gcc on OSX but hasn't been tested with the port that uses it (VMS).
2019-10-05 16:49:34 -07:00
nhmall
6688053802 remove STATIC_DCL, STATIC_OVL, STATIC_VAR, STATIC_PTR from win/tty 2019-07-14 17:33:44 -04:00
nhmall
e6efc2a81b Merge branch 'NetHack-3.6' 2019-07-02 14:07:26 -04:00
PatR
8bb8d32625 tty status highlighting via attributes
Highlighting via attributes got broken three months ago.  May or
may not have been noticeable depending upon which attributes are
supported.  Too many variations of attribute designations...
2019-07-02 01:37:04 -07:00
nhmall
d4dc1c1eab Merge branch 'NetHack-3.6.2' 2019-04-09 17:29:28 -04:00
PatR
24d09e64a3 tty blink & dim attributes
Enable blink and dim for the TERMLIB + !NO_TERMS configuration of the
tty interface.  Blink now works the same as in the curses interface
for status highlights.  The terminal emulator I'm using has an escape
sequence for dim but it evidently doesn't do anything (same no effect
as with curses), so that isn't adequately tested.
2019-04-09 13:16:54 -07:00
nhmall
abfd80d3d7 Merge branch 'NetHack-3.6.2' 2019-04-02 12:25:16 -04:00
PatR
d1dade164e tty statuslines:3
Implement the 'statuslines' option for tty.  2 and 3 line status are
similar to curses.  Tty's version doesn't include insertion of extra
spaces for enhanced readability, or ignoring 'showexp' when space is
needed for other fields, or right justifying 'score' and suppressing
it when there isn't room for the entire number.  It continues to have
abbreviated condition and encumbrance descriptions that curses lacks
which get used when the normal ones take up too much space.

'statuslines' can be set with 'O' so it is feasible to switch back
and forth between 2 and 3 lines on the fly.  But only if the display
is at least 25 lines (actually ROWNO+4) or else CLIPPING is enabled
at build time.

This fixes the bug where after resorting to abbreviated condition
values it sometimes (always?) wouldn't switch back after more room
became available.  Abbreviated encumbrance values had problems too
(lack of leading space and not changing value if encumbrance changed
to anything other than unencumbered) and this fixes that as well.
2019-03-29 04:21:18 -07:00
Bart House
b863fad3ea Changes needed in the mac terminal port due to globals changes. 2018-12-22 13:53:10 -08:00
nhmall
cb43061076 curses changes to existing files 2018-11-16 20:51:22 -05:00
Pasi Kallinen
0bb6754998 Fuzz testing debug tool
Add code to run a fuzz tester, simulating (more-or-less) random
keyboard mashing. There's no option to turn it on, you need to
set iflags.debug_fuzzer on via a debugger or something along
those lines.
2018-11-08 15:55:49 +02:00
keni
d8c49ec9d1 Add updated copyright lines, part 1. 2018-04-25 15:00:13 -04:00