ansi256 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -77,8 +77,8 @@ puts say_hello_world.plain.fg(27)
77
77
 
78
78
  ![say-hello-world](https://github.com/junegunn/ansi256/raw/master/say-hello-world.png)
79
79
 
80
- _"Just gimme the code!"_
81
- -----------------------
80
+ Ansi256 methods
81
+ ---------------
82
82
 
83
83
  ```ruby
84
84
  Ansi256.fg(232)
@@ -88,8 +88,24 @@ Ansi256.on_green
88
88
  Ansi256.bold
89
89
  Ansi256.underline
90
90
  Ansi256.reset
91
+
92
+ Ansi256.fg(232, 'Hello')
93
+ Ansi256.bg(226, 'World')
94
+ Ansi256.green('Hello World')
91
95
  ```
92
96
 
97
+ Disabling extended String methods
98
+ ---------------------------------
99
+
100
+ ```ruby
101
+ Ansi256.enabled?
102
+ # true
103
+
104
+ Ansi256.enabled = false
105
+
106
+ "Hello".fg(232)
107
+ # Hello
108
+ ```
93
109
 
94
110
  ansi256 executable
95
111
  ------------------
@@ -133,7 +133,4 @@ module Ansi256
133
133
  end
134
134
  end
135
135
 
136
- class String
137
- include Ansi256::Mixin
138
- end
139
-
136
+ Ansi256.enabled = true
@@ -1,21 +1,74 @@
1
1
  module Ansi256
2
- module Mixin
3
- def fg code
4
- Ansi256.fg(code, self)
5
- end
2
+ class << self
3
+ def enabled= bool
4
+ if bool
5
+ String.class_eval do
6
+ [:fg, :bg, :plain].each do |name|
7
+ undef_method(name) if method_defined?(name)
8
+ end
6
9
 
7
- def bg code
8
- Ansi256.bg(code, self)
9
- end
10
+ def fg code
11
+ Ansi256.fg(code, self)
12
+ end
10
13
 
11
- def plain
12
- Ansi256.plain self
13
- end
14
+ def bg code
15
+ Ansi256.bg(code, self)
16
+ end
17
+
18
+ def plain
19
+ Ansi256.plain self
20
+ end
21
+
22
+ Ansi256::CODE.each do |name, code|
23
+ undef_method(name) if method_defined?(name)
24
+ define_method name do
25
+ Ansi256.send name, self
26
+ end
27
+ end
28
+ end
14
29
 
15
- Ansi256::CODE.each do |name, code|
16
- define_method name do
17
- Ansi256.send name, self
30
+ Ansi256.class_eval do
31
+ class << self
32
+ undef_method(:enabled?) if method_defined?(:enabled?)
33
+ def enabled?
34
+ true
35
+ end
36
+ end
37
+ end
38
+ else
39
+ String.class_eval do
40
+ [:fg, :bg, :plain].each do |name|
41
+ undef_method(name) if method_defined?(name)
42
+ end
43
+
44
+ def fg code
45
+ self
46
+ end
47
+ alias bg fg
48
+
49
+ def plain
50
+ Ansi256.plain self
51
+ end
52
+
53
+ Ansi256::CODE.each do |name, code|
54
+ undef_method(name) if method_defined?(name)
55
+ define_method name do
56
+ self
57
+ end
58
+ end
59
+ end
60
+
61
+ Ansi256.class_eval do
62
+ class << self
63
+ undef_method(:enabled?) if method_defined?(:enabled?)
64
+ def enabled?
65
+ false
66
+ end
67
+ end
68
+ end
18
69
  end
70
+
71
+ bool
19
72
  end
20
73
  end
21
74
  end
@@ -1,3 +1,3 @@
1
1
  module Ansi256
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
@@ -194,4 +194,23 @@ class TestAnsi256 < MiniTest::Unit::TestCase
194
194
  puts "RGB Color".fg('#ff9900').bg('#003366')
195
195
  puts "RGB Color (Monochrome)".fg('ef').bg('3a')
196
196
  end
197
+
198
+ def test_enabled
199
+ 2.times do
200
+ [:fg, :bg].each do |m|
201
+ assert Ansi256.enabled?
202
+ hello = "hello".send(m, 'f90')
203
+ assert_equal 'hello', hello.plain
204
+
205
+ Ansi256.enabled = false
206
+ assert !Ansi256.enabled?
207
+ assert hello.length > "hello".send(m, 'f90').length
208
+ assert_equal 'hello', hello.plain
209
+
210
+ Ansi256.enabled = true
211
+ assert Ansi256.enabled?
212
+ assert_equal hello, "hello".send(m, 'f90')
213
+ end
214
+ end
215
+ end
197
216
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ansi256
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-28 00:00:00.000000000 Z
12
+ date: 2013-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler