Skip to content

Commit

Permalink
refactor: only ansi reset if something was changed
Browse files Browse the repository at this point in the history
  • Loading branch information
mecaneer23 committed Apr 18, 2024
1 parent 60bfee2 commit 0d9a107
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/acurses.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def getch(self) -> int:

def move(self, new_y: int, new_x: int) -> None:
"""Move cursor to (new_y, new_x)"""
stdout.write(f"\033[{self._begin_y + new_y + 1};{self._begin_x + new_x + 1}H")
stdout.write(f"\033[{self._begin_y + new_y + 1};{self._begin_x + new_x + 3}H")

def _parse_attrs(self, attrs: int) -> str:
"""Convert a binary `attrs` into ANSI escape codes"""
Expand Down Expand Up @@ -133,7 +133,8 @@ def addstr(self, *args: Any, **kwargs: Any) -> None:
@_addstr.register(str)
def _(self, text: str, attr: int = 0, _: None = None, __: None = None) -> None:
_ = __
stdout.write(f"{self._parse_attrs(attr)}{text}{_ANSI_RESET}")
ansi_attrs = self._parse_attrs(attr)
stdout.write(f"{ansi_attrs}{text}{_ANSI_RESET if ansi_attrs else ''}")
stdout.flush()

@_addstr.register(int)
Expand Down

0 comments on commit 0d9a107

Please sign in to comment.