The Interactive Chat Shell
NERVI's interactive shell (nervi run) uses advanced ANSI terminal escape codes and platform-specific window queries to construct a clean, double-line chat interface resembling modern IDE consoles.
📌 Pinned Status Bar (Viewport Isolation)
Standard terminal output scrolls everything upwards, causing persistent status bars to replicate and leave duplicate lines in your scrollback history. NERVI avoids this by partitioning the console viewport into a scroll region and a locked status region.
Scroll Region Partitioning
On launching the shell:
- NERVI queries the terminal height.
- It sends the ANSI escape code
\033[1;<height-1>r. This instructs the terminal emulator to restrict standard scrolling to rows1throughheight-1. - The bottom row (
height) is locked. NERVI positions the cursor at\033[<height>;1H, clears the row (\033[2K), and draws the status bar. - On exit, NERVI sends
\033[rto reset the scroll region boundaries back to the full window.
🔄 Inline Thinking Spinner
When generating responses (especially with reasoning models that output early <think> tokens), the CLI manages an inline amber spinner:
▣ Chat · model-name · ⠋ Thinking
Transition to Telemetry
- During the "thinking" stage, the spinner rotates on the active line.
- Once the first non-thinking token arrives, the spinner is erased using ANSI cursor back-movement codes.
- Upon generation completion, the total duration is calculated and printed inline:
▣ Chat · model-name · Thought: 6.4s
📏 Cross-Platform Viewport Dimensions
Windows CONOUT$
Windows consoles do not support standard Unix ioctls. NERVI imports syscall and queries GetConsoleScreenBufferInfo by opening an active handle to the console output stream:
handle, err := syscall.Open("CONOUT$", syscall.O_RDWR, 0)
Unix ioctl winsize
On Unix and macOS systems, NERVI calls the standard system ioctl with the TIOCGWINSZ constant to fetch the window size into a winsize struct.