")
line.gsub!(/\[ALIGN=left\]/i, "")
line.gsub!(/\[\/ALIGN\]/i, "")
## QUOTE
quote+=1 if line =~ /\[QUOTE\]/i
quote-=1 if (line =~ /\[\/QUOTE\]/i) && (quote > -1)
line.gsub!(/\[QUOTE\]/i, "\n")
line.gsub!(/\[\/QUOTE\]/i, "
\n")
line.gsub!(/^/, ">"*quote) if quote > 0
## EMAIL
line.gsub!(/\[EMAIL\](.*?)\[\/EMAIL\]/i, "\\1")
## LIST (TODO: LIST=1, LIST=A)
line.gsub!(/\[LIST(?:=(.*?))?\]/i, "\n\n")
line.gsub!(/\[\/LIST\]/i, "\n
\n")
line.gsub!(/\[\*\]/i, "\n")
## FONT => font ??????
## ?BLUR?, FADE?
result << sprintf("%s
\n", line)
end
return result
end
# -- Transitive methods ---------------
# Converts an ANSI string to one with HTML markup.
# Returns the string with ANSI code sequences converted to XHTML markup.
def BBCode.ansi_to_html(string)
bbcoded = BBCode.ansi_to_bbcode(string )
htmled = BBCode.bbcode_to_html(bbcoded)
return htmled
end
# Returns the (X)HTML markup code as ANSI sequences
def BBCode.html_to_ansi(string)
bbcoded = BBCode.html_to_bbcode(string )
ansied = BBCode.bbcode_to_ansi(bbcoded)
return ansied
end
end #module BBCode
end
ansi-1.5.0/lib/ansi/terminal.rb 0000644 0000041 0000041 00000001553 12465501305 016344 0 ustar www-data www-data module ANSI
# = Terminal
#
# This library is based of HighLine's SystemExtensions
# by James Edward Gray II.
#
# Copyright 2006 Gray Productions
#
# Distributed under the tems of the
# {Ruby software license}[http://www.ruby-lang.org/en/LICENSE.txt].
module Terminal
module_function
modes = %w{win32 termios curses stty}
# This section builds character reading and terminal size functions
# to suit the proper platform we're running on.
#
# Be warned: Here be dragons!
#
begin
require 'ansi/terminal/' + (mode = modes.shift)
CHARACTER_MODE = mode
rescue LoadError
retry
end
# Get the width of the terminal window.
def terminal_width
terminal_size.first
end
# Get the height of the terminal window.
def terminal_height
terminal_size.last
end
end
end
ansi-1.5.0/lib/ansi/logger.rb 0000644 0000041 0000041 00000011534 12465501305 016010 0 ustar www-data www-data # Ansi::Logger
# Copyright (c) 2009 Thomas Sawyer
# Copyright (c) 2005 George Moschovitis
require "logger"
require "time"
require "ansi/code"
# = ANSI::Logger
#
# Extended variation of Ruby's standard Logger library that supports
# color output.
#
# log = ANSI::Logger.new
#
# log.formatter do |severity, timestamp, progname, msg|
# ANSI::Logger::SIMPLE_FORMAT % [severity, msg]
# end
#
#--
# TODO: What's all this about then?
#
# When using debug level logger messages always append 'if $DBG'
# at the end. This hack is needed because Ruby does not support
# lazy evaluation (lisp macros).
#++
class ANSI::Logger < Logger
# Some available logging formats.
SIMPLE_FORMAT = "%5s: %s\n"
DETAILED_FORMAT = "%s %5s: %s\n"
# TODO: Not sure I like this approach.
class ::Logger #:nodoc:
class LogDevice #:nodoc:
attr_writer :ansicolor
def ansicolor?
@ansicolor.nil? ? true : @ansicolor
end
end
end
#
def ansicolor?
@logdev.ansicolor?
end
#
def ansicolor=(on)
@logdev.ansicolor = on
end
# Dictate the way in which this logger should format the
# messages it displays. This method requires a block. The
# block should return formatted strings given severity,
# timestamp, progname and msg.
#
# === Example
#
# logger = ANSI::Logger.new
#
# logger.formatter do |severity, timestamp, progname, msg|
# "#{progname}@#{timestamp} - #{severity}::#{msg}"
# end
#
def formatter(&block)
self.formatter = block if block
super
end
def styles(options=nil)
@styles ||= {
:info => [],
:warn => [:yellow],
:debug => [:cyan],
:error => [:red],
:fatal => [:bold, :red]
}
@styles.merge!(options) if options
@styles
end
#
def info(progname=nil, &block)
return unless info?
@logdev.ansicolor? ? info_with_color{ super } : super
end
#
def warn(progname=nil, &block)
return unless warn?
@logdev.ansicolor? ? warn_with_color{ super } : super
end
#
def debug(progname=nil, &block)
return unless debug?
@logdev.ansicolor? ? debug_with_color{ super } : super
end
#
def error(progname=nil, &block)
return unless error?
@logdev.ansicolor? ? error_with_color{ super } : super
end
#
def fatal(progname=nil, &block)
return unless error?
@logdev.ansicolor? ? fatal_with_color{ super } : super
end
private
def info_with_color #:yield:
styles[:info].each{ |s| self << ANSI::Code.send(s) }
yield
self << ANSI::Code.clear
end
def warn_with_color #:yield:
styles[:warn].each{ |s| self << ANSI::Code.send(s) }
yield
self << ANSI::Code.clear
end
def error_with_color #:yield:
styles[:error].each{ |s| self << ANSI::Code.send(s) }
yield
self << ANSI::Code.clear
end
def debug_with_color #:yield:
styles[:debug].each{ |s| self << ANSI::Code.send(s) }
yield
self << ANSI::Code.clear
end
def fatal_with_color #:yield:
styles[:fatal].each{ |s| self << ANSI::Code.send(s) }
yield
self << ANSI::Code.clear
end
end
# NOTE: trace is deprecated b/c binding of caller is no longer possible.
=begin
# Prints a trace message to DEBUGLOG (at debug level).
# Useful for emitting the value of variables, etc. Use
# like this:
#
# x = y = 5
# trace 'x' # -> 'x = 5'
# trace 'x ** y' # -> 'x ** y = 3125'
#
# If you have a more complicated value, like an array of
# hashes, then you'll probably want to use an alternative
# output format. For instance:
#
# trace 'value', :yaml
#
# Valid output format values (the _style_ parameter) are:
#
# :p :inspect
# :pp (pretty-print, using 'pp' library)
# :s :to_s
# :y :yaml :to_yaml (using the 'yaml' library')
#
# The default is :p.
#
# CREDITS:
#
# This code comes straight from the dev-utils Gem.
# Author: Gavin Sinclair
def trace(expr, style=:p)
unless expr.respond_to? :to_str
warn "trace: Can't evaluate the given value: #{caller.first}"
else
raise "FACETS: binding/or_caller is no longer possible"
require "facets/core/binding/self/of_caller"
Binding.of_caller do |b|
value = b.eval(expr.to_str)
formatter = TRACE_STYLES[style] || :inspect
case formatter
when :pp then require 'pp'
when :y, :yaml, :to_yaml then require 'yaml'
end
value_s = value.send(formatter)
message = "#{expr} = #{value_s}"
lines = message.split(/\n/)
indent = " "
debug(lines.shift)
lines.each do |line|
debug(indent + line)
end
end
end
end
TRACE_STYLES = {} # :nodoc:
TRACE_STYLES.update(
:pp => :pp_s, :s => :to_s, :p => :inspect,
:y => :to_yaml, :yaml => :to_yaml,
:inspect => :inspect, :to_yaml => :to_yaml
)
=end
ansi-1.5.0/lib/ansi/table.rb 0000644 0000041 0000041 00000007336 12465501305 015625 0 ustar www-data www-data require 'ansi/core'
require 'ansi/terminal'
module ANSI
class Table
# The Table class can be used to output nicely formatted
# tables with division lines and alignment.
#
# table - array of array
#
# options[:align] - align :left or :right
# options[:padding] - space to add to each cell
# options[:fit] - fit to screen width
# options[:border] -
#
# The +format+ block must return ANSI codes to apply
# to each cell.
#
# Other Implementations:
#
# * http://github.com/visionmedia/terminal-table
# * http://github.com/aptinio/text-table
#
# TODO: Support for table headers and footers.
def initialize(table, options={}, &format)
@table = table
@padding = options[:padding] || 0
@align = options[:align]
@fit = options[:fit]
@border = options[:border]
#@ansi = [options[:ansi]].flatten
@format = format
@pad = " " * @padding
end
#
attr_accessor :table
# Fit to scree width.
attr_accessor :fit
#
attr_accessor :padding
#
attr_accessor :align
#
attr_accessor :format
#
attr_accessor :border
#
def to_s #(fit=false)
#row_count = table.size
#col_count = table[0].size
max = max_columns(fit)
div = dividing_line
top = div #.gsub('+', ".")
bot = div #.gsub('+', "'")
body = []
table.each_with_index do |row, r|
body_row = []
row.each_with_index do |cell, c|
t = cell_template(max[c])
s = t % cell.to_s
body_row << apply_format(s, cell, c, r)
end
body << "| " + body_row.join(' | ') + " |"
end
if border
body = body.join("\n#{div}\n")
else
body = body.join("\n")
end
"#{top}\n#{body}\n#{bot}\n"
end
private
# TODO: look at the lines and figure out how many columns will fit
def fit_width
width = Terminal.terminal_width
((width.to_f / column_size) - (padding + 3)).to_i
end
# Calculate the maximun column sizes.
#
# @return [Array] maximum size for each column
def max_columns(fit=false)
max = Array.new(column_size, 0)
table.each do |row|
row.each_with_index do |col, index|
col = col.to_s
col = col.unansi
if fit
max[index] = [max[index], col.size, fit_width].max
else
max[index] = [max[index], col.size].max
end
end
end
max
end
# Number of columns based on the first row of table.
#
# @return [Integer] number of columns
def column_size
table.first.size
end
#
def cell_template(max)
case align
when :right, 'right'
"#{@pad}%#{max}s"
else
"%-#{max}s#{@pad}"
end
end
# TODO: make more efficient
def dividing_line
tmp = max_columns(fit).map{ |m| "%#{m}s" }.join(" | ")
tmp = "| #{tmp} |"
lin = (tmp % (['-'] * column_size)).gsub(/[^\|]/, '-').gsub('|', '+')
lin
end
#def dividing_line_top
# dividing_line.gsub('+', '.')
#end
#def dividing_line_bottom
# dividing_line.gsub('+', "'")
#end
#
def apply_format(str, cell, col, row)
if @format
str.ansi(*ansi_formating(cell, col, row))
else
str
end
end
#
def ansi_formating(cell, col, row)
if @format
case @format.arity
when 0
f = @format[]
when 1
f = @format[cell]
when 2
f = @format[row, col]
else
f = @format[cell, row, col]
end
else
f = nil
end
[f].flatten.compact
end
end
end
ansi-1.5.0/lib/ansi/chain.rb 0000644 0000041 0000041 00000001200 12465501305 015600 0 ustar www-data www-data require 'ansi/code'
module ANSI
# ANSI::Chain was inspired by Kazuyoshi Tlacaelel's Isna library.
#
class Chain
#
def initialize(string)
@string = string.to_s
@codes = []
end
#
attr :string
#
attr :codes
#
def method_missing(s, *a, &b)
if ANSI::CHART.key?(s)
@codes << s
self
else
super(s, *a, &b)
end
end
#
def to_s
if codes.empty?
result = @string
else
result = Code.ansi(@string, *codes)
codes.clear
end
result
end
#
def to_str
to_s
end
end
end
ansi-1.5.0/lib/ansi/progressbar.rb 0000644 0000041 0000041 00000014430 12465501305 017060 0 ustar www-data www-data # Copyright (C) 2009 Thomas Sawyer
#
# This library is based on the original ProgressBar
# by Satoru Takabayashi.
#
# ProgressBar Copyright (C) 2001 Satoru Takabayashi
require 'ansi/code'
module ANSI
# = Progressbar
#
# Progressbar is a text-based progressbar library.
#
# pbar = Progressbar.new( "Demo", 100 )
# 100.times { pbar.inc }
# pbar.finish
#
class ProgressBar
#
def initialize(title, total, out=STDERR)
@title = title
@total = total
@out = out
@bar_length = 80
@bar_mark = "|"
@total_overflow = true
@current = 0
@previous = 0
@is_finished = false
@start_time = Time.now
@format = "%-14s %3d%% %s %s"
@format_arguments = [:title, :percentage, :bar, :stat]
@styles = {}
#
yield self if block_given?
#
show_progress
end
public
attr_accessor :format
attr_accessor :format_arguments
attr_accessor :styles
#
def title=(str)
@title = str
end
#
def bar_mark=(mark)
@bar_mark = String(mark)[0..0]
end
alias_method :barmark=, :bar_mark=
alias_method :mark=, :bar_mark=
def total_overflow=(boolv)
@total_overflow = boolv ? true : false
end
# Get rid of warning about Kenrel method being redefined.
remove_method :format
# Set format and format arguments.
def format(format, *arguments)
@format = format
@format_arguments = *arguments unless arguments.empty?
end
# Set ANSI styling options.
def style(options)
@styles = options
end
#
def standard_mode
@format = "%-14s %3d%% %s %s"
@format_arguments = [:title, :percentage, :bar, :stat]
end
#
def transfer_mode
@format = "%-14s %3d%% %s %s"
@format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
end
# For backward compatability
alias_method :file_transfer_mode, :transfer_mode
def finish
@current = @total
@is_finished = true
show_progress
end
def flush
@out.flush
end
def halt
@is_finished = true
show_progress
end
def set(count)
if count < 0
raise "invalid count less than zero: #{count}"
elsif count > @total
if @total_overflow
@total = count + 1
else
raise "invalid count greater than total: #{count}"
end
end
@current = count
show_progress
@previous = @current
end
#
def reset
@current = 0
@is_finished = false
end
#
def inc(step = 1)
@current += step
@current = @total if @current > @total
show_progress
@previous = @current
end
#
def clear
@out.print(" " * get_width + eol)
end
def inspect
"(ProgressBar: #{@current}/#{@total})"
end
private
#
def convert_bytes(bytes)
if bytes < 1024
sprintf("%6dB", bytes)
elsif bytes < 1024 * 1000 # 1000kb
sprintf("%5.1fKB", bytes.to_f / 1024)
elsif bytes < 1024 * 1024 * 1000 # 1000mb
sprintf("%5.1fMB", bytes.to_f / 1024 / 1024)
else
sprintf("%5.1fGB", bytes.to_f / 1024 / 1024 / 1024)
end
end
#
def transfer_rate
bytes_per_second = @current.to_f / (Time.now - @start_time)
sprintf("%s/s", convert_bytes(bytes_per_second))
end
#
def bytes
convert_bytes(@current)
end
#
def format_time(t)
t = t.to_i
sec = t % 60
min = (t / 60) % 60
hour = t / 3600
sprintf("%02d:%02d:%02d", hour, min, sec);
end
#
# ETA stands for Estimated Time of Arrival.
def eta
if @current == 0
"ETA: --:--:--"
else
elapsed = Time.now - @start_time
eta = elapsed * @total / @current - elapsed;
sprintf("ETA: %s", format_time(eta))
end
end
#
def elapsed
elapsed = Time.now - @start_time
sprintf("Time: %s", format_time(elapsed))
end
#
def stat
if @is_finished then elapsed else eta end
end
#
def stat_for_file_transfer
if @is_finished then
sprintf("%s %s %s", bytes, transfer_rate, elapsed)
else
sprintf("%s %s %s", bytes, transfer_rate, eta)
end
end
#
def eol
if @is_finished then "\n" else "\r" end
end
#
def bar
len = percentage * @bar_length / 100
sprintf("|%s%s|", @bar_mark * len, " " * (@bar_length - len))
end
#
def percentage
if @total.zero?
100
else
@current * 100 / @total
end
end
#
def title
@title[0,13] + ":"
end
# TODO: Use Terminal.terminal_width instead.
def get_width
# FIXME: I don't know how portable it is.
default_width = 80
begin
tiocgwinsz = 0x5413
data = [0, 0, 0, 0].pack("SSSS")
if @out.ioctl(tiocgwinsz, data) >= 0 then
#rows, cols, xpixels, ypixels = data.unpack("SSSS")
cols = data.unpack("SSSS")[1]
if cols >= 0 then cols else default_width end
else
default_width
end
rescue Exception
default_width
end
end
#
def show
arguments = @format_arguments.map do |method|
colorize(send(method), styles[method])
end
line = sprintf(@format, *arguments)
width = get_width
length = ANSI::Code.uncolor{line}.length
if length == width - 1
@out.print(line + eol)
elsif length >= width
@bar_length = [@bar_length - (length - width + 1), 0].max
@bar_length == 0 ? @out.print(line + eol) : show
else #line.length < width - 1
@bar_length += width - length + 1
show
end
end
#
def show_progress
if @total.zero?
cur_percentage = 100
prev_percentage = 0
else
cur_percentage = (@current * 100 / @total).to_i
prev_percentage = (@previous * 100 / @total).to_i
end
if cur_percentage > prev_percentage || @is_finished
show
end
end
#
def colorize(part, style)
return part unless style
#[style].flatten.inject(part){ |pt, st| ANSI::Code.ansi(pt, *st) }
ANSI::Code.ansi(part, *style)
end
end
#
Progressbar = ProgressBar #:nodoc:
end
ansi-1.5.0/lib/ansi/version.rb 0000644 0000041 0000041 00000000505 12465501305 016212 0 ustar www-data www-data module ANSI
# Returns Hash table of project metadata.
def self.metadata
@spec ||= (
require 'yaml'
YAML.load(File.new(File.dirname(__FILE__) + '/../ansi.yml'))
)
end
# Check metadata for missing constants.
def self.const_missing(name)
metadata[name.to_s.downcase] || super(name)
end
end
ansi-1.5.0/lib/ansi/code.rb 0000644 0000041 0000041 00000021320 12465501305 015435 0 ustar www-data www-data module ANSI
# Global variable can be used to prevent ANSI codes
# from being used in ANSI's methods that do so to string.
#
# NOTE: This has no effect on methods that return ANSI codes.
$ansi = true
if RUBY_PLATFORM =~ /(win32|w32)/
begin
require 'Win32/Console/ANSI'
rescue LoadError
warn "ansi: 'gem install win32console' to use color on Windows"
$ansi = false
end
end
require 'ansi/constants'
# TODO: up, down, right, left, etc could have yielding methods too?
# ANSI Codes
#
# Ansi::Code module makes it very easy to use ANSI codes.
# These are especially nice for beautifying shell output.
#
# Ansi::Code.red + "Hello" + Ansi::Code.blue + "World"
# => "\e[31mHello\e[34mWorld"
#
# Ansi::Code.red{ "Hello" } + Ansi::Code.blue{ "World" }
# => "\e[31mHello\e[0m\e[34mWorld\e[0m"
#
# IMPORTANT! Do not mixin Ansi::Code, instead use {ANSI::Mixin}.
#
# See {ANSI::CHART} for list of all supported codes.
#
module Code
extend self
# include ANSI Constants
include Constants
# Regexp for matching most ANSI codes.
PATTERN = /\e\[(\d+)m/
# ANSI clear code.
ENDCODE = "\e[0m"
# List of primary styles.
def self.styles
%w{bold dark italic underline underscore blink rapid reverse negative concealed strike}
end
# List of primary colors.
def self.colors
%w{black red green yellow blue magenta cyan white}
end
# Return ANSI code given a list of symbolic names.
def [](*codes)
code(*codes)
end
# Dynamically create color on color methods.
#
# @deprecated
#
colors.each do |color|
colors.each do |on_color|
module_eval <<-END, __FILE__, __LINE__
def #{color}_on_#{on_color}(string=nil)
if string
return string unless $ansi
#warn "use ANSI block notation for future versions"
return #{color.upcase} + ON_#{color.upcase} + string + ENDCODE
end
if block_given?
return yield unless $ansi
#{color.upcase} + ON_#{on_color.upcase} + yield.to_s + ENDCODE
else
#{color.upcase} + ON_#{on_color.upcase}
end
end
END
end
end
# Use method missing to dispatch ANSI code methods.
def method_missing(code, *args, &blk)
esc = nil
if CHART.key?(code)
esc = "\e[#{CHART[code]}m"
elsif SPECIAL_CHART.key?(code)
esc = SPECIAL_CHART[code]
end
if esc
if string = args.first
return string unless $ansi
#warn "use ANSI block notation for future versions"
return "#{esc}#{string}#{ENDCODE}"
end
if block_given?
return yield unless $ansi
return "#{esc}#{yield}#{ENDCODE}"
end
esc
else
super(code, *args, &blk)
end
end
# TODO: How to deal with position codes when $ansi is false?
# Should we raise an error or just not push the codes?
# For now, we will leave this it as is.
# Like +move+ but returns to original position after
# yielding the block.
def display(line, column=0) #:yield:
result = "\e[s"
result << "\e[#{line.to_i};#{column.to_i}H"
if block_given?
result << yield
result << "\e[u"
#elsif string
# result << string
# result << "\e[u"
end
result
end
# Move cursor to line and column.
def move(line, column=0)
"\e[#{line.to_i};#{column.to_i}H"
end
# Move cursor up a specified number of spaces.
def up(spaces=1)
"\e[#{spaces.to_i}A"
end
# Move cursor down a specified number of spaces.
def down(spaces=1)
"\e[#{spaces.to_i}B"
end
# Move cursor left a specified number of spaces.
def left(spaces=1)
"\e[#{spaces.to_i}D"
end
alias :back :left
# Move cursor right a specified number of spaces.
def right(spaces=1)
"\e[#{spaces.to_i}C"
end
alias :forward :right
##
#def position
# "\e[#;#R"
#end
# Apply ANSI codes to a first argument or block value.
#
# @example
# ansi("Valentine", :red, :on_white)
#
# @example
# ansi(:red, :on_white){ "Valentine" }
#
# @return [String]
# String wrapped ANSI code.
#
def ansi(*codes) #:yield:
if block_given?
string = yield.to_s
else
# first argument must be the string
string = codes.shift.to_s
end
return string unless $ansi
c = code(*codes)
c + string.gsub(ENDCODE, ENDCODE + c) + ENDCODE
end
# TODO: Allow selective removal using *codes argument?
# Remove ANSI codes from string or block value.
#
# @param [String] string
# String from which to remove ANSI codes.
#
# @return [String]
# String wrapped ANSI code.
#
def unansi(string=nil) #:yield:
if block_given?
string = yield.to_s
else
string = string.to_s
end
string.gsub(PATTERN, '')
end
# Alias for #ansi method.
#
# @deprecated
# Here for backward compatibility.
alias_method :style, :ansi
# Alias for #unansi method.
#
# @deprecated
# Here for backwards compatibility.
alias_method :unstyle, :unansi
# Alternate term for #ansi.
#
# @deprecated
# May change in future definition.
alias_method :color, :ansi
# Alias for unansi.
#
# @deprecated
# May change in future definition.
alias_method :uncolor, :unansi
# Look-up code from chart, or if Integer simply pass through.
# Also resolves :random and :on_random.
#
# @param codes [Array 255
v
end
end
#
extend Code
end
ansi-1.5.0/lib/ansi/core.rb 0000644 0000041 0000041 00000000533 12465501305 015456 0 ustar www-data www-data require 'ansi/code'
require 'ansi/chain'
class ::String
#
def ansi(*codes)
if codes.empty?
ANSI::Chain.new(self)
else
ANSI::Code.ansi(self, *codes)
end
end
#
def ansi!(*codes)
replace(ansi(*codes))
end
#
def unansi
ANSI::Code.unansi(self)
end
#
def unansi!
replace(unansi)
end
end
ansi-1.5.0/lib/ansi/terminal/ 0000755 0000041 0000041 00000000000 12465501305 016013 5 ustar www-data www-data ansi-1.5.0/lib/ansi/terminal/curses.rb 0000644 0000041 0000041 00000000614 12465501305 017645 0 ustar www-data www-data module ANSI
module Terminal
require 'curses'
module_function
#CHARACTER_MODE = "curses" # For Debugging purposes only.
#
# Curses savvy getc().
#
def get_character(input = STDIN)
Curses.getch()
end
def terminal_size
Curses.init_screen
w, r = Curses.cols, Curses.lines
Curses.close_screen
return w, r
end
end
end
ansi-1.5.0/lib/ansi/terminal/win32.rb 0000644 0000041 0000041 00000005731 12465501305 017310 0 ustar www-data www-data module ANSI
module Terminal
# Cygwin will look like Windows, but we want to treat it like a Posix OS:
raise LoadError, "Cygwin is a Posix OS." if RUBY_PLATFORM =~ /\bcygwin\b/i
require "Win32API" # See if we're on Windows.
module_function
#CHARACTER_MODE = "Win32API" # For Debugging purposes only.
#
# Windows savvy getc().
#
#
def get_character( input = STDIN )
@stdin_handle ||= GetStdHandle(STD_INPUT_HANDLE)
begin
SetConsoleEcho(@stdin_handle, false)
input.getc
ensure
SetConsoleEcho(@stdin_handle, true)
end
end
# A Windows savvy method to fetch the console columns, and rows.
def terminal_size
stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE)
bufx, bufy, curx, cury, wattr, left, top, right, bottom, maxx, maxy =
GetConsoleScreenBufferInfo(stdout_handle)
return right - left + 1, bottom - top + 1
end
# windows savvy console echo toggler
def SetConsoleEcho( console_handle, on )
mode = GetConsoleMode(console_handle)
# toggle the console echo bit
if on
mode |= ENABLE_ECHO_INPUT
else
mode &= ~ENABLE_ECHO_INPUT
end
ok = SetConsoleMode(console_handle, mode)
end
# win32 console APIs
STD_INPUT_HANDLE = -10
STD_OUTPUT_HANDLE = -11
STD_ERROR_HANDLE = -12
ENABLE_PROCESSED_INPUT = 0x0001
ENABLE_LINE_INPUT = 0x0002
ENABLE_WRAP_AT_EOL_OUTPUT = 0x0002
ENABLE_ECHO_INPUT = 0x0004
ENABLE_WINDOW_INPUT = 0x0008
ENABLE_MOUSE_INPUT = 0x0010
ENABLE_INSERT_MODE = 0x0020
ENABLE_QUICK_EDIT_MODE = 0x0040
@@apiGetStdHandle = nil
@@apiGetConsoleMode = nil
@@apiSetConsoleMode = nil
@@apiGetConsoleScreenBufferInfo = nil
def GetStdHandle( handle_type )
@@apiGetStdHandle ||= Win32API.new( "kernel32", "GetStdHandle",
['L'], 'L' )
@@apiGetStdHandle.call( handle_type )
end
def GetConsoleMode( console_handle )
@@apiGetConsoleMode ||= Win32API.new( "kernel32", "GetConsoleMode",
['L', 'P'], 'I' )
mode = ' ' * 4
@@apiGetConsoleMode.call(console_handle, mode)
mode.unpack('L')[0]
end
def SetConsoleMode( console_handle, mode )
@@apiSetConsoleMode ||= Win32API.new( "kernel32", "SetConsoleMode",
['L', 'L'], 'I' )
@@apiSetConsoleMode.call(console_handle, mode) != 0
end
def GetConsoleScreenBufferInfo( console_handle )
@@apiGetConsoleScreenBufferInfo ||=
Win32API.new( "kernel32", "GetConsoleScreenBufferInfo",
['L', 'P'], 'L' )
format = 'SSSSSssssSS'
buf = ([0] * format.size).pack(format)
@@apiGetConsoleScreenBufferInfo.call(console_handle, buf)
buf.unpack(format)
end
end
end
ansi-1.5.0/lib/ansi/terminal/stty.rb 0000644 0000041 0000041 00000002414 12465501305 017344 0 ustar www-data www-data module ANSI
module Terminal
module_function
#COLS_FALLBACK = 80
#ROWS_FALLBACK = 25
#CHARACTER_MODE = "stty" # For Debugging purposes only.
#
# Unix savvy getc(). (second choice)
#
# *WARNING*: This method requires the external "stty" program!
#
def get_character(input = STDIN)
raw_no_echo_mode
begin
input.getc
ensure
restore_mode
end
end
#
# Switched the input mode to raw and disables echo.
#
# *WARNING*: This method requires the external "stty" program!
#
def raw_no_echo_mode
@state = `stty -g`
system "stty raw -echo cbreak isig"
end
#
# Restores a previously saved input mode.
#
# *WARNING*: This method requires the external "stty" program!
#
def restore_mode
system "stty #{@state}"
end
# A Unix savvy method to fetch the console columns, and rows.
def terminal_size
if /solaris/ =~ RUBY_PLATFORM && (`stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/)
w, r = [$2, $1]
else
w, r = `stty size`.split.reverse
end
w = `tput cols` unless w # last ditch effort to at least get width
w = w.to_i if w
r = r.to_i if r
return w, r
end
end
end
ansi-1.5.0/lib/ansi/terminal/termios.rb 0000644 0000041 0000041 00000003342 12465501305 020024 0 ustar www-data www-data module ANSI
module Terminal
require "termios" # Unix, first choice.
module_function
#CHARACTER_MODE = "termios" # For Debugging purposes only.
#
# Unix savvy getc(). (First choice.)
#
# *WARNING*: This method requires the "termios" library!
#
def get_character( input = STDIN )
old_settings = Termios.getattr(input)
new_settings = old_settings.dup
new_settings.c_lflag &= ~(Termios::ECHO | Termios::ICANON)
new_settings.c_cc[Termios::VMIN] = 1
begin
Termios.setattr(input, Termios::TCSANOW, new_settings)
input.getc
ensure
Termios.setattr(input, Termios::TCSANOW, old_settings)
end
end
# A Unix savvy method to fetch the console columns, and rows.
def terminal_size
if /solaris/ =~ RUBY_PLATFORM && (`stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/)
w, r = [$2, $1]
else
w, r = `stty size`.split.reverse
end
w = `tput cols` unless w # last ditch effort to at least get width
w = w.to_i if w
r = r.to_i if r
return w, r
end
# Console screen width (taken from progress bar)
#
# NOTE: Don't know how portable #screen_width is.
# TODO: How to fit into system?
#
def screen_width(out=STDERR)
default_width = ENV['COLUMNS'] || 76
begin
tiocgwinsz = 0x5413
data = [0, 0, 0, 0].pack("SSSS")
if out.ioctl(tiocgwinsz, data) >= 0 then
rows, cols, xpixels, ypixels = data.unpack("SSSS")
if cols >= 0 then cols else default_width end
else
default_width
end
rescue Exception
default_width
end
end
end
end
ansi-1.5.0/lib/ansi/constants.rb 0000644 0000041 0000041 00000001021 12465501305 016533 0 ustar www-data www-data module ANSI
require 'ansi/chart'
# Converts {CHART} and {SPECIAL_CHART} entries into constants.
# So for example, the CHART entry for :red becomes:
#
# ANSI::Constants::RED #=> "\e[31m"
#
# The ANSI Constants are include into ANSI::Code and can be included
# any where will they would be of use.
#
module Constants
CHART.each do |name, code|
const_set(name.to_s.upcase, "\e[#{code}m")
end
SPECIAL_CHART.each do |name, code|
const_set(name.to_s.upcase, code)
end
end
end
ansi-1.5.0/lib/ansi/mixin.rb 0000644 0000041 0000041 00000014301 12465501305 015650 0 ustar www-data www-data module ANSI
require 'ansi/code'
# This module is designed specifically for mixing into
# String-like classes or extending String-like objects.
#
# Generally speaking the String#ansi method is the more
# elegant approach to modifying a string with codes
# via a method call. But in some cases this Mixin's design
# might be preferable. Indeed, it original intent was
# as a compatability layer for the +colored+ gem.
module Mixin
def bold ; ANSI::Code.bold { to_s } ; end
def dark ; ANSI::Code.dark { to_s } ; end
def italic ; ANSI::Code.italic { to_s } ; end
def underline ; ANSI::Code.underline { to_s } ; end
def underscore ; ANSI::Code.underscore { to_s } ; end
def blink ; ANSI::Code.blink { to_s } ; end
def rapid ; ANSI::Code.rapid { to_s } ; end
def reverse ; ANSI::Code.reverse { to_s } ; end
def negative ; ANSI::Code.negative { to_s } ; end
def concealed ; ANSI::Code.concealed { to_s } ; end
def strike ; ANSI::Code.strike { to_s } ; end
def black ; ANSI::Code.black { to_s } ; end
def red ; ANSI::Code.red { to_s } ; end
def green ; ANSI::Code.green { to_s } ; end
def yellow ; ANSI::Code.yellow { to_s } ; end
def blue ; ANSI::Code.blue { to_s } ; end
def magenta ; ANSI::Code.magenta { to_s } ; end
def cyan ; ANSI::Code.cyan { to_s } ; end
def white ; ANSI::Code.white { to_s } ; end
def on_black ; ANSI::Code.on_black { to_s } ; end
def on_red ; ANSI::Code.on_red { to_s } ; end
def on_green ; ANSI::Code.on_green { to_s } ; end
def on_yellow ; ANSI::Code.on_yellow { to_s } ; end
def on_blue ; ANSI::Code.on_blue { to_s } ; end
def on_magenta ; ANSI::Code.on_magenta { to_s } ; end
def on_cyan ; ANSI::Code.on_cyan { to_s } ; end
def on_white ; ANSI::Code.on_white { to_s } ; end
def black_on_red ; ANSI::Code.black_on_red { to_s } ; end
def black_on_green ; ANSI::Code.black_on_green { to_s } ; end
def black_on_yellow ; ANSI::Code.black_on_yellow { to_s } ; end
def black_on_blue ; ANSI::Code.black_on_blue { to_s } ; end
def black_on_magenta ; ANSI::Code.black_on_magenta { to_s } ; end
def black_on_cyan ; ANSI::Code.black_on_cyan { to_s } ; end
def black_on_white ; ANSI::Code.black_on_white { to_s } ; end
def red_on_black ; ANSI::Code.red_on_black { to_s } ; end
def red_on_green ; ANSI::Code.red_on_green { to_s } ; end
def red_on_yellow ; ANSI::Code.red_on_yellow { to_s } ; end
def red_on_blue ; ANSI::Code.red_on_blue { to_s } ; end
def red_on_magenta ; ANSI::Code.red_on_magenta { to_s } ; end
def red_on_cyan ; ANSI::Code.red_on_cyan { to_s } ; end
def red_on_white ; ANSI::Code.red_on_white { to_s } ; end
def green_on_black ; ANSI::Code.green_on_black { to_s } ; end
def green_on_red ; ANSI::Code.green_on_red { to_s } ; end
def green_on_yellow ; ANSI::Code.green_on_yellow { to_s } ; end
def green_on_blue ; ANSI::Code.green_on_blue { to_s } ; end
def green_on_magenta ; ANSI::Code.green_on_magenta { to_s } ; end
def green_on_cyan ; ANSI::Code.green_on_cyan { to_s } ; end
def green_on_white ; ANSI::Code.green_on_white { to_s } ; end
def yellow_on_black ; ANSI::Code.yellow_on_black { to_s } ; end
def yellow_on_red ; ANSI::Code.yellow_on_red { to_s } ; end
def yellow_on_green ; ANSI::Code.yellow_on_green { to_s } ; end
def yellow_on_blue ; ANSI::Code.yellow_on_blue { to_s } ; end
def yellow_on_magenta ; ANSI::Code.yellow_on_magenta { to_s } ; end
def yellow_on_cyan ; ANSI::Code.yellow_on_cyan { to_s } ; end
def yellow_on_white ; ANSI::Code.yellow_on_white { to_s } ; end
def blue_on_black ; ANSI::Code.blue_on_black { to_s } ; end
def blue_on_red ; ANSI::Code.blue_on_red { to_s } ; end
def blue_on_green ; ANSI::Code.blue_on_green { to_s } ; end
def blue_on_yellow ; ANSI::Code.blue_on_yellow { to_s } ; end
def blue_on_magenta ; ANSI::Code.blue_on_magenta { to_s } ; end
def blue_on_cyan ; ANSI::Code.blue_on_cyan { to_s } ; end
def blue_on_white ; ANSI::Code.blue_on_white { to_s } ; end
def magenta_on_black ; ANSI::Code.magenta_on_black { to_s } ; end
def magenta_on_red ; ANSI::Code.magenta_on_red { to_s } ; end
def magenta_on_green ; ANSI::Code.magenta_on_green { to_s } ; end
def magenta_on_yellow ; ANSI::Code.magenta_on_yellow { to_s } ; end
def magenta_on_blue ; ANSI::Code.magenta_on_blue { to_s } ; end
def magenta_on_cyan ; ANSI::Code.magenta_on_cyan { to_s } ; end
def magenta_on_white ; ANSI::Code.magenta_on_white { to_s } ; end
def cyan_on_black ; ANSI::Code.cyan_on_black { to_s } ; end
def cyan_on_red ; ANSI::Code.cyan_on_red { to_s } ; end
def cyan_on_green ; ANSI::Code.cyan_on_green { to_s } ; end
def cyan_on_yellow ; ANSI::Code.cyan_on_yellow { to_s } ; end
def cyan_on_blue ; ANSI::Code.cyan_on_blue { to_s } ; end
def cyan_on_magenta ; ANSI::Code.cyan_on_magenta { to_s } ; end
def cyan_on_white ; ANSI::Code.cyan_on_white { to_s } ; end
def white_on_black ; ANSI::Code.white_on_black { to_s } ; end
def white_on_red ; ANSI::Code.white_on_red { to_s } ; end
def white_on_green ; ANSI::Code.white_on_green { to_s } ; end
def white_on_yellow ; ANSI::Code.white_on_yellow { to_s } ; end
def white_on_blue ; ANSI::Code.white_on_blue { to_s } ; end
def white_on_magenta ; ANSI::Code.white_on_magenta { to_s } ; end
def white_on_cyan ; ANSI::Code.white_on_cyan { to_s } ; end
# Move cursor to line and column, insert +self.to_s+ and return to
# original positon.
def display(line, column=0)
result = "\e[s"
result << "\e[#{line.to_i};#{column.to_i}H"
result << to_s
result << "\e[u"
result
end
end
end
ansi-1.5.0/lib/ansi.yml 0000644 0000041 0000041 00000002767 12465501305 014737 0 ustar www-data www-data ---
revision: 2013
type: ruby
sources:
- INDEX.yml
authors:
- name: Thomas Sawyer
email: transfire@gmail.com
- name: Florian Frank
organizations: []
requirements:
- groups:
- build
development: true
name: mast
- groups:
- build
development: true
name: indexer
- groups:
- build
development: true
name: ergo
- groups:
- test
development: true
name: qed
- groups:
- test
development: true
name: ae
- groups:
- test
development: true
name: lemon
conflicts: []
alternatives: []
resources:
- type: home
uri: http://rubyworks.github.com/ansi
label: Homepage
- type: docs
uri: http://rubydoc.info/gems/ansi/frames
label: Documentation
- type: code
uri: http://github.com/rubyworks/ansi
label: Source Code
- type: bugs
uri: http://github.com/rubyworks/ansi/issues
label: Issue Tracker
- type: mail
uri: http://groups.google.com/group/rubyworks-mailinglist
label: Mailing List
repositories:
- name: upstream
scm: git
uri: git://github.com/rubyworks/ansi.git
categories: []
copyrights:
- holder: Rubyworks
year: '2009'
license: BSD-2-Clause
customs: []
paths:
lib:
- lib
name: ansi
title: ANSI
version: 1.5.0
summary: ANSI at your fingertips!
description: The ANSI project is a superlative collection of ANSI escape code related
libraries eabling ANSI colorization and stylization of console output. Byte for
byte ANSI is the best ANSI code library available for the Ruby programming language.
orgranizations:
- Rubyworks
created: '2009-08-01'
date: '2015-01-16'
ansi-1.5.0/lib/ansi.rb 0000644 0000041 0000041 00000000652 12465501305 014530 0 ustar www-data www-data # ANSI namespace module contains all the ANSI related classes.
module ANSI
end
require 'ansi/version'
require 'ansi/core'
require 'ansi/code'
require 'ansi/bbcode'
require 'ansi/columns'
require 'ansi/diff'
require 'ansi/logger'
require 'ansi/mixin'
require 'ansi/progressbar'
require 'ansi/string'
require 'ansi/table'
require 'ansi/terminal'
# Kernel method
def ansi(string, *codes)
ANSI::Code.ansi(string, *codes)
end
ansi-1.5.0/metadata.yml 0000644 0000041 0000041 00000010507 12465501305 015006 0 ustar www-data www-data --- !ruby/object:Gem::Specification
name: ansi
version: !ruby/object:Gem::Version
version: 1.5.0
platform: ruby
authors:
- Thomas Sawyer
- Florian Frank
autorequire:
bindir: bin
cert_chain: []
date: 2015-01-17 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: mast
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
name: indexer
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
name: ergo
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
name: qed
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
name: ae
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
name: lemon
requirement: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
description: The ANSI project is a superlative collection of ANSI escape code related
libraries eabling ANSI colorization and stylization of console output. Byte for
byte ANSI is the best ANSI code library available for the Ruby programming language.
email:
- transfire@gmail.com
executables: []
extensions: []
extra_rdoc_files:
- LICENSE.txt
- NOTICE.md
- README.md
- HISTORY.md
- DEMO.md
files:
- .index
- .yardopts
- lib/ansi/bbcode.rb
- lib/ansi/chain.rb
- lib/ansi/chart.rb
- lib/ansi/code.rb
- lib/ansi/columns.rb
- lib/ansi/constants.rb
- lib/ansi/core.rb
- lib/ansi/diff.rb
- lib/ansi/hexdump.rb
- lib/ansi/logger.rb
- lib/ansi/mixin.rb
- lib/ansi/progressbar.rb
- lib/ansi/string.rb
- lib/ansi/table.rb
- lib/ansi/terminal/curses.rb
- lib/ansi/terminal/stty.rb
- lib/ansi/terminal/termios.rb
- lib/ansi/terminal/win32.rb
- lib/ansi/terminal.rb
- lib/ansi/version.rb
- lib/ansi.rb
- lib/ansi.yml
- demo/01_ansicode.md
- demo/02_core.md
- demo/03_logger.md
- demo/04_progressbar.md
- demo/05_mixin.md
- demo/06_string.md
- demo/07_columns.md
- demo/08_table.md
- demo/09_diff.md
- demo/10_bbcode.md
- demo/11_terminal.md
- demo/applique/ae.rb
- demo/applique/output.rb
- test/case_ansicode.rb
- test/case_bbcode.rb
- test/case_mixin.rb
- test/case_progressbar.rb
- test/test_helper.rb
- NOTICE.md
- README.md
- HISTORY.md
- DEMO.md
- LICENSE.txt
homepage: http://rubyworks.github.com/ansi
licenses:
- BSD-2-Clause
metadata: {}
post_install_message:
rdoc_options: []
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
required_rubygems_version: !ruby/object:Gem::Requirement
requirements:
- - '>='
- !ruby/object:Gem::Version
version: '0'
requirements: []
rubyforge_project:
rubygems_version: 2.0.3
signing_key:
specification_version: 4
summary: ANSI at your fingertips!
test_files:
- test/case_bbcode.rb
- test/case_progressbar.rb
- test/case_ansicode.rb
- test/case_mixin.rb
- test/test_helper.rb
has_rdoc:
ansi-1.5.0/test/ 0000755 0000041 0000041 00000000000 12465501305 013457 5 ustar www-data www-data ansi-1.5.0/test/case_ansicode.rb 0000644 0000041 0000041 00000001277 12465501305 016573 0 ustar www-data www-data require 'test_helper'
require 'ansi/code'
testcase ANSI::Code do
method :red do
test do
str = ANSI::Code.red
out = "\e[31m"
out.assert == str
end
test "with block notation" do
str = ANSI::Code.red { "Hello" }
out = "\e[31mHello\e[0m"
out.assert == str
end
end
method :blue do
test do
str = ANSI::Code.blue
out = "\e[34m"
out.assert == str
end
test "with block notation" do
str = ANSI::Code.blue { "World" }
out = "\e[34mWorld\e[0m"
out.assert == str
end
end
method :hex do
test do
str = ANSI::Code.hex("#000000")
out = "0"
out.assert == str
end
end
end
ansi-1.5.0/test/case_bbcode.rb 0000644 0000041 0000041 00000002161 12465501305 016215 0 ustar www-data www-data require 'test_helper'
require 'ansi/bbcode'
testcase ANSI::BBCode do
class_method :bbcode_to_ansi do
test do
str = "this is [COLOR=red]red[/COLOR], this is [B]bold[/B]"
out = "this is \e[0;31mred\e[0m, this is \e[1mbold\e[0m\n"
out.assert == ANSI::BBCode.bbcode_to_ansi(str)
end
end
class_method :bbcode_to_html do
test do
str = "this is [COLOR=red]red[/COLOR], this is [B]bold[/B]"
out = "this is red, this is bold
\n"
out.assert == ANSI::BBCode.bbcode_to_html(str)
end
end
class_method :ansi_to_html do
test do
str = "this is \e[0;31mred\e[0m, this is \e[1mbold\e[0m\n" +
"this is a line without any ansi code\n" +
"this is \e[0;31mred\e[0m, this is \e[1mbold\e[0m\n"
out = "this is red, this is bold
\n" +
"this is a line without any ansi code
\n" +
"this is red, this is bold
\n"
out.assert == ANSI::BBCode.ansi_to_html(str)
end
end
end
ansi-1.5.0/test/case_progressbar.rb 0000644 0000041 0000041 00000000576 12465501305 017340 0 ustar www-data www-data require 'test_helper'
require 'stringio'
require 'ansi/progressbar'
testcase ANSI::Progressbar do
method :initialize do
test do
stio = StringIO.new
pbar = ANSI::Progressbar.new("Test Bar", 10, stio) do |b|
b.style(:title => [:red], :bar=>[:blue])
end
10.times do |i|
sleep 0.1
pbar.inc
end
true
end
end
end
ansi-1.5.0/test/test_helper.rb 0000644 0000041 0000041 00000000036 12465501305 016321 0 ustar www-data www-data require 'lemon'
require 'ae'
ansi-1.5.0/test/case_mixin.rb 0000644 0000041 0000041 00000001022 12465501305 016116 0 ustar www-data www-data require 'test_helper'
require 'ansi/mixin'
testcase ANSI::Mixin do
# TODO: subclass
class ::String
include ANSI::Mixin
end
method :red do
test do
str = "Hello".red
out = "\e[31mHello\e[0m"
out.assert == str
end
end
method :blue do
test do
str = "World".blue
out = "\e[34mWorld\e[0m"
out.assert == str
end
end
method :display do
test do
str = "Hello".display(4,10)
out = "\e[s\e[4;10HHello\e[u"
out.assert == str
end
end
end
ansi-1.5.0/.yardopts 0000644 0000041 0000041 00000000074 12465501305 014347 0 ustar www-data www-data --title ANSI
--protected
--private
lib
-
QED.rdoc
[A-Z]*.*
ansi-1.5.0/NOTICE.md 0000644 0000041 0000041 00000015073 12465501305 014011 0 ustar www-data www-data # COPYRIGHT NOTICES
## ANSI
Copyright © 2009 [Rubyworks](http://rubyworks.github.com) ·
License [BSD-2-Clause](http://spdx.org/licenses/BSD-2-Clause) ·
Website http://rubyworks.github.com/ansi
Copyright 2009 Rubyworks.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(https://raw.github.com/rubyworks/ansi/master/LICENSE.txt)
## ProgressBar
Copyright © 2001 *Satoru Takabayashi* ·
License [Ruby](http://spdx.org/licenses/Ruby) ·
Website http://0xcc.net/ruby-progressbar
ProgressBar class is based on the original ProgressBar by Satoru Takabayashi.
Ruby/ProgressBar - a text progress bar library
Copyright (C) 2001-2005 Satoru Takabayashi
All rights reserved.
This is free software with ABSOLUTELY NO WARRANTY.
You can redistribute it and/or modify it under the terms
of Ruby's license.
## HighLine (Terminal Extensions)
Copyright © 2006 *Gray Productions* ·
License [Ruby](http://spdx.org/licenses/Ruby) ·
Website http://highline.rubyforge.org
The terminal extensions are based on HighLine's SystemExtensions
by James Edward Gray II.
Copyright 2006 Gray Productions
Distributed under the user's choice of the {GPL Version 2}[http://www.gnu.org/licenses/old-licenses/gpl-2.0.html]
(see GPL-2.0.txt for details) or the {Ruby software license}[http://www.ruby-lang.org/en/LICENSE.txt]
by James Edward Gray II and Greg Brown.
Please email James[mailto:james@grayproductions.net] with any questions.
(https://github.com/JEG2/highline/blob/master/LICENSE)
## BBCode
Copyright © 2002 *Thomas-Ivo Heinen* ·
License [Ruby](http://spdx.org/licenses/Ruby)
BBCode module is a derivative of BBCode by Thomas-Ivo Heinen.
Copyright (c) 2002 Thomas-Ivo Heinen
This module is free software. You may use, modify, and/or redistribute this
software under the same terms as Ruby.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.
## Rainbow (XTerm Color Support)
Copyright © *Marcin Kulik* ·
License [MIT](http://spdx.org/licenses/MIT) ·
Website http://github.com/sickill/rainbow
Rainbox provided the bases for building the XTerm 256 color code
support into the ANSI::Code module.
Copyright (c) Marcin Kulik
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.
(https://raw.github.com/sickill/rainbow/master/LICENSE)
## Paint (ANSI Code Names)
Copyright © 2011 *Jan Lelis* ·
License [MIT](http://spdx.org/licenses/MIT) ·
Website https://github.com/janlelis/paint
Some of the latest ANSI code names, and inspiration to check out Rainbow
and include XTerm 256 color codes, came from Paint.
Copyright (c) 2011 Jan Lelis
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.
(https://raw.github.com/janlelis/paint/master/LICENSE.txt)
## ANSIColor
_Acknowlegement_
Copyright © 2002 *Florian Frank* ·
Website http://flori.github.com/term-ansicolor
Albeit the code no long bares much, if any, resemblance to it, the ANSI Code
module (and subsequently the Constants module) originated with the
ANSIColor library by Florian Frank.
Copyright (c) 2002 Florian Frank
ansi-1.5.0/README.md 0000644 0000041 0000041 00000004764 12465501305 013772 0 ustar www-data www-data # ANSI
[HOME](http://rubyworks.github.com/ansi) ·
[API](http://rubydoc.info/gems/ansi/frames) ·
[MAIL](http://googlegroups.com/group/rubyworks-mailinglist) ·
[ISSUES](http://github.com/rubyworks/ansi/issues) ·
[SOURCE](http://github.com/rubyworks/ansi)
[](http://travis-ci.org/rubyworks/ansi)
The ANSI project is a collection of ANSI escape code related libraries
enabling ANSI code based colorization and stylization of output.
It is very nice for beautifying shell output.
This collection is based on a set of scripts spun-off from
Ruby Facets. Included are Code (used to be ANSICode), Logger,
ProgressBar and String. In addition the library includes
Terminal which provides information about the current output
device.
## Features
* ANSI::Code provides ANSI codes as module functions.
* String#ansi makes common usage very easy and elegant.
* ANSI::Mixin provides an alternative mixin (like +colored+ gem).
* Very Good coverage of standard ANSI codes.
* Additional clases for colorized columns, tables, loggers and more.
## Synopsis
There are a number of modules and classes provided by the ANSI
package. To get a good understanding of them it is best to pursue
the [QED documents](http://github.com/rubyworks/ansi/tree/master/qed/)
or the [API documentation](http://rubyworks.github.com/ansi/api/index.html).
At the heart of all the provided libraries lies the ANSI::Code module
which defines ANSI codes as constants and methods. For example:
require 'ansi/code'
ANSI.red + "Hello" + ANSI.blue + "World"
=> "\e[31mHello\e[34mWorld"
Or in block form.
ANSI.red{ "Hello" } + ANSI.blue{ "World" }
=> "\e[31mHello\e[0m\e[34mWorld\e[0m"
The methods defined by this module are used throughout the rest of
the system.
## Installation
### RubyGems
To install with RubyGems simply open a console and type:
$ sudo gem install ansi
### Setup.rb (not recommended)
Local installation requires Setup.rb (gem install setup),
then [download](http://github.com/rubyworks/ansi/download) the tarball package and type:
$ tar -xvzf ansi-1.0.0.tgz
$ cd ansi-1.0.0
$ sudo setup.rb all
Windows users use 'ruby setup.rb all'.
## Release Notes
Please see HISTORY.md file.
## License & Copyrights
Copyright (c) 2009 Rubyworks
This program is redistributable under the terms of the *FreeBSD* license.
Some pieces of the code are copyrighted by others.
See LICENSE.txt and NOTICE.md files for details.