Created
September 22, 2022 09:25
-
-
Save davep/4b8936e3a1d5da6ba1cdc230f8ca3205 to your computer and use it in GitHub Desktop.
Function to turn a MS/PC-DOS colour code into a Rich colour style markup string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rich_dos_colour( color: int ) -> str: | |
"""Convert a MS/PC-DOS colour attribute to Rich style text. | |
:param int colour: The MS/PC-DOS colour attribute. | |
:returns: A Rich BBCode-style markup string for the colour. | |
:rtype: str | |
""" | |
assert 0 <= color <= 0xFF, "DOS colour codes must be 0 to 255 inclusive" | |
return "[color({}) on color({})]".format( | |
*reversed( divmod( color, 0x10 ) ) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turns out, this doesn't quite work because the colour numbers used by Rich don't map to those used by 8bit DOS.