Termite

ANSI / VT100 Ruby utilities.

Installation

gem sources -a http://gems.github.com

sudo gem install jbe-termite

Features

  • Colored terminal output
  • Other ANSI decorations
  • Redraw lines
  • Simple output “animation”
  • Progress bars
  • Sensible syntax

Requires

  • 16 color terminal
  • nix. Windows is *not supported.

Examples


require 'rubygems'
require 'termite'

include Termite::Palette

puts "Add some ' + green('color') + '!'

puts 'And also some ' + red('contrasting background!', :green)


                        puts red(  'The pentagram thy peace doth mar?' )

              puts black(:yellow,  'To me, thou son of hell, explain,' )

     puts blue(:underscore, cyan,
                 :blink, :bright,  'How earnest thou in, if this thine exit bar?' )

                puts white(:bold,  'Could such a spirit aught ensnare?')

Parameter order is irrelevant. Multiple strings will be joined.



    print 'Redrawing... '
    redraw do |i|
      if i < 11
        sleep 0.05
        i.to_s
      elsif i == 11
        'OK'
      else
        false
      end
    end


    print 'Animating progress bar..'
    pb = Termite::Progress.new 'Loading', 35, :red
    animated_redraw(50, 25) do |f|
      pb.report f.to_f / 50
    end

See also the examples in ‘./test’.

LICENSE

(MIT License)

Copyright © 2009 Jostein Berre Eliassen

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 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.