- macOS, Linux badge and AI suggestions showcase in README - Update user guide and docs for development
2.0 KiB
2.0 KiB
Iris central integration & event loop (root/)
The root package is the entry point and orchestration layer of Iris, handling low-level terminal PTY manipulation and the main interaction loop.
How it works
- PTY wrapper: Starts a pseudoterminal (PTY) wrapping the user's shell (
zsh,bash, orfish). Shell is selected via--shellflag, config, or auto-detected by walking/proc/<pid>/commup the parent process tree, falling back to$SHELL, and ultimately defaulting tobashif nothing matches. - IO interception: Runs two pumps:
- Output pump: Forwards shell output to terminal screen via synchronized
TermWrite. - Input pump: Listens to keystrokes in raw mode, tracks typed characters in
naiveBuffer, and triggers suggestion rendering.
- Output pump: Forwards shell output to terminal screen via synchronized
- State management: Tracks active completion mode (
specvshistory). Shell-specific IPC hooks (preexec/precmdfor zsh,PROMPT_COMMANDfor bash,fish_postexecfor fish) signal command boundaries viaIRIS_CMD_STOP.
Key components
root/wrapper.go
Contains the core PTY loop:
- Sets terminal to raw mode to intercept keys like
Tab,Esc, orCtrl+C. - Manages
naiveBufferstring tracking prompt input state. - Handles suggestion insertion when pressing
TaborEnter.
root/term_sync.go
Provides TermWrite, a thread-safe stdout wrapper using sync.Mutex to prevent screen garbling when shell output and overlay rendering overlap.
Example flow
- User types
g. rootcapturesg, appends tonaiveBuffer.rootcallsrenderOverlay().renderOverlaycallsLookup("g").overlayrenders suggestions box.- User presses
Tab. rootinserts completion into prompt buffer.
Hot-reload
Iris includes an atomic hot-reload mechanism for rapid local development:
- Signal listener: The root process listens for
SIGUSR1. - Process replace: Uses
syscall.Execto replace the running binary in-place without killing the underlying PTY shell session.