Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Fix black color handling #225

Merged
merged 4 commits into from
Jul 22, 2021
Merged

Fix black color handling #225

merged 4 commits into from
Jul 22, 2021

Conversation

heiner
Copy link
Contributor

@heiner heiner commented Jul 22, 2021

Handle black items correctly.

When using ANSI_DEFAULT, hilites[CLR_BLACK] was set as a NULL string. This caused black items to show up as gray. I sent a fix to upstream NetHack at NetHack/NetHack#556.

Fixing that alone doesn't unbreak test_nethack.py::TestNethackTerminalObservation::test_crop (which broke whenever black items were in sight) since CLR_BLACK is 0, not 8 aka bright black (and also NO_COLOR, somewhat confusingly).

We fix this by changing the output of mapglyph for glyphs that aren't the null glyph.

Fixes #198.

Also fix read_tty.py (broken after #217) and simplify test_crop.

Heinrich Kuttler added 3 commits July 22, 2021 10:00
When using ANSI_DEFAULT, hilites[CLR_BLACK] was set as a NULL string.
This caused black items to show up as gray. I sent a fix to upstream
NetHack at NetHack/NetHack#556.

Fixing that alone doesn't unbreak
  test_nethack.py::TestNethackTerminalObservation::test_crop
(which broke whenever black items were in sight) since CLR_BLACK is 0,
not 8 aka bright black (and also NO_COLOR, somewhat confusingly).

We fix this by changing the output of mapglyph for glyphs that aren't
the null glyph.

Fixes #198.
@heiner heiner requested a review from cdmatters July 22, 2021 08:04
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 22, 2021
if (glyph != nul_glyph && color == CLR_BLACK) {
/* This will be 'bright black' (or blue) on tty so we change it to
* make NLE's colors and tty_colors stay compatible. */
color = iflags.wc2_darkgray ? 8 : CLR_BLUE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or CLR_BLUE?!?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will read the termcap fix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NetHack has a configuration option on whether it uses "bright black" (\033[1;30m) or (dark) blue to display black entries: https://github.com/facebookresearch/nle/blob/master/win/tty/termcap.c#L887

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity, here's a Python version of what this code here did before this change:

CLR_BLACK = 0
CLR_RED = 1
CLR_GREEN = 2
CLR_BROWN = 3  # /* on IBM, low-intensity yellow is brown */
CLR_BLUE = 4
CLR_MAGENTA = 5
CLR_CYAN = 6
CLR_GRAY = 7  # /* low-intensity white */
NO_COLOR = 8
CLR_ORANGE = 9
CLR_BRIGHT_GREEN = 10
CLR_YELLOW = 11
CLR_BRIGHT_BLUE = 12
CLR_BRIGHT_MAGENTA = 13
CLR_BRIGHT_CYAN = 14
CLR_WHITE = 15
CLR_MAX = 16

BRIGHT = 8

hilites = [None] * 16

hilites[CLR_GRAY] = ""
hilites[NO_COLOR] = hilites[CLR_GRAY]

for c in range(CLR_MAX // 2):
    if c == CLR_BLACK:
        continue
    hilites[c | BRIGHT] = "\033[1;3%dm" % c
    if c == CLR_GRAY:
        continue
    hilites[c] = "\033[0;3%dm" % c

print(hilites)

src/nle.c Outdated Show resolved Hide resolved
win/tty/termcap.c Show resolved Hide resolved
@heiner heiner merged commit 52df6e4 into master Jul 22, 2021
@heiner heiner deleted the heiner/dev branch July 22, 2021 11:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TestNethackTerminalObservation.test_crop flaky
3 participants