colorful 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,93 @@
1
+ Colorful is a gem that provides color and effect support to native Ruby Strings when printed in an ANSI color supporting terminal.
2
+
3
+ The following code will print "Test" in red using the terminal's color scheme:
4
+
5
+ puts "Test".red
6
+
7
+ Background colors are also supported:
8
+
9
+ puts "Test".blue_background
10
+
11
+ You can combine the two:
12
+
13
+ puts "Test".red.blue_background
14
+
15
+ or:
16
+
17
+ puts "Test".red_on_blue
18
+
19
+ Add some effects:
20
+
21
+ puts "Test".red_on_blue.blink.underline
22
+
23
+ And then remove some:
24
+
25
+ puts "Test".red_on_blue.blink.underline.no_blink
26
+
27
+ The supported terminal colors are:
28
+
29
+ * black
30
+ * red
31
+ * green
32
+ * yellow
33
+ * blue
34
+ * magenta
35
+ * cyan
36
+ * white
37
+ * default
38
+
39
+ The supported effects are:
40
+ * reset
41
+ * bright/bold
42
+ * italic
43
+ * underline
44
+ * blink
45
+ * inverse
46
+ * hide
47
+
48
+ Note that not all of these formats may not be supported in all environments. Using an unsupported effect will not cause any display issues, other than the style not being applied.
49
+
50
+ Additionally, Colorful supports full rgb256 or HTML color values
51
+
52
+ To use rgb256 true red as the foreground:
53
+
54
+ puts "Test".color(255, 0, 0)
55
+
56
+ For the HTML version:
57
+
58
+ puts "Test".color("F00")
59
+
60
+ or:
61
+
62
+ puts "Test".color("#ff0000")
63
+
64
+ or:
65
+
66
+ puts "Test".color(:_ff0000)
67
+
68
+ These methods handle standard or shortened HTML codes, case insensitive, with or without # or _
69
+
70
+ Note that these methods require xterm 256 color support, and colors will be translated to the nearest possible valid color.
71
+
72
+ Lastly, some methods have been added that allow for cursor movement. The supported movement operations include:
73
+ * and_go_up(n)
74
+ * and_go_down(n)
75
+ * and_go_left(n)
76
+ * and_go_right(n)
77
+ * and_go_to(n)
78
+
79
+ To return to the beginning of the line:
80
+
81
+ 10.times do |n|
82
+ print n.to_s.and_go_to 0
83
+ end
84
+
85
+ or:
86
+
87
+ 10.times do |n|
88
+ puts n.to_s.and_go_up 1
89
+ end
90
+
91
+ Note that some methods work better with puts, and others with print. Puts will implicitly add a new line to the end of the string it is printing, moving the cursor.
92
+
93
+ This is a work in progress but is stable. Let me know if you would like a feature added to the project.
data/Rakefile CHANGED
@@ -1 +1,4 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ task(:default).clear
4
+ task :default => [:spec]
@@ -19,6 +19,12 @@ module Colorful
19
19
  :blink => 5,
20
20
  :inverse => 7,
21
21
  :hide => 8 }
22
+
23
+ MOVEMENT = { :up => 'F',
24
+ :down => 'E',
25
+ :left => 'D',
26
+ :right => 'C',
27
+ :to => 'G' }
22
28
  end
23
29
 
24
30
  class String
@@ -27,15 +33,16 @@ class String
27
33
  inject_ansi_code 30 + code
28
34
  end
29
35
 
30
- define_method "#{color}_background" do
31
- inject_ansi_code 40 + code
32
- end
33
-
34
36
  Colorful::COLORS.each do |bg_color, bg_code|
35
37
  define_method "#{color}_on_#{bg_color}" do
36
38
  inject_ansi_code 30 + code, 40 + bg_code
37
39
  end
38
40
  end
41
+
42
+ define_method "#{color}_background" do
43
+ inject_ansi_code 40 + code
44
+ end
45
+
39
46
  end
40
47
 
41
48
  Colorful::EFFECTS.each do |effect, code|
@@ -48,6 +55,13 @@ class String
48
55
  end
49
56
  end
50
57
 
58
+ Colorful::MOVEMENT.each do |move, code|
59
+ define_method "and_go_#{move}" do |num|
60
+ result = self
61
+ result += "\e[#{num}#{code}"
62
+ end
63
+ end
64
+
51
65
  def foreground(*args)
52
66
  code = ansi_color_code *args
53
67
  inject_ansi_code 38, 5, code
@@ -1,3 +1,3 @@
1
1
  module Colorful
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colorful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-14 00:00:00.000000000 -05:00
12
+ date: 2011-12-09 00:00:00.000000000 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &2157578920 !ruby/object:Gem::Requirement
17
+ requirement: &2156837840 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *2157578920
25
+ version_requirements: *2156837840
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: fuubar
28
- requirement: &2157578500 !ruby/object:Gem::Requirement
28
+ requirement: &2156837420 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *2157578500
36
+ version_requirements: *2156837420
37
37
  description: Provides string extensions for terminal color output
38
38
  email:
39
39
  - randland@gmail.com
@@ -45,6 +45,7 @@ files:
45
45
  - .rspec
46
46
  - .rvmrc
47
47
  - Gemfile
48
+ - README.markdown
48
49
  - Rakefile
49
50
  - colorful.gemspec
50
51
  - lib/colorful.rb