ripl-color_streams 0.1.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/.gemspec +1 -1
- data/README.rdoc +2 -2
- data/deps.rip +1 -1
- data/lib/ripl/color_streams.rb +38 -20
- metadata +5 -9
data/.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.summary = "A ripl plugin to colorize stdout and stderr."
|
12
12
|
s.description = "This ripl plugin colorizes your stdout and stderr streams."
|
13
13
|
s.required_rubygems_version = ">= 1.3.6"
|
14
|
-
s.add_dependency 'ripl', '>= 0.2.
|
14
|
+
s.add_dependency 'ripl', '>= 0.2.7'
|
15
15
|
s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile .gemspec}
|
16
16
|
s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
|
17
17
|
s.license = 'MIT'
|
data/README.rdoc
CHANGED
@@ -4,7 +4,7 @@ This {ripl}[http://github.com/cldwalker/ripl] plugin colorizes your +stdout+ and
|
|
4
4
|
== Install
|
5
5
|
Install the gem with:
|
6
6
|
|
7
|
-
|
7
|
+
gem install ripl-color_streams
|
8
8
|
|
9
9
|
== Usage
|
10
10
|
|
@@ -12,7 +12,7 @@ Add to your ~/.riplrc
|
|
12
12
|
|
13
13
|
require 'ripl/color_streams'
|
14
14
|
|
15
|
-
The default colors are
|
15
|
+
The default colors are <tt>:dark_gray</tt> (1;30) and <tt>:light_red</tt> (1;31). You can change them like this:
|
16
16
|
|
17
17
|
Ripl.config[:color_streams_stdout] = :light_gray
|
18
18
|
Ripl.config[:color_streams_stderr] = :red
|
data/deps.rip
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ripl >=0.2.
|
1
|
+
ripl >=0.2.7
|
data/lib/ripl/color_streams.rb
CHANGED
@@ -2,7 +2,7 @@ require 'ripl'
|
|
2
2
|
|
3
3
|
module Ripl
|
4
4
|
module ColorStreams
|
5
|
-
VERSION = '0.1.
|
5
|
+
VERSION = '0.1.1'
|
6
6
|
COLORS = {
|
7
7
|
:nothing => '0;0',
|
8
8
|
:black => '0;30',
|
@@ -24,20 +24,9 @@ module Ripl
|
|
24
24
|
}
|
25
25
|
|
26
26
|
def before_loop
|
27
|
-
# patch
|
28
|
-
|
29
|
-
|
30
|
-
def color_write(*args)
|
31
|
-
Ripl::ColorStreams.write_stream :stdout, *args
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
$stderr.instance_eval do
|
36
|
-
alias real_write write
|
37
|
-
def color_write(*args)
|
38
|
-
Ripl::ColorStreams.write_stream :stderr, *args
|
39
|
-
end
|
40
|
-
end
|
27
|
+
# patch $stdout/$stderr
|
28
|
+
Ripl::ColorStreams.patch_stream :stdout
|
29
|
+
Ripl::ColorStreams.patch_stream :stderr
|
41
30
|
|
42
31
|
# default settings
|
43
32
|
Ripl.config[:color_streams_stdout] ||= :dark_gray
|
@@ -48,12 +37,12 @@ module Ripl
|
|
48
37
|
end
|
49
38
|
|
50
39
|
def loop_eval(input)
|
51
|
-
|
52
|
-
|
40
|
+
Ripl::ColorStreams.set_stream_status :stdout, true
|
41
|
+
Ripl::ColorStreams.set_stream_status :stderr, true
|
53
42
|
super
|
54
43
|
ensure
|
55
|
-
|
56
|
-
|
44
|
+
Ripl::ColorStreams.set_stream_status :stdout, false
|
45
|
+
Ripl::ColorStreams.set_stream_status :stderr, false
|
57
46
|
end
|
58
47
|
|
59
48
|
class << self
|
@@ -65,10 +54,39 @@ module Ripl
|
|
65
54
|
|
66
55
|
stream.real_write color_code ? "\e[#{ color_code }m#{ data }\e[0;0m" : data.to_s
|
67
56
|
end
|
57
|
+
|
58
|
+
# patch stream output (but do not activate)
|
59
|
+
def patch_stream(stream_name)
|
60
|
+
stream = Object.const_get stream_name.to_s.upcase
|
61
|
+
|
62
|
+
stream.instance_eval do
|
63
|
+
alias real_write write
|
64
|
+
def color_write(*args) # define_method is not defined for singletons :/
|
65
|
+
stream_name = (self == $stdout) ? :stdout : :stderr
|
66
|
+
Ripl::ColorStreams.write_stream stream_name, *args
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def set_stream_status(stream_name, true_or_false)
|
72
|
+
stream = Object.const_get stream_name.to_s.upcase
|
73
|
+
|
74
|
+
# check if stream object has changed
|
75
|
+
unless stream.respond_to?(:real_write) && stream.respond_to?(:color_write)
|
76
|
+
Ripl::ColorStreams.patch_stream stream_name
|
77
|
+
end
|
78
|
+
|
79
|
+
# (de)activate
|
80
|
+
if true_or_false
|
81
|
+
stream.instance_eval do alias write color_write end
|
82
|
+
else
|
83
|
+
stream.instance_eval do alias write real_write end
|
84
|
+
end
|
85
|
+
end
|
68
86
|
end
|
69
87
|
end
|
70
88
|
end
|
71
89
|
|
72
|
-
Ripl::Shell.send :include, Ripl::ColorStreams
|
90
|
+
Ripl::Shell.send :include, Ripl::ColorStreams
|
73
91
|
|
74
92
|
# J-_-L
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ripl-color_streams
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 27
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Jan Lelis
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-12-08 00:00:00 +01:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,12 +25,11 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 17
|
30
28
|
segments:
|
31
29
|
- 0
|
32
30
|
- 2
|
33
|
-
-
|
34
|
-
version: 0.2.
|
31
|
+
- 7
|
32
|
+
version: 0.2.7
|
35
33
|
type: :runtime
|
36
34
|
version_requirements: *id001
|
37
35
|
description: This ripl plugin colorizes your stdout and stderr streams.
|
@@ -65,7 +63,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
63
|
requirements:
|
66
64
|
- - ">="
|
67
65
|
- !ruby/object:Gem::Version
|
68
|
-
hash: 3
|
69
66
|
segments:
|
70
67
|
- 0
|
71
68
|
version: "0"
|
@@ -74,7 +71,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
71
|
requirements:
|
75
72
|
- - ">="
|
76
73
|
- !ruby/object:Gem::Version
|
77
|
-
hash: 23
|
78
74
|
segments:
|
79
75
|
- 1
|
80
76
|
- 3
|