Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ansi_up

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ansi_up

Convert ansi sequences in strings to colorful HTML

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14K
decreased by-78.83%
Maintainers
1
Weekly downloads
 
Created
Source

ansi_up is a simple library for converting text embedded with ANSI terminal color commands into HTML spans that render the proper coloring. This is compliant with AMD (require.js). This code has been used in production since early 2012. This is a new project, but I will actively maintain it and welcome all feedback. Thanks for reading.

Turn this:

ESC[1;Foreground
 30   30   30   30   30   30   30   30  
 31   31   31   31   31   31   31   31  
 32   32   32   32   32   32   32   32  
...

Into this:

Browser Example

<script src="ansi_up.js" type="text/javascript"></script>
<script type="text/javascript">

var txt  = "\n\n\033[1;33;40m 33;40  \033[1;33;41m 33;41  \033[1;33;42m 33;42  \033[1;33;43m 33;43  \033[1;33;44m 33;44  \033[1;33;45m 33;45  \033[1;33;46m 33;46  \033[1m\033[0\n\n\033[1;33;42m >> Tests OK\n\n"

var html = ansi_up.ansi_to_html(txt);

var cdiv = document.getElementById("console");

cdiv.innerHTML = html;

</script>

Node Example

var ansi_up = require('ansi_up');

var txt  = "\n\n\033[1;33;40m 33;40  \033[1;33;41m 33;41  \033[1;33;42m 33;42  \033[1;33;43m 33;43  \033[1;33;44m 33;44  \033[1;33;45m 33;45  \033[1;33;46m 33;46  \033[1m\033[0\n\n\033[1;33;42m >> Tests OK\n\n"

var html = ansi_up.ansi_to_html(txt);

There are examples in the repo that demonstrate an AMD/require.js/ jQuery example as well as a simple browser example.

Installation

$ npm install ansi_up

API

ansi_up should be called via the functions defined on the module. It is recommended that the HTML is rendered with a monospace font and black background. See the examples, for a basic CSS definition.

escape_for_html (txt)

This does the minimum escaping of text to make it compliant with HTML. In particular, the '&','<', and '>' characters are escaped.

linkify (txt)

This replaces any links in the text with anchor tags that display the link. The links should have at least one whitespace character surrounding it.

ansi_to_html (txt)

This replaces ANSI terminal escape codes with SPAN tags that wrap the content. The styles are inline on the SPAN tags.

Building

Currently we are not using a build system, so there is just one file. Feel free to include the file in your asset minification process.

Running tests

To run the tests for ansi_up, run npm install to install dependencies and then:

$ make test

License

(The MIT License)

Copyright (c) 2011 Dru Nelson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WIT

Keywords

FAQs

Package last updated on 10 Oct 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc