mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
add truecolor tests, remove automatic truecolor greyscale -> xterm256 conversion
This commit is contained in:
parent
71fee0a3ea
commit
0f75e520e0
2 changed files with 40 additions and 24 deletions
|
|
@ -121,27 +121,22 @@ class HexColors:
|
|||
|
||||
r, g, b = self._hex_to_rgb_24_bit(tag)
|
||||
|
||||
# Is it greyscale?
|
||||
if r == g and g == b:
|
||||
return f"{indicator}=" + self._GREYS[self._grey_int(r)]
|
||||
if not truecolor:
|
||||
# Fallback to xterm256 syntax
|
||||
r, g, b = self._rgb_24_bit_to_256(r, g, b)
|
||||
return f"{indicator}{r}{g}{b}"
|
||||
|
||||
else:
|
||||
if not truecolor:
|
||||
# Fallback to xterm256 syntax
|
||||
r, g, b = self._rgb_24_bit_to_256(r, g, b)
|
||||
return f"{indicator}{r}{g}{b}"
|
||||
xtag = f"\033["
|
||||
if "[" in indicator:
|
||||
# Background Color
|
||||
xtag += "4"
|
||||
|
||||
else:
|
||||
xtag = f"\033["
|
||||
if "[" in indicator:
|
||||
# Background Color
|
||||
xtag += "4"
|
||||
xtag += "3"
|
||||
|
||||
else:
|
||||
xtag += "3"
|
||||
|
||||
xtag += f"8;2;{r};{g};{b}m"
|
||||
return xtag
|
||||
xtag += f"8;2;{r};{g};{b}m"
|
||||
return xtag
|
||||
|
||||
def xterm_truecolor_to_html_style(self, fg="", bg="") -> str:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -15,57 +15,78 @@ class TestANSIStringHex(TestCase):
|
|||
def setUp(self):
|
||||
self.str = "test "
|
||||
self.output1 = "\x1b[38;5;16mtest \x1b[0m"
|
||||
self.output1_truecolor = "\x1b[38;2;0;0;0mtest \x1b[0m"
|
||||
self.output2 = "\x1b[48;5;16mtest \x1b[0m"
|
||||
self.output2_truecolor = "\x1b[48;2;0;0;0mtest \x1b[0m"
|
||||
self.output3 = "\x1b[38;5;46mtest \x1b[0m"
|
||||
self.output3_truecolor = "\x1b[38;2;0;255;0mtest \x1b[0m"
|
||||
self.output4 = "\x1b[48;5;46mtest \x1b[0m"
|
||||
self.output4_truecolor = "\x1b[48;2;0;255;0mtest \x1b[0m"
|
||||
|
||||
def test_long_grayscale_fg(self):
|
||||
raw = f"|#000000{self.str}|n"
|
||||
ansi = AN(raw)
|
||||
ansi_256 = parser(raw, xterm256=True)
|
||||
self.assertEqual(ansi.clean(), self.str, "Cleaned")
|
||||
self.assertEqual(ansi.raw(), self.output1, "Output")
|
||||
self.assertEqual(ansi.raw(), self.output1_truecolor, "Output truecolor")
|
||||
self.assertEqual(ansi_256, self.output1, "Output xterm256")
|
||||
|
||||
def test_long_grayscale_bg(self):
|
||||
raw = f"|[#000000{self.str}|n"
|
||||
ansi = AN(raw)
|
||||
ansi_256 = parser(raw, xterm256=True)
|
||||
self.assertEqual(ansi.clean(), self.str, "Cleaned")
|
||||
self.assertEqual(ansi.raw(), self.output2, "Output")
|
||||
self.assertEqual(ansi.raw(), self.output2_truecolor, "Output truecolor")
|
||||
self.assertEqual(ansi_256, self.output2, "Output xterm256")
|
||||
|
||||
def test_short_grayscale_fg(self):
|
||||
raw = f"|#000{self.str}|n"
|
||||
ansi = AN(raw)
|
||||
ansi_256 = parser(raw, xterm256=True)
|
||||
self.assertEqual(ansi.clean(), self.str, "Cleaned")
|
||||
self.assertEqual(ansi.raw(), self.output1, "Output")
|
||||
self.assertEqual(ansi.raw(), self.output1_truecolor, "Output truecolor")
|
||||
self.assertEqual(ansi_256, self.output1, "Output xterm256")
|
||||
|
||||
def test_short_grayscale_bg(self):
|
||||
raw = f"|[#000{self.str}|n"
|
||||
ansi = AN(raw)
|
||||
ansi_256 = parser(raw, xterm256=True)
|
||||
self.assertEqual(ansi.clean(), self.str, "Cleaned")
|
||||
self.assertEqual(ansi.raw(), self.output2, "Output")
|
||||
self.assertEqual(ansi.raw(), self.output2_truecolor, "Output truecolor")
|
||||
self.assertEqual(ansi_256, self.output2, "Output xterm256")
|
||||
|
||||
def test_short_color_fg(self):
|
||||
raw = f"|#0F0{self.str}|n"
|
||||
ansi = AN(raw)
|
||||
ansi_256 = parser(raw, xterm256=True)
|
||||
self.assertEqual(ansi.clean(), self.str, "Cleaned")
|
||||
self.assertEqual(ansi.raw(), self.output3, "Output")
|
||||
self.assertEqual(ansi.raw(), self.output3_truecolor, "Output truecolor")
|
||||
self.assertEqual(ansi_256, self.output3, "Output xterm256")
|
||||
|
||||
def test_short_color_bg(self):
|
||||
raw = f"|[#0f0{self.str}|n"
|
||||
ansi = AN(raw)
|
||||
ansi_256 = parser(raw, xterm256=True)
|
||||
self.assertEqual(ansi.clean(), self.str, "Cleaned")
|
||||
self.assertEqual(ansi.raw(), self.output4, "Output")
|
||||
self.assertEqual(ansi.raw(), self.output4_truecolor, "Output truecolor")
|
||||
self.assertEqual(ansi_256, self.output4, "Output xterm256")
|
||||
|
||||
def test_long_color_fg(self):
|
||||
raw = f"|#00ff00{self.str}|n"
|
||||
ansi = AN(raw)
|
||||
ansi_256 = parser(raw, xterm256=True)
|
||||
self.assertEqual(ansi.clean(), self.str, "Cleaned")
|
||||
self.assertEqual(ansi.raw(), self.output3, "Output")
|
||||
self.assertEqual(ansi.raw(), self.output3_truecolor, "Output truecolor")
|
||||
self.assertEqual(ansi_256, self.output3, "Output xterm256")
|
||||
|
||||
def test_long_color_bg(self):
|
||||
raw = f"|[#00FF00{self.str}|n"
|
||||
ansi = AN(raw)
|
||||
ansi_256 = parser(raw, xterm256=True)
|
||||
self.assertEqual(ansi.clean(), self.str, "Cleaned")
|
||||
self.assertEqual(ansi.raw(), self.output4, "Output")
|
||||
self.assertEqual(ansi.raw(), self.output4_truecolor, "Output truecolor")
|
||||
self.assertEqual(ansi_256, self.output4, "Output xterm256")
|
||||
|
||||
|
||||
|
||||
class TestANSIParser(TestCase):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue