Skip to content

PTY event loop: connect all session components#49

Merged
andreahlert merged 2 commits intomainfrom
feat/pty-event-loop
Mar 26, 2026
Merged

PTY event loop: connect all session components#49
andreahlert merged 2 commits intomainfrom
feat/pty-event-loop

Conversation

@andreahlert
Copy link
Copy Markdown
Contributor

Summary

The core event loop that connects PTY, keys, OSC, popup, and async IPC into a working session.

  • tabra session now spawns a real shell inside a PTY wrapper
  • Arrow keys, Tab, Escape intercepted by the session (not readline)
  • Popup rendered directly to real terminal via ANSI escape sequences
  • Auto-starts daemon if not running
  • Raw mode with scopeguard restoration

Issues

Closes #45

Test plan

  • 36 tests pass (19 session + 6 lib + 11 integration)
  • CI green
  • Manual: cargo run -- session drops into a working bash shell

Event loop (session/event_loop.rs):
- stdin reader: raw bytes → KeyEvent → PopupState → forward/show/erase
- PTY reader: blocking thread → channel → OscParser → strip OSC + passthrough
- PTY writer: channel → blocking write to master fd
- Terminal writer: blocking thread with stdout lock → passthrough + popup
- SIGWINCH handler: resize PTY + update popup cols
- Escape timeout: 10ms disambiguates standalone ESC from sequences
- Accept: Ctrl-A + Ctrl-K + retype via PTY master (readline-compatible)

Session entry (session/mod.rs):
- Auto-starts daemon if not running
- Writes integration script to temp file
- Spawns shell via PTY with --rcfile
- Enables raw mode with scopeguard restoration
- Runs event loop via tokio runtime
- Cleans up temp files on exit

popup.rs: Made popup_lines field pub for event loop access

Closes #45

Signed-off-by: André Ahlert <andre@aex.partners>
- Await stdin_task, sigwinch_task, pty_writer_task after abort()
  to ensure they've stopped before master fd is closed
- Remove mem::forget(master): OwnedFd drop is the intended single
  close point (both threads already mem::forget their File copies)
- Prevents use-after-close on master fd during SIGWINCH or mid-write

Signed-off-by: André Ahlert <andre@aex.partners>
@andreahlert andreahlert merged commit 9492e11 into main Mar 26, 2026
5 checks passed
@andreahlert andreahlert deleted the feat/pty-event-loop branch March 26, 2026 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PTY wrapper: async event loop (stdin + PTY + SIGWINCH)

1 participant