#8640·effect

DRAFT: Prompt: Esc is ignored — only Ctrl-C/Ctrl-D cancel a prompt

Author: spencerbeggsCreated Sep 30, 2026Updated Sep 30, 2026

We use Prompt in interactive CLIs and noticed that Esc does nothing in a prompt. We aren't sure whether that's intended.

What we observed

Pressing Esc in a Prompt.Select beeps (\x07), and the prompt keeps waiting. Enter then submits the highlighted choice. The only ways to back out of a prompt are Ctrl-C and Ctrl-D, which surface as Terminal.QuitError. Some other terminal prompt libraries treat Esc as cancel, so users try it and nothing happens.

Environment: [email protected] (tag [email protected], ad61db8) and @effect/[email protected], on Node 26.10.0 and macOS. From reading the source, the same lines are unchanged on main at 8b0eac6 (packages/effect/src/cli/Prompt.ts:3615-3642).

Reproduction

typescript
import * as NodeRuntime from "@effect/platform-node/NodeRuntime"
import * as NodeServices from "@effect/platform-node/NodeServices"
import { Console, Effect } from "effect"
import { Prompt } from "effect/cli"

const pick = Prompt.Select({
  message: "Pick one",
  choices: [{ title: "a", value: "a" }, { title: "b", value: "b" }]
})

Prompt.run(pick).pipe(
  Effect.flatMap((value) => Console.log(`\nselected: ${value}`)),
  Effect.catchTag("QuitError", () => Console.log("\nQuitError")),
  Effect.provide(NodeServices.layer),
  NodeRuntime.runMain
)

We ran node repro.ts under a pseudo-terminal, sent keystrokes to it, and captured the raw output live (escape bytes shown escaped).

Esc, then Enter half a second later. The \x07 after the first frame is the beep for Esc; the prompt then submits a:

\x1b[?25l\x1b[96m?\x1b[0m \x1b[1mPick one\x1b[0m \x1b[90m›\x1b[0m \r\n\x1b[96m❯\x1b[0m \x1b[4m\x1b[96ma\x1b[0m \r\n  b \x07\x1b[2K\x1b[1G\x1b[2K\x1b[G\x1b[32m✔\x1b[0m \x1b[1mPick one\x1b[0m \x1b[90m…\x1b[0m  \x1b[37ma\x1b[0m\r\n\x1b[?25h\r\nselected: a\r\n

The control, Ctrl-C:

\x1b[?25l\x1b[96m?\x1b[0m \x1b[1mPick one\x1b[0m \x1b[90m›\x1b[0m \r\n\x1b[96m❯\x1b[0m \x1b[4m\x1b[96ma\x1b[0m \r\n  b \x07\x1b[?25h\r\nQuitError\r\n

The key does reach the prompt. Reading one event from Terminal.readInput under the same pseudo-terminal and pressing Esc prints key.name="escape".

Where it happens

  • Prompt.ts:3615-3642: handleSelectProcess has no "escape" case, so the key falls to default, which returns Action.Beep(). The other built-in prompts' process handlers have no "escape" case either; grep -n escape packages/effect/src/cli/Prompt.ts finds nothing.
  • NodeTerminal.ts:176-178: the default shouldQuit ends input on Ctrl-C or Ctrl-D only.

Is this intended?

If Esc is left unbound on purpose, for example to leave it free for a future use, a line in the Prompt docs would help users. If not, one possible direction is to treat "escape" like Ctrl-C and fail with QuitError. Existing handling of cancellation, such as Flag.withFallbackPrompt re-failing with the original missing-option error, would then apply to it unchanged. Another is a Prompt option that opts into this behaviour. readline's escapeCodeTimeout: 50 in NodeTerminal already separates a lone Esc from the start of an arrow-key sequence, as the key.name check above shows.