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

Commit 36f4ee7

Browse files
committed
Add notebook rendering style, that sets background as black.
1 parent fc2483a commit 36f4ee7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

nle/env/base.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,15 @@ def get_seeds(self):
525525
"""
526526
return self.env.get_current_seeds()
527527

528-
def get_tty_rendering(self, tty_chars, tty_colors):
528+
def get_tty_rendering(self, tty_chars, tty_colors, set_background=False):
529529
# TODO: Merge with "full" rendering below. Why do we have both?
530+
ansi_code = "\033[%d;3%d;40m%s" if set_background else "\033[%d;3%dm%s"
530531
rows, cols = tty_chars.shape
531532
result = ""
532533
for i in range(rows):
533534
line = "\n"
534535
for j in range(cols):
535-
line += "\033[%d;3%dm%s" % (
536+
line += ansi_code % (
536537
bool(tty_colors[i, j] & TTY_BRIGHT),
537538
tty_colors[i, j] & ~TTY_BRIGHT,
538539
chr(tty_chars[i, j]),
@@ -543,13 +544,14 @@ def get_tty_rendering(self, tty_chars, tty_colors):
543544
def render(self, mode="human"):
544545
"""Renders the state of the environment."""
545546
chars_index = self._observation_keys.index("chars")
546-
if mode == "human":
547+
if mode == "human" or mode == "notebook":
548+
set_background = mode == "notebook"
547549
obs = self.last_observation
548550
tty_chars_index = self._observation_keys.index("tty_chars")
549551
tty_colors_index = self._observation_keys.index("tty_colors")
550552
tty_chars = obs[tty_chars_index]
551553
tty_colors = obs[tty_colors_index]
552-
rendering = self.get_tty_rendering(tty_chars, tty_colors)
554+
rendering = self.get_tty_rendering(tty_chars, tty_colors, set_background)
553555
print(rendering)
554556
return
555557
elif mode == "full":

0 commit comments

Comments
 (0)