Go to file
Mai Lapyst bac4a2ddfd Update test 2023-09-25 06:20:50 +02:00
src Patch 2.0.1: Fix calculation of truecolor colors in range 16-231 2023-09-25 06:19:09 +02:00
test Update test 2023-09-25 06:20:50 +02:00
.gitignore Initial commit; version 1.0.0 2023-09-22 20:44:55 +02:00
LICENSE Initial commit; version 1.0.0 2023-09-22 20:44:55 +02:00
package.json Patch 2.0.1: Fix calculation of truecolor colors in range 16-231 2023-09-25 06:19:09 +02:00
readme.md Update 2.0.0: 2023-09-25 05:49:28 +02:00
test.rb Initial commit; version 1.0.0 2023-09-22 20:44:55 +02:00
vite.config.js Update 2.0.0: 2023-09-25 05:49:28 +02:00
yarn.lock Initial commit; version 1.0.0 2023-09-22 20:44:55 +02:00

readme.md

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