Skip to content

The REPL

The Shape REPL is a notebook-style TUI built on ratatui — not a plain stdin-line prompt. It uses modal editing (Normal / Insert / Command / Inspect) and cell-based history.

Terminal window
shape repl

This drops you into an alternate-screen terminal UI. Each cell has a gutter marker:

  • [N] (green) — input cell, not yet executed
  • [N]✓ (cyan) — input cell, executed successfully
  • / blank (dark gray) — output cell
  • ! (red) — error output
  • # (cyan) — chart output

The REPL is modal in the vim style:

  • Normal — navigation, cell selection, commands
  • Insert — typing into the focused cell
  • Command — typed after :, executes a REPL command on Enter
  • Inspect — output-cell inspection

The current mode is shown in the status bar.

KeyAction
iEnter Insert mode in the selected cell
a / A / IInsert at cursor / end / beginning
oOpen a new input cell below
j / k (or arrows)Move selection down / up
h / l (or arrows)Move selection left / right
g gGo to first cell
GGo to last cell
xCut character
rRe-run selected cell
d dDelete selected cell
:Enter Command mode
qQuit
KeyAction
EscCommit the cell and return to Normal mode
EnterInsert a newline inside the cell
Shift+Enter / Ctrl+EnterExecute the cell and open a new one below

Press : from Normal mode to enter Command mode, then type one of:

  • q / quit — exit the REPL
  • clear — clear all cells

Any other input shows Unknown command in the status bar.

  1. Start with shape repl — you land in Normal mode with an empty input cell.
  2. Press i to enter Insert mode and type:
    let x = 10
    let y = 5
    x + y
  3. Press Shift+Enter to execute. The cell is committed ([0]✓), and a new input cell opens below with the result rendered in an output cell.
  4. Press i again to enter the next cell. Type:
    fn square(n: int) -> int { n * n }
    Then Shift+Enter.
  5. Open another cell with o, type square(9), then Shift+Enter — the output shows 81.
  6. Press :, type q, press Enter to quit (or just press q from Normal mode).
  • Keep cell content small and focused — each cell is one logical unit.
  • Validate inferred types with hover/inlay hints in your editor when prototyping larger pieces, then drop them into the REPL.
  • Use r to re-execute the selected cell after editing it.

Continue with Variables and Types.