function setupRightMarginPreview
setupRightMarginPreview(
server: REPLServer,
session: ReplSession,
): void

Shows what the line would come to, dimmed against the RIGHT MARGIN while it is still being typed.

> document.title                                              'qunitx repl'

Free by construction: the session evaluates with V8 refusing anything that has a side effect, so an expression that would change something answers nothing at all rather than changing it. What is left is worth showing before Enter, which is the whole point — the answer to 1 + 1 is not worth a round of the read-eval-print loop.

Drawn only where there is room for it, and on ONE line. A narrow terminal, a line already near the edge, a value that needs more columns than are left: in each case it is cut to the room or not drawn at all, because a preview that crowds the line it belongs to costs more than it gives. Painted in the colours the page rendered it in, which are the colours the same value will be printed in a keystroke later.

import { setupRightMarginPreview } from './index.ts';

import type { REPLServer } from 'node:repl';
import type { ReplSession } from '../../repl/session.ts';

// Defined, not invoked: it evaluates in a live page and draws on a live terminal.
function example(server: REPLServer, session: ReplSession) {
  setupRightMarginPreview(server, session, {
    isEvaluating: () => false,
    suggestionOnTheRow: () => '',
  });
}

Parameters

server: REPLServer
session: ReplSession

Return Type

void

Usage

import { setupRightMarginPreview } from "lib/commands/repl/index.ts";