Skip to content

Commit

Permalink
Initial commit to formatador.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wesley Beary committed Nov 25, 2009
0 parents commit e1a3757
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .document
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,5 @@
README.rdoc
lib/**/*.rb
bin/*
features/**/*.feature
LICENSE
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,21 @@
## MAC OS
.DS_Store

## TEXTMATE
*.tmproj
tmtags

## EMACS
*~
\#*
.\#*

## VIM
*.swp

## PROJECT::GENERAL
coverage
rdoc
pkg

## PROJECT::SPECIFIC
28 changes: 28 additions & 0 deletions README.rdoc
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,28 @@
= formatador

STDOUT text formatting

== Copyright

(The MIT License)

Copyright (c) 2009 {geemus (Wesley Beary)}[http://github.com/geemus]

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.
49 changes: 49 additions & 0 deletions Rakefile
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'rubygems'
require 'rake'

begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "formatador"
gem.summary = %Q{TODO: one-line summary of your gem}
gem.description = %Q{TODO: longer description of your gem}
gem.email = "wbeary@engineyard.com"
gem.homepage = "http://github.com/geemus/formatador"
gem.authors = ["Wesley Beary"]
gem.add_development_dependency "shindo", ">= 0"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end

require 'shindo/rake'
Shindo::Rake.new

begin
require 'rcov/rcovtask'
Rcov::RcovTask.new do |tests|
tests.libs << 'tests'
tests.pattern = 'tests/**/*_tests.rb'
tests.verbose = true
end
rescue LoadError
task :rcov do
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
end
end

task :tests => :check_dependencies

task :default => :tests

require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "formatador #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
57 changes: 57 additions & 0 deletions lib/formatador.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,57 @@
class Formatador

STYLES = {
:reset => "\e[0m",
:bold => "\e[1m",
:underline => "\e[4m",
:blink_slow => "\e[5m",
:blink_fast => "\e[6m",
:negative => "\e[7m", # invert color/background_color
:normal => "\e[22m",
:underline_none => "\e[24m",
:blink_off => "\e[25m",
:positive => "\e[27m", # revert color/background_color
:foreground_black => "\e[30m",
:foreground_red => "\e[31m",
:foreground_green => "\e[32m",
:foreground_yellow => "\e[33m",
:foreground_blue => "\e[34m",
:foreground_magenta => "\e[35m",
:foreground_cyan => "\e[36m",
:foreground_white => "\e[37m",
:background_black => "\e[40m",
:background_red => "\e[41m",
:background_green => "\e[42m",
:background_yellow => "\e[43m",
:background_blue => "\e[44m",
:background_magenta => "\e[45m",
:background_cyan => "\e[46m",
:background_white => "\e[47m"
}

def display(string, styles = [])
print(format(string, [*styles]))
end

def display_line(string, styles = [])
display(string, styles)
print("\n")
end

def format(string, styles, reset = true)
if STDOUT.tty? && !styles.empty?
formated = ''
for style in styles
formated << STYLES[style]
end
formated << string
if reset
formated << STYLES[:reset]
end
formated
else
string
end
end

end
8 changes: 8 additions & 0 deletions tests/formatador_tests.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,8 @@
require File.expand_path(File.dirname(__FILE__) + '/tests_helper')

Shindo.tests("Formatador") do
test("fails") do
"hey buddy, you should probably rename this file and start specing for real"
false
end
end
5 changes: 5 additions & 0 deletions tests/tests_helper.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,5 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'formatador'
require 'rubygems'
require 'shindo'

0 comments on commit e1a3757

Please sign in to comment.