Skip to content

Commit

Permalink
Various: Solidify behaviour across similar methods
Browse files Browse the repository at this point in the history
This includes:

- Always writing to `terminal` in ansi_interface, not directly to
  stdout.
- Passing along all `**kwargs` in the printer returned by `cursor_at`
  • Loading branch information
bczsalba committed Jul 31, 2022
1 parent 5a2ec6b commit 9e5e708
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
8 changes: 4 additions & 4 deletions pytermgui/ansi_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ def clear(what: str = "screen") -> None:
def hide_cursor() -> None:
"""Stops printing the cursor."""

print("\x1b[?25l")
terminal.write("\x1b[?25l")


def show_cursor() -> None:
"""Starts printing the cursor."""

print("\x1b[?25h")
terminal.write("\x1b[?25h")


def save_cursor() -> None:
Expand Down Expand Up @@ -165,7 +165,7 @@ def report_cursor() -> tuple[int, int] | None:
`report_mouse` if that is what you are interested in.
"""

print("\x1b[6n")
terminal.write("\x1b[6n", flush=True)
chars = getch()
posy, posx = chars[2:-1].split(";")

Expand Down Expand Up @@ -617,7 +617,7 @@ def print_to(pos: tuple[int, int], *args: Any, **kwargs: Any) -> None:
"""

move_cursor(pos)
print(*args, **kwargs, end="", flush=True)
print(*args, **kwargs)


def reset() -> str:
Expand Down
4 changes: 2 additions & 2 deletions pytermgui/context_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ def cursor_at(pos: tuple[int, int]) -> Generator[Callable[..., None], None, None
offset = 0
posx, posy = pos

def printer(*args: tuple[Any, ...]) -> None:
def printer(*args: Any, **kwargs: Any) -> None:
"""Print to posx, current y"""

nonlocal offset

print_to((posx, posy + offset), *args)
print_to((posx, posy + offset), *args, **kwargs)
offset += 1

try:
Expand Down
5 changes: 0 additions & 5 deletions pytermgui/widgets/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,8 +1058,3 @@ def get_lines(self) -> list[str]:

self.height = max(widget.height for widget in self)
return lines

def debug(self) -> str:
"""Return identifiable information"""

return super().debug().replace("Container", "Splitter", 1)
2 changes: 1 addition & 1 deletion pytermgui/widgets/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __call__(self, item: str) -> str:
# this is purposefully broad, as anything can happen during these calls.
except Exception as error:
raise RuntimeError(
f'Could not apply style {self.method} to "{item}": {error}' # type: ignore
f"Could not apply style {self.method} to {item!r}: {error}" # type: ignore
) from error

def __eq__(self, other: object) -> bool:
Expand Down

0 comments on commit 9e5e708

Please sign in to comment.