Permalink
Browse files

Initial commit to formatador.

  • Loading branch information...
0 parents commit e1a3757d86987c39ac48852161eae02d71379e92 Wesley Beary committed Nov 25, 2009
Showing with 173 additions and 0 deletions.
  1. +5 −0 .document
  2. +21 −0 .gitignore
  3. +28 −0 README.rdoc
  4. +49 −0 Rakefile
  5. +57 −0 lib/formatador.rb
  6. +8 −0 tests/formatador_tests.rb
  7. +5 −0 tests/tests_helper.rb
@@ -0,0 +1,5 @@
+README.rdoc
+lib/**/*.rb
+bin/*
+features/**/*.feature
+LICENSE
@@ -0,0 +1,21 @@
+## MAC OS
+.DS_Store
+
+## TEXTMATE
+*.tmproj
+tmtags
+
+## EMACS
+*~
+\#*
+.\#*
+
+## VIM
+*.swp
+
+## PROJECT::GENERAL
+coverage
+rdoc
+pkg
+
+## PROJECT::SPECIFIC
@@ -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.
@@ -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
@@ -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
@@ -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
@@ -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.