Parse ANSI code colors in a browser?

I have a source that has ANSI escape code attached to the lines it spits out. These lines are sent to the browser. I want to parse these ANSI escape codes with javascript in a browser so that it looks as if it would be in a terminal window.

Purpose: ANSI strings -> html styling covers

Is it possible? First I need to know how to parse ANSI strings in JS.

Thanks!!

+6
source share
3 answers

This has been done before. A quick google search finds escapes.js as one example.

+3
source

If you use angular, this may work: https://github.com/jorgeecardona/ansi-to-html

var app = angular.module('app', ['ansiToHtml']); app.controller('contr', function($scope, ansi2html) { $scope.text = ansi2html.toHtml("some ansi text"); }) 

I just create this repository and it works based on the coffeescript code linked on the page:

+3
source

Source: https://habr.com/ru/post/918125/


All Articles