Skip to content

Commit

Permalink
Implement setting custom colours by number
Browse files Browse the repository at this point in the history
  • Loading branch information
Moult committed Dec 23, 2024
1 parent 636b679 commit 4066dcc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pyte/screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pyte/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 4066dcc

Please sign in to comment.