term-ansicolor 1.0.2 → 1.0.3

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.
Files changed (7) hide show
  1. data/CHANGES +2 -0
  2. data/Rakefile +5 -28
  3. data/VERSION +1 -1
  4. data/install.rb +2 -2
  5. data/lib/term/ansicolor.rb +134 -9
  6. data/make_doc.rb +3 -4
  7. metadata +37 -27
data/CHANGES CHANGED
@@ -1,3 +1,5 @@
1
+ 2007-10-05 * 1.0.3 * Better documentation + some code clean up.
2
+ * Deleted autorequire from Rakefile.
1
3
  2005-11-12 * 1.0.2 * Added DESTDIR in front of install path to make repackaging
2
4
  easier. Thanks to Tilman Sauerbeck <tilman@code-monkey.de>
3
5
  for giving the hint.
data/Rakefile CHANGED
@@ -26,43 +26,20 @@ task :clean do
26
26
  end
27
27
 
28
28
  spec = Gem::Specification.new do |s|
29
- #### Basic information.
30
-
31
29
  s.name = 'term-ansicolor'
32
30
  s.version = PKG_VERSION
33
31
  s.summary = "Ruby library that colors strings using ANSI escape sequences"
34
32
  s.description = ""
35
33
 
36
- #### Dependencies and requirements.
37
-
38
- #s.add_dependency('log4r', '> 1.0.4')
39
- #s.requirements << ""
40
-
41
34
  s.files = PKG_FILES
42
35
 
43
- #### C code extensions.
44
-
45
- #s.extensions << "ext/extconf.rb"
46
-
47
- #### Load-time details: library and application (you will need one or both).
48
-
49
36
  s.require_path = 'lib' # Use these for libraries.
50
- s.autorequire = 'term/ansicolor'
51
-
52
- #s.bindir = "bin" # Use these for applications.
53
- #s.executables = ["bla.rb"]
54
- #s.default_executable = "bla.rb"
55
-
56
- #### Documentation and testing.
57
-
58
- #s.has_rdoc = true
59
- #s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
60
- #s.rdoc_options <<
61
- # '--title' << 'Term::ANSIColor -- ANSI color escape sequences' <<
62
- # '--main' << 'README' <<
63
- # '--line-numbers'
64
37
 
65
- #### Author and project details.
38
+ s.has_rdoc = true
39
+ s.rdoc_options <<
40
+ '--title' << 'Term::ANSIColor' <<
41
+ '--inline-source' <<
42
+ '--line-numbers'
66
43
 
67
44
  s.author = "Florian Frank"
68
45
  s.email = "flori@ping.de"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.0.3
data/install.rb CHANGED
@@ -5,9 +5,9 @@ include Config
5
5
  require 'fileutils'
6
6
  include FileUtils::Verbose
7
7
 
8
- destdir = "#{ENV["DESTDIR"]}"
8
+ destdir = "#{ENV['DESTDIR']}"
9
9
  libdir = CONFIG["sitelibdir"]
10
10
  dest = destdir + File.join(libdir, 'term')
11
11
  mkdir_p dest
12
- install('lib/term/ansicolor.rb', dest)
12
+ install 'lib/term/ansicolor.rb', dest
13
13
  # vim: set et sw=2 ts=2:
@@ -1,6 +1,128 @@
1
+ # = Term::ANSIColor - ANSI escape sequences in Ruby
2
+ #
3
+ # == Description
4
+ #
5
+ # This library can be used to color/uncolor strings using ANSI escape sequences.
6
+ #
7
+ # == Author
8
+ #
9
+ # Florian Frank mailto:flori@ping.de
10
+ #
11
+ # == License
12
+ #
13
+ # This is free software; you can redistribute it and/or modify it under the
14
+ # terms of the GNU General Public License Version 2 as published by the Free
15
+ # Software Foundation: www.gnu.org/copyleft/gpl.html
16
+ #
17
+ # == Download
18
+ #
19
+ # The latest version of this library can be downloaded at
20
+ #
21
+ # * http://rubyforge.org/frs?group_id=391
22
+ #
23
+ # The homepage of this library is located at
24
+ #
25
+ # * http://term-ansicolor.rubyforge.org
26
+ #
27
+ # == Examples
28
+ #
29
+ # The file examples/example.rb in the source/gem-distribution shows how
30
+ # this library can be used:
31
+ # require 'term/ansicolor'
32
+ #
33
+ # # Use this trick to work around namespace cluttering that
34
+ # # happens if you just include Term::ANSIColor:
35
+ #
36
+ # class Color
37
+ # class << self
38
+ # include Term::ANSIColor
39
+ # end
40
+ # end
41
+ #
42
+ # print Color.red, Color.bold, "No Namespace cluttering:", Color.clear, "\n"
43
+ # print Color.green + "green" + Color.clear, "\n"
44
+ # print Color.on_red(Color.green("green")), "\n"
45
+ # print Color.yellow { Color.on_black { "yellow on_black" } }, "\n\n"
46
+ #
47
+ # # Or shortcut Term::ANSIColor by assignment:
48
+ # c = Term::ANSIColor
49
+ #
50
+ # print c.red, c.bold, "No Namespace cluttering (alternative):", c.clear, "\n"
51
+ # print c.green + "green" + c.clear, "\n"
52
+ # print c.on_red(c.green("green")), "\n"
53
+ # print c.yellow { c.on_black { "yellow on_black" } }, "\n\n"
54
+ #
55
+ # # Anyway, I don't define any of Term::ANSIColor's methods in this example
56
+ # # and I want to keep it short:
57
+ # include Term::ANSIColor
58
+ #
59
+ # print red, bold, "Usage as constants:", reset, "\n"
60
+ # print clear, "clear", reset, reset, "reset", reset,
61
+ # bold, "bold", reset, dark, "dark", reset,
62
+ # underscore, "underscore", reset, blink, "blink", reset,
63
+ # negative, "negative", reset, concealed, "concealed", reset, "|\n",
64
+ # black, "black", reset, red, "red", reset, green, "green", reset,
65
+ # yellow, "yellow", reset, blue, "blue", reset, magenta, "magenta", reset,
66
+ # cyan, "cyan", reset, white, "white", reset, "|\n",
67
+ # on_black, "on_black", reset, on_red, "on_red", reset,
68
+ # on_green, "on_green", reset, on_yellow, "on_yellow", reset,
69
+ # on_blue, "on_blue", reset, on_magenta, "on_magenta", reset,
70
+ # on_cyan, "on_cyan", reset, on_white, "on_white", reset, "|\n\n"
71
+ #
72
+ # print red, bold, "Usage as unary argument methods:", reset, "\n"
73
+ # print clear("clear"), reset("reset"), bold("bold"), dark("dark"),
74
+ # underscore("underscore"), blink("blink"), negative("negative"),
75
+ # concealed("concealed"), "|\n",
76
+ # black("black"), red("red"), green("green"), yellow("yellow"),
77
+ # blue("blue"), magenta("magenta"), cyan("cyan"), white("white"), "|\n",
78
+ # on_black("on_black"), on_red("on_red"), on_green("on_green"),#
79
+ # on_yellow("on_yellow"), on_blue("on_blue"), on_magenta("on_magenta"),
80
+ # on_cyan("on_cyan"), on_white("on_white"), "|\n\n"
81
+ #
82
+ # print red { bold { "Usage as block forms:" } }, "\n"
83
+ # print clear { "clear" }, reset { "reset" }, bold { "bold" },
84
+ # dark { "dark" }, underscore { "underscore" }, blink { "blink" },
85
+ # negative { "negative" }, concealed { "concealed" }, "|\n",
86
+ # black { "black" }, red { "red" }, green { "green" },
87
+ # yellow { "yellow" }, blue { "blue" }, magenta { "magenta" },
88
+ # cyan { "cyan" }, white { "white" }, "|\n",
89
+ # on_black { "on_black" }, on_red { "on_red" }, on_green { "on_green" },
90
+ # on_yellow { "on_yellow" }, on_blue { "on_blue" },
91
+ # on_magenta { "on_magenta" }, on_cyan { "on_cyan" },
92
+ # on_white { "on_white" }, "|\n\n"
93
+ #
94
+ # # Usage as Mixin into String or its Subclasses
95
+ # class String
96
+ # include Term::ANSIColor
97
+ # end
98
+ #
99
+ # print "Usage as String Mixins:".red.bold, "\n"
100
+ # print "clear".clear, "reset".reset, "bold".bold, "dark".dark,
101
+ # "underscore".underscore, "blink".blink, "negative".negative,
102
+ # "concealed".concealed, "|\n",
103
+ # "black".black, "red".red, "green".green, "yellow".yellow,
104
+ # "blue".blue, "magenta".magenta, "cyan".cyan, "white".white, "|\n",
105
+ # "on_black".on_black, "on_red".on_red, "on_green".on_green,
106
+ # "on_yellow".on_yellow, "on_blue".on_blue, "on_magenta".on_magenta,
107
+ # "on_cyan".on_cyan, "on_white".on_white, "|\n\n"
108
+ #
109
+ # symbols = Term::ANSIColor::attributes
110
+ # print red { bold { "All supported attributes = " } },
111
+ # blue { symbols.inspect }, "\n\n"
112
+ #
113
+ # print "Send symbols to strings:".send(:red).send(:bold), "\n"
114
+ # print symbols[12, 8].map { |c| c.to_s.send(c) }, "\n\n"
115
+ #
116
+ # print red { bold { "Make strings monochromatic again:" } }, "\n"
117
+ # print [ "red".red, "not red anymore".red.uncolored,
118
+ # uncolored { "not red anymore".red }, uncolored("not red anymore".red)
119
+ # ].map { |x| x + "\n" }
1
120
  module Term
121
+ # The ANSIColor module can be used for namespacing and mixed into your own
122
+ # classes.
2
123
  module ANSIColor
3
- @@attributes = [
124
+ # :stopdoc:
125
+ ATTRIBUTES = [
4
126
  [ :clear , 0 ],
5
127
  [ :reset , 0 ], # synonym for :clear
6
128
  [ :bold , 1 ],
@@ -31,25 +153,28 @@ module Term
31
153
  [ :on_white , 47 ],
32
154
  ]
33
155
 
156
+ ATTRIBUTE_NAMES = ATTRIBUTES.transpose.first
157
+ # :startdoc:
158
+
34
159
  # Returns true, if the coloring function of this module
35
160
  # is switched on, false otherwise.
36
161
  def self.coloring?
37
- @@coloring
162
+ @coloring
38
163
  end
39
164
 
40
165
  # Turns the coloring on or off globally, so you can easily do
41
166
  # this for example:
42
167
  # Term::ANSIColor::coloring = STDOUT.isatty
43
168
  def self.coloring=(val)
44
- @@coloring = val
169
+ @coloring = val
45
170
  end
46
171
  self.coloring = true
47
172
 
48
- @@attributes.each do |c, v|
173
+ ATTRIBUTES.each do |c, v|
49
174
  eval %Q{
50
175
  def #{c}(string = nil)
51
176
  result = ''
52
- result << "\e[#{v}m" if @@coloring
177
+ result << "\e[#{v}m" if Term::ANSIColor.coloring?
53
178
  if block_given?
54
179
  result << yield
55
180
  elsif string
@@ -59,14 +184,14 @@ module Term
59
184
  else
60
185
  return result #only switch on
61
186
  end
62
- result << "\e[0m" if @@coloring
187
+ result << "\e[0m" if Term::ANSIColor.coloring?
63
188
  result
64
189
  end
65
190
  }
66
191
  end
67
192
 
68
- # Regular expression that is used to scan for ANSI-sequences. It is used to
69
- # uncolor strins.
193
+ # Regular expression that is used to scan for ANSI-sequences while
194
+ # uncoloring strings.
70
195
  COLORED_REGEXP = /\e\[([34][0-7]|[0-9])m/
71
196
 
72
197
  # Returns an uncolored version of the string, that is all
@@ -87,7 +212,7 @@ module Term
87
212
 
88
213
  # Returns an array of all Term::ANSIColor attributes as symbols.
89
214
  def attributes
90
- @@attributes.map { |c| c.first }
215
+ ATTRIBUTE_NAMES
91
216
  end
92
217
  extend self
93
218
  end
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $outdir = 'doc/'
4
- puts "Creating documentation in '#$outdir'."
5
- system "rdoc -d -o #$outdir lib/term/ansicolor.rb"
6
- # vim: set et sw=4 ts=4:
3
+ puts "Creating documentation."
4
+ system "rdoc --line-numbers --inline-source --title Term::ANSIColor -d #{Dir['lib/**/*.rb'] * ' '}"
5
+ # vim: set et sw=2 ts=2:
metadata CHANGED
@@ -1,51 +1,61 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: term-ansicolor
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.2
7
- date: 2005-11-12 00:00:00 +01:00
6
+ version: 1.0.3
7
+ date: 2007-10-05 00:00:00 +02:00
8
8
  summary: Ruby library that colors strings using ANSI escape sequences
9
9
  require_paths:
10
- - lib
10
+ - lib
11
11
  email: flori@ping.de
12
12
  homepage: http://term-ansicolor.rubyforge.org
13
13
  rubyforge_project: term-ansicolor
14
- description: ''
15
- autorequire: term/ansicolor
14
+ description: ""
15
+ autorequire:
16
16
  default_executable:
17
17
  bindir: bin
18
- has_rdoc: false
18
+ has_rdoc: true
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
- -
22
- - ">"
23
- - !ruby/object:Gem::Version
24
- version: 0.0.0
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
25
24
  version:
26
25
  platform: ruby
27
26
  signing_key:
28
27
  cert_chain:
28
+ post_install_message:
29
29
  authors:
30
- - Florian Frank
30
+ - Florian Frank
31
31
  files:
32
- - examples
33
- - install.rb
34
- - GPL
35
- - Rakefile
36
- - VERSION
37
- - CHANGES
38
- - lib
39
- - make_doc.rb
40
- - README.en
41
- - examples/example.rb
42
- - examples/cdiff.rb
43
- - lib/term
44
- - lib/term/ansicolor.rb
32
+ - install.rb
33
+ - lib
34
+ - make_doc.rb
35
+ - CHANGES
36
+ - README.en
37
+ - VERSION
38
+ - Rakefile
39
+ - GPL
40
+ - examples
41
+ - lib/term
42
+ - lib/term/ansicolor.rb
43
+ - examples/cdiff.rb
44
+ - examples/example.rb
45
45
  test_files: []
46
- rdoc_options: []
46
+
47
+ rdoc_options:
48
+ - --title
49
+ - Term::ANSIColor
50
+ - --inline-source
51
+ - --line-numbers
47
52
  extra_rdoc_files: []
53
+
48
54
  executables: []
55
+
49
56
  extensions: []
57
+
50
58
  requirements: []
51
- dependencies: []
59
+
60
+ dependencies: []
61
+