From 4066dccc9dfa854d50fbb6fd7dfb8a7b010f6561 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 23 Dec 2024 14:03:09 +1100 Subject: [PATCH] Implement setting custom colours by number --- pyte/screens.py | 13 +++++++++++++ pyte/streams.py | 3 +++ 2 files changed, 16 insertions(+) diff --git a/pyte/screens.py b/pyte/screens.py index ebbac7c..9404251 100644 --- a/pyte/screens.py +++ b/pyte/screens.py @@ -544,6 +544,19 @@ def set_icon_name(self, param: str) -> None: """ self.icon_name = param + def set_color_number(self, index: int, color: str) -> None: + """Set colour number index to be the specified colour (in hex) + """ + # TODO: This has no way to reset colors back to their original. + if index > 15: + g.FG_BG_256[index] = color + elif index > 7: # Bright colors + g.FG_AIXTERM[index + 82] = color + g.BG_AIXTERM[index + 92] = color + else: + g.FG_ANSI[index + 30] = color + g.BG_ANSI[index + 40] = color + def carriage_return(self) -> None: """Move the cursor to the beginning of the current line.""" self.cursor.x = 0 diff --git a/pyte/streams.py b/pyte/streams.py index cd0f51c..54e9152 100644 --- a/pyte/streams.py +++ b/pyte/streams.py @@ -376,6 +376,9 @@ def create_dispatcher(mapping: Mapping[str, str]) -> Dict[str, Callable[..., Non listener.set_icon_name(param) if code in "02": listener.set_title(param) + if code == "4": + index, color = param.split(";") + listener.set_color_number(int(index), color[4:].replace("/", "").lower()) elif char not in NUL_OR_DEL: draw(char)