Merge branch 'main' of https://git.miaig.dev/mia/hafas-terminal-app
This commit is contained in:
commit
ee6082bf25
1 changed files with 52 additions and 24 deletions
|
|
@ -31,48 +31,76 @@ def run_station_monitor(hafas: backend.HafasClient | None = None):
|
|||
hafas = backend.HafasClient()
|
||||
|
||||
keyB = KeyBindings()
|
||||
inputBuffer = Buffer()
|
||||
resultBuffer = Buffer()
|
||||
|
||||
prefixBuffer = Buffer()
|
||||
prefixBuffer.text = "Haltestelle eingeben: "
|
||||
prefixBuffer.read_only = True
|
||||
|
||||
userinputBuffer = Buffer()
|
||||
|
||||
arrivalBuffer = Buffer()
|
||||
departureBuffer = Buffer()
|
||||
stop_event = threading.Event()
|
||||
app_state = "MONITOR"
|
||||
|
||||
inputBuffer.text = "Haltestelle eingeben: "
|
||||
inputBuffer.cursor_position = len(inputBuffer.text)
|
||||
resultBuffer.text = "Ausgabe: "
|
||||
arrivalBuffer.text = "Ankünfte:\n"
|
||||
departureBuffer.text = "Abfahrten:\n"
|
||||
|
||||
|
||||
|
||||
root_container = HSplit(children=[
|
||||
VSplit(children=[
|
||||
Window(content=BufferControl(buffer=inputBuffer, focusable=True)),
|
||||
Window(content=BufferControl(buffer=prefixBuffer, focusable=False),width=22),
|
||||
Window(content=BufferControl(buffer=userinputBuffer, focusable=True)),
|
||||
Window(width=1, char='│', style="fg:#9D1D75"),
|
||||
Window(content=BufferControl(buffer=resultBuffer, focusable=True)),
|
||||
|
||||
HSplit(children=[
|
||||
Window(content=BufferControl(buffer=arrivalBuffer, focusable=True)),
|
||||
Window(height=1, char='-', style="fg:#9D1D75"),
|
||||
Window(content=BufferControl(buffer=departureBuffer, focusable=True)),
|
||||
]),
|
||||
]),
|
||||
Window(height=1, char='-', style="bg:#9D1D75 fg:#FFFFFF"),
|
||||
])
|
||||
|
||||
layout = Layout(root_container, focused_element=inputBuffer)
|
||||
layout = Layout(root_container, focused_element=userinputBuffer)
|
||||
|
||||
@keyB.add("enter")
|
||||
def handle_enter(event):
|
||||
global app_state
|
||||
|
||||
user_input = inputBuffer.text.replace("Haltestelle eingeben: ", "").strip()
|
||||
user_input = userinputBuffer.text.strip()
|
||||
|
||||
if user_input:
|
||||
app_state = "RESULTS"
|
||||
# TODO: handle case of no results gracefully
|
||||
results = hafas.getStationNames(user_input)
|
||||
inputBuffer.insert_line_below()
|
||||
for station in results:
|
||||
inputBuffer.insert_text(f"\n {station[0]}")
|
||||
resultBuffer.text = f"Ergebnisse für: {results[0][1]}\n\n"
|
||||
station = results[0][1] if results else "Keine Ergebnisse gefunden."
|
||||
departures = hafas.getArrDep(station, arrdep="ARR", count=3)
|
||||
resultBuffer.text = "\n".join(
|
||||
[resultBuffer.text.rstrip()] + [f" {entry['departure_time']} {entry['line']} {entry['name']}" for entry in departures]
|
||||
)
|
||||
if user_input:
|
||||
app_state = "RESULTS"
|
||||
results = hafas.getStationNames(user_input)
|
||||
|
||||
if not results:
|
||||
arrivalBuffer.text = f"Keine Stationen gefunden für: {user_input}"
|
||||
departureBuffer.text= ""
|
||||
userinputBuffer.text=""
|
||||
app_state = "MONITOR"
|
||||
|
||||
else:
|
||||
app_state = "MONITOR"
|
||||
station_name = results[0][1]
|
||||
station_id = results[0][0]
|
||||
|
||||
arrivals = hafas.getArrDep(station_id, arrdep="ARR", count=3)
|
||||
arrivalBuffer.text = f"Ankünfte für {station_name}:\n"
|
||||
for arrival in arrivals:
|
||||
arrivalBuffer.insert_text(f"\n {arrival}")
|
||||
|
||||
departures = hafas.getArrDep(station_id, arrdep="DEP", count=3)
|
||||
departureBuffer.text = f"Abfahrten für {station_name}:\n"
|
||||
for departure in departures:
|
||||
departureBuffer.insert_text(f"\n {departure}")
|
||||
|
||||
|
||||
userinputBuffer.text = ""
|
||||
|
||||
else:
|
||||
app_state = "MONITOR"
|
||||
|
||||
|
||||
@keyB.add("c-q")
|
||||
def exit_(event):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue