Thanks to visit codestin.com
Credit goes to GitHub.com

Skip to content

Render text with ANSI escape codes as HTML

License

Notifications You must be signed in to change notification settings

mischnic/ANSI-Escape.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ANSI-Escape.js

A Javascript library to render text with ANSI escape sequences using HTML and CSS.

To force a command to use escape sequences (even without an interactive shell) use, depending on your OS:

  • script -q /dev/null ls -alG or

  • script -qec "ls -alG" /dev/null

    (to save the output to a file: replace /dev/null with a filename)

Usage

/* 
 *  `parseInteractive` removes artifacts caused by the interactive
 *  rewriting of the terminal window by some applications.
 */
function ansiToHTML(input, parseInteractive=true){
    ....
    return parsedHTMLCode;
}


const cmdOutput = "... some text with escape sequences";
const parsedOutput = ansiToHTML(cmdOutput);
document.querySelector(".console > code > pre").innerHTML = parsedOutput;

Supported features

  • color: 8/16 mode
  • style: bold/underlined/dim/hidden
  • corresponding reset codes

Not (yet) supported:

  • color: 88/256 mode
  • style: blink/reversed
  • (unsupported codes are also logged to the console)

For detailed information see the ANSI_Styles object in ANSI-Escape.js.

Example output from test.js

About

Render text with ANSI escape codes as HTML

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published