make readline_wrap a staticmethod

This commit is contained in:
Jeffrey C. Ollie 2023-10-29 17:02:35 -05:00
parent 78090e80b9
commit a463c62d69
Signed by: jeff
GPG key ID: 6F86035A6D97044E

View file

@ -39,21 +39,6 @@ def check_annotations(func: Callable) -> Callable:
return wrapped
def readline_wrap(func: Callable) -> Callable:
"""wrap output in SOH/STX so that readline handles prompts properly"""
@wraps(func)
def wrapped(ansi: ANSI, *args, **kwargs):
result = ""
if ansi.readline_wrap:
result += ansi.SOH
result += func(ansi, *args, **kwargs)
if ansi.readline_wrap:
result += ansi.STX
return wrapped
class Mode(Enum):
C0 = auto()
C1 = auto()
@ -191,6 +176,21 @@ class ANSI:
mode: Mode
wrap: bool
@staticmethod
def readline_wrap(func: Callable) -> Callable:
"""wrap output in SOH/STX so that readline handles prompts properly"""
@wraps(func)
def wrapped(ansi: Self, *args, **kwargs):
result = ""
if ansi.wrap:
result += ansi.SOH
result += func(ansi, *args, **kwargs)
if ansi.wrap:
result += ansi.STX
return wrapped
def __init__(self: Self, mode: Mode = Mode.C0, wrap: bool = False) -> None:
self.mode = mode
self.wrap = wrap