Project

ansispan

0.0
No release in over a year
Ruby port of the ansispan JS library.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

ansispan

Ruby port of the JS ansispan library, with some enhancements.

Installation

Add to Gemfile and bundle

gem "ansispan"

Usage

require "ansispan"

ansi_text = "* \e[33m8fb4737\e[m\e[33m (\e[m\e[1;36mHEAD -> \e[m\e[1;32mmaster\e[m\e[33m, \e[m\e[1;31morigin/master\e[m\e[33m, \e[m\e[1;31morigin/HEAD\e[m\e[33m)\e[m rails new\n"
Ansispan.convert(ansi_text)
# => * <span style="color: yellow">8fb4737</span><span style="color: yellow"> (</span><span style="font-weight: bold; color: cyan">HEAD -> </span><span style="font-weight: bold; color: green">master</span><span style="color: yellow">, </span><span style="font-weight: bold; color: red">origin/master</span><span style="color: yellow">, </span><span style="font-weight: bold; color: red">origin/HEAD</span><span style="color: yellow">)</span> rails new

The default escape character is \033 but you can pass your own to the convert method.

Ansispan.convert(ansi_text, escape_character: "\e")

Terminal output

terminal_output

HTML output

html_output

Ansi color reference

https://gist.github.com/Prakasaka/219fe5695beeb4d6311583e79933a009 (use \033 instead of \e) https://gist.github.com/Prakasaka/219fe5695beeb4d6311583e79933a009#gistcomment-3676483