-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteraction.py
More file actions
36 lines (29 loc) · 1.01 KB
/
Copy pathinteraction.py
File metadata and controls
36 lines (29 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import queue
import threading
class TerminalUI:
"""
Asynchronous terminal interface.
Lets Dad type while the perception/reasoning loop is running.
"""
def __init__(self) -> None:
self.input_queue: queue.Queue[str] = queue.Queue()
self.listen_thread = threading.Thread(target=self._listen_loop, daemon=True)
self.listen_thread.start()
print("\n[System] Terminal UI activated. Type your message anytime and press Enter.")
def get_and_clear(self) -> str:
messages: list[str] = []
while True:
try:
messages.append(self.input_queue.get_nowait())
except queue.Empty:
break
return "\n".join(messages)
def _listen_loop(self) -> None:
while True:
try:
user_text = input()
except (EOFError, KeyboardInterrupt):
break
clean_text = user_text.strip()
if clean_text:
self.input_queue.put(clean_text)