From e3a367ba7e35370c4fb12afca4742c5b980bec1d Mon Sep 17 00:00:00 2001 From: Mecaneer23 <74385377+Mecaneer23@users.noreply.github.com> Date: Wed, 17 Apr 2024 20:58:47 -0500 Subject: [PATCH] refactor: write characters to screen one at a time. While this seems like it would decrease performance, the python file.write method is buffered, so it shouldn't make a difference --- src/acurses.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/acurses.py b/src/acurses.py index e904f32..649bbab 100644 --- a/src/acurses.py +++ b/src/acurses.py @@ -147,9 +147,11 @@ def addstr(self, *args: Any, **kwargs: Any) -> None: @_addstr.register(str) def _(self, text: str, attr: int = 0) -> None: ansi_attrs = self._parse_attrs(attr) - stdout.write( - f"{ansi_attrs}{text[:self._width]}{_ANSI_RESET if ansi_attrs else ''}" - ) + stdout.write(ansi_attrs) + for char in text[:self._width]: + stdout.write(char) + if ansi_attrs: + stdout.write(_ANSI_RESET) stdout.flush() @_addstr.register(int)