mirror of
https://github.com/rr-/pq-cli.git
synced 2026-11-12 22:40:36 -07:00
Python 3.10 is the minimum, so annotations use `X | None`, `list[X]` and friends, enforced by ruff's pyupgrade rules. The remaining typing names are imported directly, with abstract types coming from collections.abc. first() is now generic over the item and default.
42 lines
919 B
Python
42 lines
919 B
Python
import curses
|
|
from typing import Any
|
|
|
|
|
|
class Widget:
|
|
def __del__(self) -> None:
|
|
self.stop()
|
|
|
|
def stop(self) -> None:
|
|
pass
|
|
|
|
|
|
class WindowWrapper(Widget):
|
|
def __init__(
|
|
self, parent: Any | None, h: int, w: int, y: int, x: int
|
|
) -> None:
|
|
self._parent = parent
|
|
self._win: Any | None
|
|
|
|
if not parent:
|
|
self._win = None
|
|
else:
|
|
try:
|
|
self._win = parent.derwin(h, w, y, x)
|
|
self._win.noutrefresh()
|
|
except curses.error:
|
|
self._win = None
|
|
|
|
def stop(self) -> None:
|
|
del self._win
|
|
self._win = None
|
|
|
|
def getbegyx(self) -> tuple[int, int]:
|
|
if not self._win:
|
|
return (0, 0)
|
|
return self._win.getbegyx()
|
|
|
|
def getmaxyx(self) -> tuple[int, int]:
|
|
if not self._win:
|
|
return (0, 0)
|
|
return self._win.getmaxyx()
|