feat(console): add core framework - keybindings, navigation, screen base
Add the three core modules that all screens depend on: - keybindings.py: Key constants (curses codes) and KeyBindings registry - navigation.py: Stack-based screen navigation with breadcrumbs - screens.py: Screen base class with on_enter/on_key/render lifecycle Includes 31 tests covering all public APIs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
46
console/core/screens.py
Normal file
46
console/core/screens.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""
|
||||
Base screen class for the console UI.
|
||||
|
||||
Every screen in the application inherits from :class:`Screen` and overrides
|
||||
:meth:`on_enter`, :meth:`on_key`, and :meth:`render`.
|
||||
"""
|
||||
|
||||
|
||||
class Screen:
|
||||
"""Abstract base for all console screens.
|
||||
|
||||
Subclasses must override the three lifecycle methods to provide real
|
||||
behaviour. The base implementations are intentional no-ops so that
|
||||
simple screens (e.g. a static splash page) need not implement every
|
||||
method.
|
||||
|
||||
Attributes:
|
||||
name: Machine-readable identifier used by :class:`Navigation`.
|
||||
title: Human-readable heading displayed at the top of the screen.
|
||||
"""
|
||||
|
||||
def __init__(self, name: str, title: str):
|
||||
self.name = name
|
||||
self.title = title
|
||||
|
||||
def on_enter(self, context, db, renderer) -> None:
|
||||
"""Called once when this screen becomes the active screen.
|
||||
|
||||
Use this hook to load data, reset scroll positions, or set up
|
||||
key bindings specific to the screen.
|
||||
"""
|
||||
|
||||
def on_key(self, key: int, context, db, renderer, nav):
|
||||
"""Handle a single keypress.
|
||||
|
||||
Returns a navigation instruction (e.g. a dict or tuple) when the
|
||||
screen wants to push/pop, or ``None`` to stay on the current
|
||||
screen.
|
||||
"""
|
||||
return None
|
||||
|
||||
def render(self, context, db, renderer) -> None:
|
||||
"""Draw the screen contents using *renderer*.
|
||||
|
||||
Called after every keypress and on initial display.
|
||||
"""
|
||||
Reference in New Issue
Block a user