Chris-plus-alphanumericgibberish / dNAO

Merge of dnethack onto the nethack.alt.org sources.
Other
20 stars 29 forks source link

Add classic_colors, SETCOLOR, and RESETCOLOR options to better handle custom colors in Curses #2270

Closed RikerW closed 3 months ago

RikerW commented 3 months ago

Add classic_colors option for curses to use "classic" nethack colors

This adds an option to ignore terminal color settings and instead default to 'normal' colors as far as nethack is concerned.

This mostly includes specific definitions for yellow (as brown) and bright red (as orange) which are decidedly non-standard for 16 color terminals, and some specific ideas of 'bright' colors as saturated rather than pastel - so cyan is teal and bright cyan is cyan, for example.

This should cleanup & restore fine on terminals that read 16 colors into curses, but has the same extant bug of not resetting the 8 bright colors for some terminals that only read colors 0-7 into curses. There is no clean solution for this, curses does not support one. Noisy suggested a potential solution of adding a RESETCOLOR option to set which color to restore state to, which is probably the best option. I'll probably implement that later.

Add SETCOLOR/RESETCOLOR options for custom-defined colors

Now, you can override certain colors to be your desired colors, and set RESETCOLOR to make up for curses' inability to figure out what your terminal looked like beforehand.

Syntax for both is

RESETCOLOR=lightblue:#00FF99
SETCOLOR=magenta:255 0 180

They accept both hex codes (prefixed with #, should be case insensitive I believe) or a triad of decimal numbers. The decimal numbers are NOT clamped, but are cast to ints immediately (read as longs) and then multiplied by a factor of 1000/255 to turn them into curses-approved colors. Curses handles any OOB numbers - they'll just fail silently. Hex codes physically can't be out of bounds, since they just only look at certain bits. No clue what happens if you try to feed it a number bigger than a C long. I also decided to not allow varying scales for inputs, just use 255 based colors.

The color names are identical to what nethack uses, but accept either light or bright for the brighter versions of each color. Any order will work for these options, you don't need to put any colors before others. Set colors will override terminal default or the classic colors option, and reset colors will override whatever your terminal started with before.

List of color names: (first word is the name, second word is the 'palette name' for the color)

black
red
green
brown (dark yellow)
blue
magenta
cyan
gray (dark white)

orange (bright red)
brightgreen
lightgreen (also bright green)
yellow (bright yellow)
brightblue
lightblue (also bright blue)
brightmagenta
lightmagenta (also bright magenta)
brightcyan
lightcyan (also bright cyan)
white (bright white)

Note that nethack doesn't use 'bright black' for anything, so any attempts to set it will give a bad option message. Redefining the same color, by either a duplicate line with the same color name or another name for the same color (like bright foo & light foo) will use the latter of the wto lines.


Note: none of this does anything for tty. All of this is entirely based around the Curses handling for custom colors - I don't think tty supports that very well, but I personally don't use it and haven't looked at the code, so there's probably a reasonable alternative.