Skip to content

Commit

Permalink
feat: add attron, attroff, and attrset
Browse files Browse the repository at this point in the history
  • Loading branch information
mecaneer23 committed Jun 19, 2024
1 parent 836742e commit af31554
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/acurses.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ def __init__(

self._keypad: bool = False

self._attrs = 0

def getch(self) -> int:
"""
Get a character. Note that the integer returned
Expand Down Expand Up @@ -201,7 +203,7 @@ def move(self, new_y: int, new_x: int) -> None:
def _parse_attrs(self, attrs: int) -> str:
"""Convert a binary `attrs` into ANSI escape codes"""
output = ""
iattrs = bin(attrs)[2:]
iattrs = bin(attrs | self._attrs)[2:]
background = 0
for ansi_code in compress(count(len(iattrs) - 1, -1), map(int, iattrs)):
if ansi_code // 10 == 4:
Expand Down Expand Up @@ -329,6 +331,27 @@ def keypad(self, flag: bool = False) -> None:
"""
self._keypad = flag

def attron(self, attr: int) -> None:
"""
Add attribute attr from the “background” set
applied to all writes to the current window.
"""
self._attrs |= attr

def attroff(self, attr: int) -> None:
"""
Remove attribute attr from the “background” set
applied to all writes to the current window.
"""
self._attrs ^= attr

def attrset(self, attr: int) -> None:
"""
Set the “background” set of attributes to attr.
This set is initially 0 (no attributes).
"""
self._attrs = attr


def use_default_colors() -> None:
"""Allow using default colors. Not yet implemented."""
Expand Down

0 comments on commit af31554

Please sign in to comment.