From 1848cb72cde18aab9645dca07c60f0ebaf7209a5 Mon Sep 17 00:00:00 2001 From: acki Date: Mon, 10 Nov 2025 18:14:17 +0100 Subject: [PATCH] test serial read/write --- simulated_pcb/odo_serial.test.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/simulated_pcb/odo_serial.test.py b/simulated_pcb/odo_serial.test.py index 27b1c2d..97f8458 100644 --- a/simulated_pcb/odo_serial.test.py +++ b/simulated_pcb/odo_serial.test.py @@ -32,6 +32,7 @@ def curses_main(stdscr): log_lines = [] log_lock = threading.Lock() + cmd_history = [] with serial.Serial(SERIAL_PORT, BAUDRATE, timeout=1) as ser: time.sleep(2) @@ -43,15 +44,25 @@ def curses_main(stdscr): while True: stdscr.clear() h, w = stdscr.getmaxyx() + + # Split screen horizontally (80% logs, 20% history) + split_x = int(w * 0.7) log_height = h - 2 - # Display log lines + # --- Left panel: logs --- with log_lock: visible_logs = log_lines[-log_height:] for i, line in enumerate(visible_logs): - stdscr.addnstr(i, 0, line, w - 1) + stdscr.addnstr(i, 0, line, split_x - 1) - # Input line + # --- Right panel: command history --- + stdscr.vline(0, split_x, "|", log_height) + history_start_x = split_x + 2 + stdscr.addstr(0, history_start_x, "Historique des commandes:") + for i, cmd in enumerate(reversed(cmd_history[-(log_height - 2):])): + stdscr.addnstr(i + 1, history_start_x, cmd, w - history_start_x - 1) + + # --- Input line --- stdscr.addstr(log_height, 0, "-" * (w - 1)) stdscr.addstr(log_height + 1, 0, f"Commande >>> {user_input}") stdscr.refresh() @@ -64,7 +75,7 @@ def curses_main(stdscr): if ch is None: continue - # Handle input + # Handle key input if isinstance(ch, str): if ch in ("\n", "\r"): cmd = user_input.strip() @@ -73,8 +84,9 @@ def curses_main(stdscr): break if cmd: ser.write((cmd + "\n").encode()) + cmd_history.append(cmd) user_input = "" - elif ch in ("\b", "\x7f"): # Backspace compatibility + elif ch in ("\b", "\x7f"): user_input = user_input[:-1] elif ch.isprintable(): user_input += ch