Skip to main content

Terminal Formatter

ANSI escape codes for shell output.

Options

RuntimeOptions
Rustlanguage, theme
Elixirlanguage, theme
JavaScriptlanguage, theme
JavawithLang(), withTheme(), withFormatter(Formatter.TERMINAL)
CLIdefault formatter, --theme

Example

import {highlight} from '@lumis-sh/lumis'
import {terminal} from '@lumis-sh/lumis/formatters'
import javascript from '@lumis-sh/lumis/langs/javascript'
import dracula from '@lumis-sh/themes/dracula'
const ansi = await highlight('const x = 1', terminal({language: javascript, theme: dracula}))
console.log(ansi)

Output format

Terminal output is plain text wrapped in ANSI escape sequences:

\x1b[38;2;229;192;123mfn\x1b[0m \x1b[38;2;97;175;239mmain\x1b[0m() {}
  • the source stays as terminal text, not HTML
  • ANSI escape sequences set foreground color and text styles
  • \x1b[0m resets formatting between styled segments

When to use it

  • CLI tools
  • logs and local scripts
  • previewing highlighted code in a terminal