2.2 KiB
2.2 KiB
IRIS: Central Integration & Event Loop (root/)
The root package is the entry point and the orchestration layer of IRIS. It handles the low-level terminal manipulation and the main interaction loop.
How it works
- PTY Wrapper: When you run
iris, it starts a Pseudo-Terminal (PTY) and launchesbashinside it. - IO Interception: It creates two "pumps":
- Output Pump: Forwards everything from Bash to your screen using
TermWrite(synchronized to prevent UI glitches). - Input Pump: Listens to your keyboard. If it detects you are typing a command, it records it in a
naiveBufferand triggers the suggestion engine.
- Output Pump: Forwards everything from Bash to your screen using
- State Management: It tracks whether you are in
specmode (command suggestions) orhistorymode (Ctrl+R).
Key Components
root.go
Contains the runWrapper() function which:
- Sets the terminal to Raw Mode so Iris can capture keys like
Tab,Esc, orCtrl+Cbefore the shell does. - Manages the
naiveBuffer: a string that tracks exactly what you see on your prompt. - Handles Selection Logic: When you press
Tab, it modifies the Bash line using theCtrl+U(clear line) +selected commandsequence.
term_sync.go
Provides TermWrite, a thread-safe wrapper around os.Stdout. It uses a sync.Mutex to ensure that if Bash and the Iris Overlay try to write at the exact same millisecond, the output doesn't get garbled.
Example Flow
- User types
g. rootcapturesg, appends tonaiveBuffer.rootcallsrenderOverlay().renderOverlaycallsLookup("g").overlayrenders the resultgit.- User presses
Tab. rootsendsCtrl+Uto Bash, then sendsgit(the completion).
Hot-Reload
IRIS features an Atomic Hot-Reload mechanism designed for rapid development:
- Signal Listener: The root process listens for
SIGUSR1. - Identity Exposure: It exports
IRIS_PIDto the environment so child processes knows where to send the signal. - In-place Replacement: Upon receiving the signal, Iris uses
syscall.Execto replace its current process image with the newly built binary. - Handoff Notification: It uses
IRIS_RELOADEDto notify the new instance to announce its successful load.