ansilight
v1.2.1
Published
Truecolor syntax highlighting in the terminal with 200+ themes
Maintainers
Readme
ansilight
Ansilight is a syntax highlighter for the terminal.
Includes 256 truecolor themes from highlight.js, looking the same as in the browser.

The original highlight.js sample, rendered by ansilight.
Features
- 192 languages via
highlight.js - 256 truecolor themes ported from
highlight.js - Supports compound and nested style scopes, e.g.
variable.constantandmeta keyword - Configurable code block: background, padding, width
- Detects color scheme:
light/dark - Resolves theme based on detected scheme
- Automatically detects color support with graceful fallback
Install
npm install ansilightRequires Node.js 18+. This package is ESM only.
Quick Start
Reproduces the screenshot above using the bundled atom-one-dark theme.
import ansilight from 'ansilight';
import theme from 'ansilight/themes/atom-one-dark';
const code =
`class MyClass {
public static myValue: string;
constructor(init: string) {
this.myValue = init;
}
}
import fs = require("fs");
module MyModule {
export interface MyInterface extends Other {
myProperty: any;
}
}
declare magicNumber number;
myArray.forEach(() => { }); // fat arrow syntax`;
const output = ansilight(code, {
lang: 'typescript', // optional, auto-detected if omitted
theme, // optional, uses 'default' theme if omitted
});
console.log(output);Theme gallery
The package bundles 6 popular themes. All 256 themes are in the GitHub repository.
| Theme light | Theme dark |
|---|---|
| default (built-in)
| dark
|
| atom-one-light
| atom-one-dark
|
| github
| github-dark
|
More: full theme gallery | full documentation
