initial commit

This commit is contained in:
2026-03-20 08:55:47 +00:00
commit 17889e56bd
11 changed files with 889 additions and 0 deletions

89
src/vban_tui/tui.py Normal file
View File

@@ -0,0 +1,89 @@
import vban_cmd
from textual.app import App, ComposeResult
from textual.containers import Grid
from textual.widgets import RichLog
from .hybrid import LabelInput
from .settings import Settings
class VbanTui(App):
"""A Textual App to display VBAN data."""
CSS_PATH = 'tui.tcss'
def __init__(self):
super().__init__()
self._settings = Settings()
def compose(self) -> ComposeResult:
"""Create child widgets for the app."""
yield Grid(
LabelInput(
'VBAN Host:',
'localhost',
id='host-labelinput',
label_id='host-label',
input_id='host-input',
),
LabelInput(
'VBAN Port:',
'6980',
id='port-labelinput',
label_id='port-label',
input_id='port-input',
),
LabelInput(
'VBAN Stream Name:',
'Command1',
id='streamname-labelinput',
label_id='streamname-label',
input_id='streamname-input',
),
LabelInput(
'VBAN Command:',
'Enter request',
id='request-labelinput',
label_id='request-label',
input_id='request-input',
),
RichLog(id='response-log'),
id='main-grid',
)
def on_mount(self):
"""Focus the request input on mount."""
self.query_one('#host-input').value = self._settings.host
self.query_one('#port-input').value = str(self._settings.port)
self.query_one('#streamname-input').value = self._settings.streamname
self.query_one('#request-input').focus()
def on_key(self, event):
"""Handle key events."""
match event.key:
case 'q':
self.exit()
case 'enter' if self.query_one('#request-input').has_focus:
self.query_one('#response-log').clear()
request_input = self.query_one('#request-input')
request_input.add_class('request-sent')
self.send_request()
self.set_timer(0.5, lambda: request_input.remove_class('request-sent'))
def send_request(self):
with vban_cmd.api(
'potato',
host=self.query_one('#host-input').value,
port=int(self.query_one('#port-input').value),
streamname=self.query_one('#streamname-input').value,
disable_rt_listeners=True,
) as vban:
if response := vban.sendtext(self.query_one('#request-input').value):
self.query_one('#response-log').write(response)
def main():
"""Run the VBAN TUI application."""
app = VbanTui()
app.run()