Formatters
Terminal Formatter
Options and examples for Lumis ANSI terminal output.
ANSI escape codes for shell output.
Options
| Runtime | Options |
|---|---|
| Rust | language, theme, background, width, highlight_lines, line_numbers |
| Elixir | language, theme, background, width, highlight_lines, line_numbers |
| JavaScript / TypeScript | language, theme, background, width, highlightLines, lineNumbers |
| Java | withLang(), withTheme(), withFormatter(Formatter.TERMINAL) |
| CLI | default formatter, --theme, --background, --width, --highlight-lines, --highlight-lines-background, --line-numbers |
A highlighted line is painted with a background, from highlight_lines'
background or the theme's highlighted style. See
Line Highlighting.
Example
import {highlight} from '@lumis-sh/lumis'
import {terminal} from '@lumis-sh/lumis/formatters'
import javascript from '@lumis-sh/wasm-javascript'
import frappe from '@lumis-sh/themes/catppuccin_frappe'
const ansi = await highlight(
'const x = 1',
terminal({
language: javascript,
theme: frappe,
background: 'theme',
width: 120,
}),
)
console.log(ansi)Output format
Terminal output is plain text wrapped in ANSI escape sequences:
\x1b[38;2;202;158;230mfn\x1b[0m \x1b[38;2;140;170;238mmain\x1b[0m() {}- the source stays as terminal text, not HTML
- ANSI escape sequences set foreground color and text styles
background/--backgroundcontrols the fallback background: omit it to inherit the output background, usethemeto reuse the theme background, or pass a hex colorwidth/--widthpads each rendered line to the requested width, which is only visible alongsidebackground; in the CLI,autouses the current terminal width when available, and-wis the short form- a tab counts as four columns when measuring a line for padding, in every runtime
\x1b[0mresets formatting between styled segments
When to use it
- CLI tools
- logs and local scripts
- previewing highlighted code in a terminal