term2html
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

term2html

Npm package version Npm package license Npm package types

Small library to convert terminal output to html code.

License

This project is licensed under AGPL-3.0. See the LICENSE file for more informations.

Usage

Basic example:

import { TerminalState, defaultTerminalState, term2html } from '../src/term2html';

const state: TerminalState = defaultTerminalState();
const text: string = '\u001B[31mhello\u001B[0m';
const html: string = term2html(text, state);

Note that term2html always needs a state supplied; with this you can call this multiple times to transform chunks of text, without losing the current state (styles and colors).

The generated html needs some css to work; most of it is in term2html.css inside the package.

Other then that it needs the actual colors for the 16 color palett (2 x 8 colors); they are retrieved via css variables:

  • --term2html-cX where X is between 0 and 7 (inclusive)
  • --term2html-bcX where X is between 0 and 7 (inclusive) (brighter colors)

One example is contained with the term2html-solarized-colors.css file, that configures the colors after the solarized color theme.

Supported

CSI codes (\u001B[?m):

  • bold, italic, underline, blinking and invisible (hidden)
  • foreground & background colors (8-colors, 16-colors, indexed 256-colors, rgb)
  • underline colors (indexed 256-colors, rgb)
  • color reset for all color types

Package Sidebar

Install

npm i term2html

Weekly Downloads

11

Version

2.0.2

License

AGPL-3.0-or-later

Unpacked Size

45.6 kB

Total Files

10

Last publish

Collaborators

  • mai-lapyst