This commit is contained in:
Sophia S 2026-06-03 11:13:45 +02:00
commit d0a67d5a18
4 changed files with 303 additions and 70 deletions

View file

@ -5,10 +5,16 @@ haTerm - v0.1
haTerm is a Terminal Based hafas client, using the ivb endpoint.
Prompt_toolkit (https://github.com/prompt-toolkit/python-prompt-toolkit) will be used to render a terminal user interface (TUI).
The application will provide routing information and station departures/arrivals.
"""
#routenplanung mit promt tool kit
import prompt_toolkit as pk
Route planning UI.
Wrapped in a function so it can be launched from `main.py` with a shared
`HafasClient` instance from `backend.py`.
Note: This module is a minimal TUI stub. Many features are not implemented
yet (station lookup, route rendering). Add TODOs where appropriate.
"""
import time
from prompt_toolkit import Application
from prompt_toolkit.buffer import Buffer
@ -21,45 +27,57 @@ from prompt_toolkit.shortcuts import yes_no_dialog
from prompt_toolkit.shortcuts import input_dialog
from prompt_toolkit import prompt
kb = KeyBindings()
import backend
start = prompt("Start: ")
end = prompt("Ende: ")
def run_route_planning(hafas: backend.HafasClient | None = None):
"""Run the route planning TUI.
Parameters:
- hafas: optional shared HafasClient instance. If omitted, a new one is
created. Prefer passing the shared client from `main.py`.
"""
if hafas is None:
hafas = backend.HafasClient()
# TODO: integrate actual station search + routing using `hafas`.
kb = KeyBindings()
start = prompt("Start: ")
end = prompt("Ende: ")
startBuffer = Buffer()
startBuffer.text = start
startBuffer = Buffer()
startBuffer.text = start
etdBuffer = Buffer()
etdBuffer.text = "13:00" #testweise, später mit tatsächlicher Abfahrtszeit von Hafas ersetzen
#etdBuffer.text = (ungefähre abfahrtszeit)
etdBuffer = Buffer()
etdBuffer.text = "13:00" #testweise, später mit tatsächlicher Abfahrtszeit von Hafas ersetzen
#etdBuffer.text = (ungefähre abfahrtszeit)
endBuffer = Buffer()
endBuffer.text = end
endBuffer = Buffer()
endBuffer.text = end
etaBuffer = Buffer()
etaBuffer.text = "13:45" #testweise, später mit tatsächlicher Ankunftszeit von Hafas ersetzen
#etaBuffer.text = (ungefähre ankunftszeit)
etaBuffer = Buffer()
etaBuffer.text = "13:45" #testweise, später mit tatsächlicher Ankunftszeit von Hafas ersetzen
#etaBuffer.text = (ungefähre ankunftszeit)
drivetimeBuffer = Buffer()
#drivetimeBuffer.text = Fahrzeit von Hafas.
drivetimeBuffer = Buffer()
#drivetimeBuffer.text = Fahrzeit von Hafas.
infoBuffer = Buffer()
infoBuffer.text = f"Routenplanung von {start} nach {end}"
root_container = HSplit(children=[
infoBuffer = Buffer()
infoBuffer.text = f"Routenplanung von {start} nach {end}"
root_container = HSplit(children=[
HSplit(children=[
Window(height=2, content=BufferControl(buffer=infoBuffer, focusable=False), style="fg:#2A71D5"), #informationen über Route
Window(width=1, height = 1, char='-', style="fg:#2A71D5"), #Trennlinie
Window(content=BufferControl(buffer=startBuffer, focusable=True)), #start Station
Window(content=BufferControl(buffer=etdBuffer, focusable=False)), #abfahrtszeit
Window(width = 1, height = 2, char= ".", style= "fg:#A86FD6"), #Trennlinie
@ -70,24 +88,27 @@ root_container = HSplit(children=[
#Window(content=BufferControl(buffer=drivetimeBuffer, focusable=False)),
#Window(Content)
]),
Window(height=1, char=' ', style="bg:#2A71D5 fg:black"),
#Window(content=BufferControl(buffer=userBuffer),height=4),
])
]),
Window(height=1, char=' ', style="bg:#2A71D5 fg:black"),
])
@kb.add('c-e')
def _(event):
result = yes_no_dialog(
title='Programm beenden',
text='Fenster schließen?').run()
if result == True:
event.app.exit()
@kb.add('c-e')
def _(event):
result = yes_no_dialog(
title='Programm beenden',
text='Fenster schließen?').run()
if result == True:
event.app.exit()
layout = Layout(root_container)
layout = Layout(root_container)
app = Application(layout=layout, key_bindings=kb, full_screen=True)
app = Application(layout=layout, key_bindings=kb, full_screen=True)
try:
app.run()
except KeyboardInterrupt:
# graceful exit on Ctrl-C
return
app.run()