mirror of
https://github.com/rr-/pq-cli.git
synced 2026-11-12 22:40:36 -07:00
The main loop slept 100 ms whenever no key was pending, so keys took up to a tick to register and every screen woke ten times a second. Each view now declares how often it needs idle(): the game view keeps its 100 ms tick, while menus wait for a key. getch() blocks for that long, so keys register at once, and over 15 s in the roster menu the process goes from about 300 wake-ups to 6.
22 lines
405 B
Python
22 lines
405 B
Python
import curses
|
|
|
|
|
|
class BaseView:
|
|
# How often idle() runs, in milliseconds; None waits for a key.
|
|
idle_interval: int | None = None
|
|
|
|
def __init__(self, screen: curses.window) -> None:
|
|
self.screen = screen
|
|
|
|
def start(self) -> None:
|
|
pass
|
|
|
|
def stop(self) -> None:
|
|
pass
|
|
|
|
def idle(self) -> None:
|
|
pass
|
|
|
|
def keypress(self, key: int) -> None:
|
|
pass
|