function reportBadPath
reportBadPath(
command: string,
typed: string,
found: Exclude<FoundPath, { kind: "file"; }>
): void

Says why a typed path did not open, and puts the part that WAS real back on the prompt.

One function because it was always two calls in a row, byte for byte, in all three commands that do this — .cat, .tree and .view. Splitting them meant a command could say what went wrong and forget to help, which is a bug nobody would see in review.

The prompt is refilled so the next attempt costs a few keystrokes rather than the whole path: .cat lib/rep that missed comes back as .cat lib/ to carry on from, and TAB and the ghost take it from there. Nothing is refilled on a pipe, which has no line to put it on, and nothing for a path that exists but cannot be read — that one is not a typo.

import { reportBadPath } from './report-bad-path.ts';

import type { ReplContext } from './command.ts';

// Defined, not invoked: it writes to a live prompt.
function example(repl: ReplContext) {
  reportBadPath(repl, 'cat', 'lib/nope.ts', { kind: 'missing', prefill: 'lib/' });
  // logs `no such file: lib/nope.ts — lib/ exists`, then types `.cat lib/`
}

Parameters

command: string
typed: string
found: Exclude<FoundPath, { kind: "file"; }>

Return Type

void

Usage

import { reportBadPath } from "lib/commands/repl/report-bad-path.ts";