Files
tty7/docs/terminal/prompt.mdx
T
l0ng-aiandl0ng-ai 72db26d15a feat(prompt): let the shell's own line editor own the prompt (#633)
Closes #624

tty7's inline editor takes the prompt the moment OSC 133 reports one, and
until now the only way to keep it off was to hide the shell's own name
from tty7 so integration never armed — which costs the prompt boundaries,
cwd and exit codes as well. Someone who binds `history-beginning-search-
backward-end` to Up in their zshrc had no way to reach it, and the local
history the editor walks instead is per-view: a command run in one pane is
not in another's list, so the shell's shared history looked broken too.

The new `prompt_editor` switch (Settings -> Input -> Prompt, on by
default) hands the line back. Off, every key at the prompt goes to the
PTY, so ZLE / readline / fish do the editing and what the user bound
behaves as written. Shell integration is untouched by it.

The gate is one line in `input_inactive_reason`, which every path that
could take the prompt from the shell already asks: keys, IME commits,
paste, Tab, the completion and reverse-search menus, the input bar. That
is what makes this a mode rather than a special case per key.

`shell_owns_prompt` learns the flag too, and that half matters more than
it looks: the gap hold and the typeahead record both exist to feed the
local editor, and `flush_typeahead` sends ^U to erase the line before
moving it there — on a line only ZLE is editing, that erases the user's
work. Ctrl-R landing on the PTY also stops raising the missing-integration
notice: the shell owning it is what was asked for.

Turning it off mid-line hands what is typed to the shell the way an
unknown chord does, so the text is still on the prompt to finish. Live
panes follow the switch, including a hand edit of config.json in another
window.

Tab completion and history search are menus tty7 opens inside that editor,
so the page greys them out and says why while it is off. Only their text
dims — a switch already draws its thumb at 35% when disabled, and dimming
the row on top of that leaves a pill with nothing visible in it. Their
stored values are left alone and come back with the editor.

Co-authored-by: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com>
2026-08-14 14:46:22 +08:00

166 lines
6.5 KiB
Plaintext

---
title: "The prompt"
description: "Ghost suggestions, tab completion that explains itself, syntax highlighting, and real multi-line editing."
---
tty7 puts an editor at the shell prompt. Nothing to install, no plugin to source
— the moment a supported shell starts in a pane, the prompt behaves like this.
<Frame caption="Placeholder — video: typing a command with a ghost suggestion, accepting it, then opening the completion menu">
<img src="/images/placeholder.svg" alt="The tty7 prompt" />
</Frame>
## Ghost suggestions
As you type, the rest of the line is filled in from your history, greyed out
ahead of the cursor.
| | |
|---|---|
| <kbd>→</kbd> | Accept the whole suggestion |
| Keep typing | The suggestion narrows |
| Anything that does not match | It disappears |
Your existing shell history is what feeds it — there is no separate database to
build up first, and it carries across sessions and reboots.
## Tab completion, with descriptions
<kbd>⇥</kbd> opens a completion menu that knows what it is offering:
- **Commands** from your PATH and your shell's builtins
- **Files and directories**, with `cd`, `pushd`, `popd`, and `rmdir` offering
directories only
- **Flags and subcommands** with their descriptions, for about 100 common
commands — `git`, `cargo`, `docker`, `kubectl`, `npm`, `brew` and the rest
- **Values** where a flag only takes certain ones
<Frame caption="Placeholder — screenshot: the completion menu on `git c`, each subcommand with its description">
<img src="/images/placeholder.svg" alt="Explained tab completion" />
</Frame>
When tty7 has nothing useful to offer, the <kbd>⇥</kbd> falls through to your
shell's own completion, so a carefully configured zsh setup is not lost.
To hand <kbd>⇥</kbd> back to the shell entirely, turn off **Settings → Input →
Prompt → Tab completion** (`tab_completion` in `config.json`).
## Syntax highlighting
The line you are typing is coloured as you type it: the command, its flags, its
arguments, paths, quoted strings, operators, comments. It is a fast tokenizer,
not a shell parser — it never changes what gets run.
## Line editing
The prompt behaves like a text field, because it is one:
- **Click to place the caret** anywhere in the line
- **Select with the mouse**, drag to extend
- **Word motion** and word delete
- **Undo**
Everything readline does still works — this sits on top, it does not replace it.
<Tip>
On macOS, turn on **Settings → Input → Keyboard → Option (⌥) acts as Meta** if
you want <kbd>⌥ B</kbd> / <kbd>⌥ F</kbd> to move by word instead of typing
`∫` and `ƒ`.
</Tip>
## Typing with an IME
Pinyin, Kana, Hangul and the rest work in a pane the way they do in a text
field: the composition is drawn in place at the cursor and only the committed
text reaches the program.
Two rules decide who gets a keystroke:
- **A plain printable key goes to the IME.** A key held with <kbd>⌃</kbd>,
<kbd>⌘</kbd>, <kbd>fn</kbd>, or <kbd>⌥</kbd> does not — those are chords, not
characters.
- **A program that asks for every key gets every key.** When something turns on
the kitty keyboard protocol's report-all-keys mode, the IME steps aside so the
program sees raw input.
<Note>
On macOS with **Option (⌥) acts as Meta** turned on, <kbd>⌥</kbd> chords
bypass the IME entirely, so <kbd>⌥ B</kbd> reaches your shell as meta-b
instead of being eaten as a dead key.
</Note>
Rendering CJK well is a separate question — see
[fonts and the two-column grid](/customization/fonts#cjk-and-the-two-column-grid).
## Multi-line commands
A command that wraps, or one you deliberately break across lines, edits in
place. The grid shifts to keep the caret visible instead of scrolling the whole
screen away.
| | |
|---|---|
| <kbd>⇧ ⏎</kbd> · <kbd>⌥ ⏎</kbd> | Insert a newline instead of submitting |
| <kbd>⏎</kbd> | Submit the whole buffer, however many lines it is |
The newline key is rebindable as `InsertNewline` under **Settings →
Keybindings**.
## Which shells
The prompt features arrive through tty7's shell integration, which is injected
automatically — nothing to add to your rc file — for **zsh**, **bash**,
**fish**, **PowerShell**, and **WSL**. Other shells (nushell, elvish, xonsh, and
the rest) run perfectly well in a pane; they simply do not get the prompt layer.
The integration is also what reports the working directory, the exit code of
each command, and where prompts begin — which is what the sidebar's branch
readout, the "command finished" notification, and `tty7 procs` are built on.
[How shell integration works →](/reference/shell-integration)
## Turning it off
Each prompt feature is a switch, and turning one off hands its key straight back
to the shell:
| Setting | Key it releases |
|---|---|
| **Settings → Input → Prompt → Tab completion** | <kbd>⇥</kbd> → your shell's completion |
| **Settings → Input → Prompt → History search** | <kbd>⌃ R</kbd> → your shell's reverse-i-search, or your fzf binding |
### Giving the whole prompt back to the shell
Turning off **Settings → Input → Prompt → Prompt editor**
(`prompt_editor: false`) hands over not one key but the line itself. Every
keystroke at the prompt — printable characters, arrows, IME commits, paste — goes
straight to the PTY, and your shell's own line editor does the editing: zsh's
ZLE, bash's readline, fish's reader. A widget you bound yourself runs exactly as
it does outside tty7:
```zsh
# ~/.zshrc — works at a tty7 prompt with the editor off
bindkey '^[[A' history-beginning-search-backward-end
```
What you give up is the layer this page describes: ghost suggestions, the
completion menu, the fuzzy <kbd>⌃ R</kbd>, the multi-line editor, mouse caret
placement and undo on the prompt. Tab completion and history search grey out in
Settings while it is off — both are menus tty7 opens inside that editor, so
there is nothing left for them to switch.
What you keep is everything shell integration reports: prompt boundaries, the
working directory, exit codes, "command finished" notifications, the sidebar's
branch readout, `tty7 procs`. The setting moves the line editor, not the
integration.
It applies to open panes immediately, so there is nothing to restart, and a line
you had half-typed is handed to the shell rather than dropped.
<Tip>
Reach for this if the shell's own history traversal matters to you — shared
history between panes, `HIST_FIND_NO_DUPS`, a prefix search bound to
<kbd>↑</kbd> — or if a plugin you rely on (zsh-autosuggestions,
zsh-syntax-highlighting, atuin) should own the line instead.
</Tip>