Project

ansible

0.0
No commit activity in last 3 years
No release in over 3 years
Ansible is a fast (somewhat rough) conversion tool that takes a string with ANSI escapes and produces HTML.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
>= 0
 Project Readme

Ansible

Overview

Ansible is an attempt at an ANSI-escape to HTML conversion tool that's fast enough to use on large input. Particularly, it's meant to be significantly faster than the ansi-sys gem for large input text.

Installation

Install the gem:

 gem install ansible

Usage

Here's an example of using Ansible in a rails controller:

 require 'ansible'

 class TextController << ApplicationController
   include Ansible
   def show
     rawtext = Text.find(params[:id])
     @text = ansi_escaped(rawtext)
   end
 end

Ansible will convert escapes into HTML <span> tags that apply sensible classes that correspond to ANSI escape directives, like:

  • ansible_green
  • ansible_blue
  • ansible_magenta

You can control the display of these with CSS however you please.

See the sample stylesheet.

Long input

For input beyond a certain size (default 65535 characters), Ansible will automatically fall back to simply stripping escapes entirely. You can control this threshold when you call ansi_escaped:

 class Helper
   include Ansible

   def handle_escaped(rawtext)
     ansi_escaped(h(rawtext), 32768).html_safe
   end
 end

What's with the name Ansible?

An ansible is a fictional faster than light communication device.

Contributing

We welcome fixes and enhancements. Feel free to fork on github and submit a pull request.