Skip to content

Commit

Permalink
Add support for TUI applications
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Sep 6, 2023
1 parent fd81f4e commit 6ed329b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ clean: $(PY_PREFIX)clean $(DZ_PREFIX)clean
s:
./venv$(PYTHON_VERSION)/bin/runtimepy arbiter --curses \
./local/arbiter/test.yaml
+@echo "success"
13 changes: 12 additions & 1 deletion local/arbiter/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,18 @@ async def noop2(app: AppInfo) -> int:
async def gui(app: AppInfo) -> int:
"""Run a channel GUI for application connections."""

print(app)
window = app.tui.window
while not app.stop.is_set():
data = window.getch()
if data != -1 and not await app.tui.handle_char(data):
# trigger this with 'q'
app.stop.set()

# do stuff

# make this updating a task
app.tui.tui_update()
await asyncio.sleep(0.1)

return 0

Expand Down
2 changes: 1 addition & 1 deletion local/arbiter/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ tasks:

app:
# - [tasks.test, tasks.noop1, tasks.noop2]
- tasks.noop1
- tasks.gui
1 change: 1 addition & 0 deletions runtimepy/net/arbiter/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ async def _entry(
self._namespace,
self.stop_sig,
config if config is not None else self._config,
self,
)

# Initialize tasks.
Expand Down
4 changes: 4 additions & 0 deletions runtimepy/net/arbiter/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

# internal
from runtimepy.net.connection import Connection as _Connection
from runtimepy.tui.mixin import TuiMixin

ConnectionMap = _MutableMapping[str, _Connection]
T = _TypeVar("T", bound=_Connection)
Expand Down Expand Up @@ -48,6 +49,8 @@ class AppInfo:
# Configuration data that may be specified in a configuration file.
config: _JsonObject

tui: TuiMixin

def with_new_logger(self, name: str) -> "AppInfo":
"""Get a copy of this AppInfo instance, but with a new logger."""

Expand All @@ -58,6 +61,7 @@ def with_new_logger(self, name: str) -> "AppInfo":
self.names,
self.stop,
self.config,
self.tui,
)

def search(
Expand Down

0 comments on commit 6ed329b

Please sign in to comment.