Convert ANSI Escapes to HTML
C Ruby CSS
Switch branches/tags
Latest commit c07d756 Jul 11, 2016 William Josephson Add a build configuration.
Permalink
Failed to load latest commit information.
ext/ansible Make it easier to load the gem; step the gem version. Jul 11, 2016
lib
spec Add regression test for C extension. Jul 11, 2016
stylesheets
.gitignore
Gemfile Add regression test for C extension. Jul 11, 2016
Gemfile.lock
LICENSE basic structure Sep 4, 2011
README.md Edited README.md via GitHub Sep 4, 2011
Rakefile
ansible.gemspec
solano.yml

README.md

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.