geek_painter 0.0.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/README.rdoc CHANGED
@@ -1,11 +1,15 @@
1
- = geek painter
1
+ == Geek Painter
2
2
 
3
3
  A very simple DSL to generate a colored shell prompt to use in *nix OS
4
4
 
5
+ == Installation
6
+
7
+ gem install geek_painter
8
+
5
9
  == Usage
6
10
 
7
11
  #put the following lines in a file (ie. geek_painter_client.rb or whatever you want)
8
- painting = GeekPainter.new.paint do
12
+ painting = GeekPainter.paint do
9
13
  trace "[".in :brown
10
14
  trace "\\u".in :red
11
15
  trace ":".in :yellow
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "geek_painter"
8
+ gem.summary = %Q{A very simple DSL to generate a colored shell prompt string to use in *nix OS terminals}
9
+ gem.description = %Q{A very simple DSL to generate a colored shell prompt string to use in *nix OS terminals. it might be used to generate a valid string to be used as a prompt or to generated strings that represent colored text on a terminal.}
10
+ gem.email = "raf.magana@gmail.com"
11
+ gem.homepage = "http://github.com/rafmagana/geek_painter"
12
+ gem.authors = ["Rafael Magana"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "geek_painter #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.1
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{geek_painter}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Rafael Magana"]
12
+ s.date = %q{2010-04-03}
13
+ s.description = %q{A very simple DSL to generate a colored shell prompt string to use in *nix OS terminals. it might be used to generate a valid string to be used as a prompt or to generated strings that represent colored text on a terminal.}
14
+ s.email = %q{raf.magana@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "geek_painter.gemspec",
27
+ "geek_painter_client.rb",
28
+ "lib/geek_painter.rb",
29
+ "lib/geek_painter/canvas.rb",
30
+ "lib/geek_painter/escaping_tools.rb",
31
+ "lib/geek_painter/palette.rb",
32
+ "lib/geek_painter/string.rb",
33
+ "test/helper.rb",
34
+ "test/test_geek_painter.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/rafmagana/geek_painter}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.6}
40
+ s.summary = %q{A very simple DSL to generate a colored shell prompt string to use in *nix OS terminals}
41
+ s.test_files = [
42
+ "test/helper.rb",
43
+ "test/test_geek_painter.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
57
+ end
58
+ end
59
+
@@ -1,4 +1,5 @@
1
- require "lib/geek_painter"
1
+ require "rubygems"
2
+ require "geek_painter"
2
3
 
3
4
  painting = GeekPainter.paint do
4
5
  trace "[".in :brown
@@ -12,4 +13,7 @@ painting = GeekPainter.paint do
12
13
  end
13
14
 
14
15
  painting.print_raw
15
- #painting.show
16
+ # >>
17
+ # >> \[\033[0;33m\][\[\033[0;31m\]\u\[\033[1;33m\]:\[\033[0;31m\]\h\[\033[0;35m\]] \[\033[0m\]\w \[\033[1;33m\]$(__git_ps1)\[\033[0m\] $ \[\033[0m\]
18
+ # >>
19
+ # >> copy the string above and put it in your ~/.bashrc or ~/.bash_profile like this => PS1='the_string'
@@ -0,0 +1,43 @@
1
+ module GeekPainter
2
+ #
3
+ # The main DSL, every single call to the "trace" method pushes the parameters to an array
4
+ # and "raw" method then joins the array to generate the actual string to be used in PS1 or wherever.
5
+ #
6
+ # ie. canvas = Canvas.new
7
+ # canvas.trace "\\[\\033[33m\\]user:" => yellow text
8
+ # canvas.trace "\\[\\033[34m\\]host" => blue text
9
+ # canvas.show => \\[\\033[33m\\]user:\\[\\033[34m\\]host => user:host
10
+
11
+ class Canvas
12
+ include EscapingTools
13
+
14
+ def initialize
15
+ @traces = []
16
+ end
17
+
18
+ def trace(string)
19
+ add_trace(string)
20
+ end
21
+
22
+ def raw
23
+ @traces << escape_char("0")
24
+ @traces.join("")
25
+ end
26
+
27
+ def print_raw
28
+ puts ""
29
+ puts raw
30
+ puts ""
31
+ puts "copy the string above and put it in your ~/.bashrc or ~/.bash_profile like this => PS1='the_string'"
32
+ end
33
+
34
+ def show
35
+ puts raw
36
+ end
37
+
38
+ protected
39
+ def add_trace(trace)
40
+ @traces << trace
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,15 @@
1
+ module GeekPainter
2
+ module EscapingTools
3
+ def open_esc_char
4
+ "\\[\\033["
5
+ end
6
+
7
+ def close_esc_char
8
+ "m\\]"
9
+ end
10
+
11
+ def escape_char(char)
12
+ open_esc_char + char + close_esc_char
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,34 @@
1
+ module GeekPainter
2
+ #
3
+ # The palette of colors
4
+ #
5
+ class Palette
6
+ extend EscapingTools
7
+ def self.grab_escaped(color_name)
8
+ case color_name
9
+ when :black then escape "0;30"
10
+ when :dark_gray then escape "1;30"
11
+ when :light_gray then escape "1;37"
12
+ when :red then escape "0;31"
13
+ when :light_red then escape "1;31"
14
+ when :green then escape "0;32"
15
+ when :light_green then escape "1;32"
16
+ when :yellow then escape "1;33"
17
+ when :brown then escape "0;33"
18
+ when :blue then escape "0;34"
19
+ when :light_blue then escape "1;34"
20
+ when :magenta then escape "0;35"
21
+ when :light_magenta then escape "1;35"
22
+ when :cyan then escape "0;36"
23
+ when :light_cyan then escape "1;36;5"
24
+ when :white then escape "1;37"
25
+ when :default then escape "0"
26
+ end
27
+ end
28
+
29
+ private
30
+ def self.escape(color_code)
31
+ self.escape_char(color_code.to_s)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,22 @@
1
+ #
2
+ # Extend String to help the DSL to be more readable
3
+ # adds a "in" method to specify the color of the text
4
+ # ie. "my_text".in :red
5
+ #
6
+ module GeekPainter
7
+ module RubyCoreExtensions
8
+ module String
9
+ def in(color_name)
10
+ Palette.grab_escaped(color_name) + self.to_s
11
+ end
12
+
13
+ def reset
14
+ self + escape_char("0")
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ String.class_eval do
21
+ include GeekPainter::RubyCoreExtensions::String
22
+ end
@@ -0,0 +1,12 @@
1
+ require 'geek_painter/escaping_tools'
2
+ require 'geek_painter/string'
3
+ require 'geek_painter/palette'
4
+ require 'geek_painter/canvas'
5
+
6
+ module GeekPainter
7
+ def self.paint(&block)
8
+ @canvas = Canvas.new
9
+ @canvas.instance_eval(&block)
10
+ @canvas
11
+ end
12
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 0
8
- - 0
9
- version: 0.0.0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Rafael Magana
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: "0"
30
30
  type: :development
31
31
  version_requirements: *id001
32
- description: A very simple DSL to generate a colored shell prompt string to use in *nix OS terminals
32
+ description: A very simple DSL to generate a colored shell prompt string to use in *nix OS terminals. it might be used to generate a valid string to be used as a prompt or to generated strings that represent colored text on a terminal.
33
33
  email: raf.magana@gmail.com
34
34
  executables: []
35
35
 
@@ -39,10 +39,21 @@ extra_rdoc_files:
39
39
  - LICENSE
40
40
  - README.rdoc
41
41
  files:
42
+ - .document
43
+ - .gitignore
42
44
  - LICENSE
45
+ - README.rdoc
46
+ - Rakefile
43
47
  - VERSION
48
+ - geek_painter.gemspec
44
49
  - geek_painter_client.rb
45
- - README.rdoc
50
+ - lib/geek_painter.rb
51
+ - lib/geek_painter/canvas.rb
52
+ - lib/geek_painter/escaping_tools.rb
53
+ - lib/geek_painter/palette.rb
54
+ - lib/geek_painter/string.rb
55
+ - test/helper.rb
56
+ - test/test_geek_painter.rb
46
57
  has_rdoc: true
47
58
  homepage: http://github.com/rafmagana/geek_painter
48
59
  licenses: []