function setupLineHighlighting
setupLineHighlighting(
server: REPLServer,
palette: Theme
): void

Paints the line AS IT IS TYPED, in the colours the theme gives each capture.

Two halves. _writeToOutput is where readline puts the prompt and the line on screen, so that is where the line is swapped for a painted one — the substitution is by VALUE, and anything that is not exactly what readline believes the line to be passes through untouched. And a refresh is asked for on every keypress, because readline appends a typed character in place rather than redrawing, and a keyword cannot be recognised one character at a time.

Only what is written changes, never what readline computed: the painted line occupies the same columns as the plain one, so every cursor position readline worked out still lands where it meant to.

import { setupLineHighlighting } from './index.ts';
import { theme } from '../../repl/theme.ts';

import type { REPLServer } from 'node:repl';

// Defined, not invoked: it draws on a live terminal.
function example(server: REPLServer) {
  setupLineHighlighting(server, theme());
}

Parameters

server: REPLServer
palette: Theme

Return Type

void

Usage

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