The terminal UI I wanted for a coding agent had an awkward requirement: the model could still be producing output while I was typing the next command. Printing every token on a new line would be easy. Keeping a readable transcript, a stable prompt and a cursor in the right place is where the engineering begins.
On August 13, 2025, I opened Gemini CLI's App.tsx. Looking at a command-line application through a component tree led me to Ink. On August 27 I searched for a Rust equivalent and opened Ratatui's counter tutorial. The language comparison was deliberate. I wanted to see which responsibilities belong to any terminal UI, even after changing the renderer.12
Who owns the screen while a response is streaming?
Suppose I write a Python command called agent and use Click to define a --model option. When I type agent --model demo, Click passes the value demo to my function. If I type agent --help, Click lists the option for me.3 Now suppose the agent is running and I move the cursor back a few words to edit my next message. When another piece of the model's reply appears above the prompt, how does the cursor stay where I put it?
I would give the application three pieces of state: completed messages, the assistant's current response, and an editable input buffer with a cursor. A token extends the current response. Enter submits the input once and assigns it to a request. A resize changes the available columns and may rewrap the current response. None of those events should silently replace the user's draft. Keeping the transcript and the draft separate makes the expected behavior testable.
What should I see when I drag a file into the prompt? Suppose a file called draft notes.ts contains just one line, export const retries = 3;. On macOS, dragging the file from Finder into Terminal inserts its full path at the cursor.4 In a file-opening command I could design, the interaction would look like this:
After the drop, while the prompt is still editable:
> /open /Users/lee/notes/draft\ notes.ts
After pressing Enter, in the file preview:
export const retries = 3;
In the command, the backslash marks the space as part of the filename. If the model sends another line of its reply while I pause here, that line belongs in the transcript above. I should still be able to press Left and edit my command. When I press Enter, the app's command handler interprets the text after /open as one path, /Users/lee/notes/draft notes.ts. It calls readFile(path, 'utf8') from Node's node:fs/promises module, waits for the file text, and puts it in the preview. If I mistype the path, the app should show the read error where I expected the file contents.5
Suppose I type “Review the change to the invitation email” and want to add “Check what happens when the name is empty” on a second line. Ernest Chiang advised his workshop readers to configure Shift+Enter for a newline in Claude Code. He also noted that fuzzy matching helped users find slash commands as they typed.6 For my prompt, I would map a distinct Shift+Enter input to inserting a newline at the cursor. Both lines would stay editable, even as the previous response streamed in. Pressing Enter would submit the whole draft once. Likewise, typing /di could suggest /diff while I was still editing. These are input behaviors I could test with either renderer.
A terminal has rows and columns. A long diff forces a layout decision: let it fill the scrollback, limit its height, or open a dedicated view. Cursor movement has its own problem. Deleting a character in the middle of a command must preserve the text on both sides; a UTF-8 byte offset or a JavaScript string index need not correspond to one visible terminal cell. Even with perfect model output, an input box that eats the next character is a broken interface.
What does Ink buy a TypeScript agent?
The file drop made my first choice easier. If all I want is agent "draft notes.ts" to print a file once, Node can read the path from the command line. For a sequence of questions with one answer at a time, Node's built-in readline can collect a line for each question. A renderer becomes useful when several things stay on screen and change independently. In my case those were the editable command, the reply still arriving, and the preview. TSX lets me describe those regions as components. Ink supplies the code that draws them in terminal cells.78
When I asked which library Gemini CLI used, the assistant initially suggested it drew its own interface. I pointed it back to the “Who's Using Ink?” section of Ink's README. The August list named Codex, Claude Code and Gemini CLI. Gemini CLI's August package manifest shows the dependency itself, "ink": "^6.0.1". With that settled, I asked for a small example I could try.9
Ink uses a React renderer for terminal output. Box arranges regions and Text displays terminal text. A transcript can therefore be a composition of familiar components. Ink's Static can print completed entries above the changing area; the partial answer and the user's draft can remain in the live area. The two examples below use the same packages. The first shows who owns the draft while I edit a path. The second adds a reply that arrives in pieces.8
Can I run the file preview from an empty directory?
Here is a small example written for this article. It uses Ink 4 and React 18, the pair in my prototype's CLI package. The extra ink-text-input component handles typing, pasting and moving the cursor. I keep the whole example in one package. On Node 22 with npm, these commands create that package and install tsx, which runs a TypeScript file containing JSX. Node runs the app directly, so this setup needs no browser build step or Vite configuration.1011
mkdir ink-preview
cd ink-preview
npm init -y
npm pkg set type=module 'scripts.start=tsx app.tsx'
npm install ink@4.4.1 react@18.3.1 ink-text-input@5.0.1
npm install --save-dev tsx@4.20.5
Save this as app.tsx. The input starts with /open already filled in. The preview changes only on submission. A number attached to each submission lets a second request replace the first even if the earlier read finishes last.
import React, {useRef, useState} from 'react';
import {readFile} from 'node:fs/promises';
import {Box, Text, render} from 'ink';
import TextInput from 'ink-text-input';
function App() {
const [draft, setDraft] = useState('/open ');
const [preview, setPreview] = useState('Enter a path to preview a text file.');
const latest = useRef(0);
async function submit(command: string) {
const request = ++latest.current;
const match = /^\/open\s+(.+)$/.exec(command.trim());
if (!match) {
setPreview('Usage: /open <path>');
return;
}
const argument = match[1];
const quoted = /^(["'])(.*)\1$/.exec(argument);
const path = quoted ? quoted[2] : argument.replace(/\\ /g, ' ');
setPreview('Reading ' + path);
try {
const contents = await readFile(path, 'utf8');
if (request === latest.current) setPreview(contents || '(empty file)');
} catch (error) {
if (request === latest.current) {
setPreview(error instanceof Error ? error.message : String(error));
}
}
}
return (
<Box flexDirection="column">
<Text>{preview}</Text>
<Box>
<Text>{'> '}</Text>
<TextInput value={draft} onChange={setDraft} onSubmit={submit} />
</Box>
</Box>
);
}
render(<App />);
printf '%s\n' 'export const retries = 3;' > 'draft notes.ts'
npm start
In the terminal that started the app, type draft notes.ts after /open , or drag that file from Finder into macOS Terminal. The sample takes one small UTF-8 text file. It accepts the path with spaces typed literally, with the backslash-escaped spaces shown above, or enclosed in a pair of quotes. Press Left and edit the name before submitting. Enter on the correct name displays export const retries = 3;. Change it to a missing name and press Enter again to see the file error. Press Ctrl+C to exit. The terminal supplies the path, the input component keeps the editable draft, and only submit calls the filesystem.
Can I keep typing while an answer arrives?
In the same directory, save this as chat.tsx and run node --import tsx chat.tsx. A timer supplies pieces of a sample reply so the interaction works without a model account. Each completed turn goes into Static once. The pending reply and the editable input stay below it.
import React, {useEffect, useState} from 'react';
import {Box, Static, Text, render, useInput} from 'ink';
import TextInput from 'ink-text-input';
type Turn = {prompt: string; reply: string};
function Chat() {
const [turns, setTurns] = useState<Turn[]>([]);
const [pending, setPending] = useState<string | null>(null);
const [partial, setPartial] = useState('');
const [draft, setDraft] = useState('');
const [recalled, setRecalled] = useState<number | null>(null);
const input = recalled === null ? draft : turns[recalled].prompt;
useInput((_, key) => {
if (key.upArrow && turns.length > 0) {
setRecalled(Math.max(0, (recalled ?? turns.length) - 1));
} else if (key.downArrow && recalled !== null) {
setRecalled(recalled + 1 < turns.length ? recalled + 1 : null);
}
});
useEffect(()=> {
if (pending= null) return;
const chunks= ['Looking ', 'for the ', 'invitation ', 'template.'];
let reply= '';
let index= 0;
const timer= setInterval(()=> {
reply = chunks[index++];
if (index < chunks.length) {
setPartial(reply);
} else {
clearInterval(timer);
setTurns(previous=> [...previous, {prompt: pending, reply}]);
setPending(null);
}
}, 500);
return ()=> clearInterval(timer);
}, [pending]);
function submit(prompt: string) {
if (pending = null || !prompt.trim()) return;
setDraft('');
setRecalled(null);
setPartial('');
setPending(prompt);
}
return (
<Box flexDirection="column">
<Static items={turns}>{(turn, index) =>
<Text key={index}>{'> '}{turn.prompt}{'\n'}{turn.reply}</Text>
}</Static>
{pending !== null && <Text>{'> '}{pending}{'\n'}{partial}</Text>}
<Box>
<Text>{'> '}</Text>
<TextInput value={input} onSubmit={submit} onChange={value=> {
setDraft(value);
setRecalled(null);
}} />
</Box>
</Box>
);
}
render(<Chat />);
Submit find the email, then start typing check the greeting while the answer appears. When the reply finishes, the first exchange should appear once and the second draft should still be editable. Press Up to recall the submitted prompt, then Down to return to the draft. This example accepts one request at a time, so Enter submits the draft once the previous reply is complete.
How does the same problem look in Ratatui?
In Ratatui the application owns its event loop. It consumes an input, resize or model event, updates its state, and asks the terminal to draw a frame. A draw callback describes the visible screen with widgets and rectangles. Ratatui compares buffers and sends the required changes to the terminal backend. The programmer can reason about the whole frame while the backend deals with many of the individual writes.2
| One event | Ink implementation | Ratatui implementation |
|---|---|---|
| Model emits text | Append to the current response in state; render the live output component. | Send a chunk to the event loop; append to the response and request a draw. |
| User presses Up | Handle input while the prompt has focus; restore an earlier command into the draft. | Map the key event to a history action; update the buffer and cursor before drawing. |
| Terminal narrows | Recompute widths and wrapping in the component layout. | Read the new frame area and lay out transcript and input rectangles again. |
| User interrupts a request | Cancel the producer and reconcile the partial response with the transcript. | Signal cancellation, handle the final event, and ensure terminal modes are restored on exit. |
A model stream and a keyboard are independent event sources. In either implementation I would feed them into one owner of screen state. For a fast stream, drawing once for several chunks can keep the prompt responsive. I would test typing, resizing and cancelling during a response. A counter incremented by one keypress only exercises the easy case.
What my prototype reached
In open-vibe-coder-js, commit 03bd8c1 on August 25 creates the TypeScript workspace and an Ink entry point displaying Hello CLI world. The local work that followed includes components and command handling. The problems I asked about were concrete: Up and Down for history, Left and Right for the editing cursor, Backspace, and displaying a file after opening it. An August 26 Git stash connects the sidebar, editor, command input and diff dialog. Its /diff branch opens the dialog with the literal text Diff functionality coming soon.... The interface had somewhere to show changes, but that action still needed the two file versions.10
That distinction influenced which prototype I would build next. For the TypeScript agent, Ink lets the interface share types and events with the existing core. A Rust application can use Ratatui to keep the event loop, terminal lifecycle and rendering schedule explicit. The useful comparison is the same interaction in both: type half a command, receive a long reply, resize the terminal, and press Left. The prompt should still contain the half-written command with its cursor on the intended character. The broader file-editing experiment is recorded in my coding-agent implementation notes.
References
Footnotes
-
Google and Gemini CLI contributors. (n.d.). Gemini CLI application UI. GitHub. The application entry I visited. The main-branch link can change after the August 2025 visit. ↩
-
Ratatui contributors. (n.d.). Counter app and Rendering. Ratatui documentation. Counter tutorial I visited, frame and buffer model. ↩ ↩2
-
Pallets. (n.d.). Welcome to Click. Click documentation. Command example and generated help. ↩
-
Apple. (n.d.). Drag items into a Terminal window on Mac. Terminal User Guide. Entering the path of a file or folder. ↩
-
Cai, B. (2025, August 27). 终端里的编程助手怎样调用核心?从 TypeScript 函数调用到 Python 子进程. Further reading on where the file-reading function can run. ↩
-
Chiang, E. (2025, July 30). 我的 Anthropic Claude Code 學習筆記. Ernest Chiang. See the workshop advice on configuring Shift+Enter and the early terminal features, including slash-command matching. ↩
-
Node.js contributors. (2025). Readline (v22.18.0). Node.js documentation. Reading one line and asking a question. ↩
-
Demedes, V., and contributors. (n.d.). Ink. GitHub. Box, Text, Static and input handling. ↩ ↩2
-
Demedes, V., and contributors. (2025, August 21). Ink. GitHub. “Who's Using Ink?”, first three entries. Google Gemini CLI contributors. (2025, August 13). CLI package manifest. GitHub. Ink dependency. ↩
-
Cai, B. (2025, August). open-vibe-coder-js [Local Git repository and subsequent working tree]. Commit
03bd8c1, packages/cli/src/index.tsx; August 26 stash92b0527, same entry point, lines 34–42 and 44–78. The working tree and Cursor exchanges document the command-editing work. ↩ ↩2 -
Demedes, V., and contributors. (n.d.). ink-text-input (v5.0.1) [Source code]. GitHub. Controlled input, cursor movement and submission. ↩