ansi 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/.ruby ADDED
@@ -0,0 +1,58 @@
1
+ ---
2
+ name: ansi
3
+ spec_version: 1.0.0
4
+ title: ANSI
5
+ contact: rubyworks-mailinglist@googlegroups.com
6
+ requires:
7
+ - group:
8
+ - build
9
+ name: syckle
10
+ version: 0+
11
+ - group:
12
+ - test
13
+ name: ko
14
+ version: 0+
15
+ resources:
16
+ repository: git://github.com/rubyworks/ansi.git
17
+ api: http://rubyworks.github.com/ansi/rdoc
18
+ mail: http://groups.google.com/group/rubyworks-mailinglist
19
+ home: http://rubyworks.github.com/ansi
20
+ work: http://github.com/rubyworks/ansi
21
+ manifest:
22
+ - .ruby
23
+ - lib/ansi/bbcode.rb
24
+ - lib/ansi/code.rb
25
+ - lib/ansi/columns.rb
26
+ - lib/ansi/logger.rb
27
+ - lib/ansi/mixin.rb
28
+ - lib/ansi/progressbar.rb
29
+ - lib/ansi/string.rb
30
+ - lib/ansi/table.rb
31
+ - lib/ansi/terminal/curses.rb
32
+ - lib/ansi/terminal/stty.rb
33
+ - lib/ansi/terminal/termios.rb
34
+ - lib/ansi/terminal/win32.rb
35
+ - lib/ansi/terminal.rb
36
+ - lib/ansi/version.rb
37
+ - lib/ansi.rb
38
+ - test/case_ansicode.rb
39
+ - test/case_bbcode.rb
40
+ - test/case_mixin.rb
41
+ - test/case_progressbar.rb
42
+ - PROFILE
43
+ - LICENSE
44
+ - README.rdoc
45
+ - HISTORY
46
+ - NOTICE
47
+ - VERSION
48
+ version: 1.2.3
49
+ licenses:
50
+ - Apache 2.0
51
+ copyright: Copyright (c) 2009 Thomas Sawyer
52
+ description: ANSI codes at your fingertips!
53
+ summary: ANSI codes at your fingertips!
54
+ organization: RubyWorks
55
+ authors:
56
+ - Thomas Sawyer
57
+ - Florian Frank
58
+ created: 2004-08-01
data/HISTORY CHANGED
@@ -1,5 +1,39 @@
1
1
  = RELEASE HISTORY
2
2
 
3
+ == 1.2.3 // 2011-04-12
4
+
5
+ Minor release to add #clear method to ProgressBar and provide bug
6
+ fix to BBCode.ansi_to_bbcode. Big thanks goes to Junegunn Choi
7
+ for this fix.
8
+
9
+ Changes:
10
+
11
+ * Add ProgressBar#clear method.
12
+ * Fixed ANSI::BBCode.ansi_to_bbcode and ansi_to_html from omitting lines
13
+ without any ansi code (Junegunn Choi).
14
+
15
+ == 1.2.2 // 2010-06-12
16
+
17
+ This release removes warnings about string arguments for certain
18
+ ANSI::Code methods. While the string form is considered deprecated,
19
+ for a few methods there is no use for any argument, so the string
20
+ form can remain. In addition, String#unansi has been added to
21
+ compliment String#ansi. Lastly, this release also adds the #display
22
+ method to ANSI::Mixin.
23
+
24
+ Changes:
25
+
26
+ * Remove string argument warnings.
27
+ * Add String#unansi and String#unansi!
28
+ * Add ANIS::Mixin#display.
29
+
30
+
31
+ == 1.2.1 // 2010-05-10
32
+
33
+ This release was simply a quick fix to remove the incorecct embedded
34
+ version number, until it gets fixed.
35
+
36
+
3
37
  == 1.2.0 // 2010-05-10
4
38
 
5
39
  This release entails numerous improvements. First and foremost
data/LICENSE CHANGED
@@ -1,23 +1,205 @@
1
- The MIT License
1
+ .
2
2
 
3
- Copyright (c) 2004 Thomas Sawyer
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
4
6
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
11
8
 
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
9
+ 1. Definitions.
14
10
 
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
22
13
 
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
23
16
 
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ APPENDIX: How to apply the Apache License to your work.
181
+
182
+ To apply the Apache License to your work, attach the following
183
+ boilerplate notice, with the fields enclosed by brackets "[]"
184
+ replaced with your own identifying information. (Don't include
185
+ the brackets!) The text should be enclosed in the appropriate
186
+ comment syntax for the file format. We also recommend that a
187
+ file or class name and description of purpose be included on the
188
+ same "printed page" as the copyright notice for easier
189
+ identification within third-party archives.
190
+
191
+ Copyright [yyyy] [name of copyright owner]
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
204
+
205
+ .
data/NOTICE ADDED
@@ -0,0 +1,18 @@
1
+ = COPYRIGHT NOTICES
2
+
3
+ == ProgressBar
4
+
5
+ ProgressBar class is based on the original ProgressBar by Satoru Takabayashi.
6
+
7
+ Copyright (C) 2001 Satoru Takabayashi
8
+
9
+
10
+ == Terminal Extensions
11
+
12
+ The terminal extensions are based on HighLine's SystemExtensions
13
+ by James Edward Gray II.
14
+
15
+ Copyright 2006 Gray Productions
16
+
17
+ {Ruby software license}[http://www.ruby-lang.org/en/LICENSE.txt]
18
+
data/PROFILE CHANGED
@@ -1,11 +1,13 @@
1
1
  ---
2
- title : ANSI
3
- suite : rubyworks
4
- summary : ANSI codes at your fingertips!
5
- copyright : Copyright (c) 2009 Thomas Sawyer
6
- license : MIT
7
- contact : rubyworks-mailinglist@googlegroups.com
8
- created : 2004-08-01
2
+ title : ANSI
3
+ summary: ANSI codes at your fingertips!
4
+ license: Apache 2.0
5
+ contact: rubyworks-mailinglist@googlegroups.com
6
+ created: 2004-08-01
7
+
8
+ requires:
9
+ - syckle (build)
10
+ - ko (test)
9
11
 
10
12
  authors:
11
13
  - Thomas Sawyer
@@ -21,3 +23,6 @@ resources:
21
23
  mailinglist : http://groups.google.com/group/rubyworks-mailinglist
22
24
  repository : git://github.com/rubyworks/ansi.git
23
25
 
26
+ organization : RubyWorks
27
+ copyright : Copyright (c) 2009 Thomas Sawyer
28
+
@@ -19,9 +19,9 @@ device.
19
19
 
20
20
  == FEATURES/ISSUES
21
21
 
22
- * ANSI::Code can be used as a mixin or for module functions.
23
- * ANSI::Mixin provides an alternative mixin like +colored+ gem.
24
- * Single extension to String class makes common usage very elegant.
22
+ * ANSI::Code provides ANSI codes as module functions.
23
+ * String#ansi makes common usage very easy and elegant.
24
+ * ANSI::Mixin provides an alternative mixin (like +colored+ gem).
25
25
  * Very Good coverage of standard ANSI codes.
26
26
 
27
27
 
@@ -79,7 +79,7 @@ Windows users use 'ruby setup.rb all'.
79
79
 
80
80
  Copyright (c) 2004 Thomas Sawyer
81
81
 
82
- This program is ditributed unser the terms of the MIT license.
82
+ This program is ditributed unser the terms of the Apache 2 license.
83
83
 
84
84
  See LICENSE file for details.
85
85
 
data/VERSION CHANGED
@@ -1,5 +1 @@
1
- name : ansi
2
- major: 1
3
- minor: 2
4
- patch: 2
5
- date : 2010-06-11
1
+ 1.2.3
@@ -1,9 +1,8 @@
1
1
  # ANSI module contains all the ANSI related classes.
2
- #
3
2
  module ANSI
4
- # TODO: metadata constant lookup
5
3
  end
6
4
 
5
+ require 'ansi/version'
7
6
  require 'ansi/code'
8
7
  require 'ansi/logger'
9
8
  require 'ansi/progressbar'
@@ -107,11 +107,8 @@ module ANSI
107
107
 
108
108
  ## Iterate over input lines
109
109
  string.split("\n").each do |line|
110
- ansi = line.scan(/\e\[[0-9;]+m/)
111
- continue if ansi.nil? || ansi.empty?
112
-
113
110
  ## Iterate over found ansi sequences
114
- ansi.each do |seq|
111
+ line.scan(/\e\[[0-9;]+m/).each do |seq|
115
112
  ansiname = ANSINAME2CODE.invert["#{seq}"]
116
113
 
117
114
  ## Pop last tag and form closing tag
@@ -127,7 +124,7 @@ module ANSI
127
124
 
128
125
  ## Replace ansi sequence by BBCode tag
129
126
  replace = sprintf("[%s]", bbname)
130
- line.sub!("#{Regexp.quote(seq)}", replace)
127
+ line.sub!(seq, replace)
131
128
  end
132
129
 
133
130
  ## Append converted line
@@ -0,0 +1,111 @@
1
+ require 'ansi'
2
+ require 'ansi/terminal'
3
+
4
+ module ANSI
5
+
6
+ class Columns
7
+
8
+ # Create a column-based layout.
9
+ #
10
+ # string - multiline string to columnize
11
+ #
12
+ # options[:columns] - number of columns
13
+ # options[:align] - align :left or :right
14
+ # options[:padding] - space to add to each cell
15
+ #
16
+ # The +format+ must return ansi codes.
17
+ def initialize(string, options={}, &format)
18
+ @string = string
19
+ @columns = options[:columns] || 3
20
+ @padding = options[:padding] || 0
21
+ @align = options[:align]
22
+ #@ansi = [options[:ansi]].flatten
23
+ @format = format
24
+ end
25
+
26
+ #
27
+ attr_accessor :string
28
+
29
+ #
30
+ attr_accessor :columns
31
+
32
+ #
33
+ attr_accessor :padding
34
+
35
+ #
36
+ attr_accessor :align
37
+
38
+ #
39
+ attr_accessor :format
40
+
41
+ #
42
+ def to_s
43
+ if columns
44
+ to_s_columns(columns)
45
+ else
46
+ to_s_auto
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ #
53
+ # TODO: put in empty strings for blank cells
54
+ def to_s_columns(columns)
55
+ lines = string.lines.to_a
56
+ count = lines.size
57
+ cols = []
58
+ mod = (count / columns.to_f).to_i + 1
59
+ lines.each_with_index do |line, index|
60
+ (cols[index % mod] ||=[]) << line.strip
61
+ end
62
+ max = lines.map{ |l| l.size }.max
63
+ pad = " " * padding
64
+ tmp = template(max, pad)
65
+ str = ""
66
+ cols.each_with_index do |row, c|
67
+ row.each_with_index do |cell, r|
68
+ str << (tmp % cell).ansi(*ansi_formating(cell, c, r))
69
+ end
70
+ str << "\n"
71
+ end
72
+ str
73
+ end
74
+
75
+ # TODO: look at the lines and figure out how many columns will fit
76
+ def to_s_auto
77
+ width = Terminal.terminal_width
78
+ end
79
+
80
+ #
81
+ def template(max, pad)
82
+ case align
83
+ when :right, 'right'
84
+ "%#{max}s#{pad}"
85
+ else
86
+ "%-#{max}s#{pad}"
87
+ end
88
+ end
89
+
90
+ #
91
+ def ansi_formating(cell, col, row)
92
+ if @format
93
+ case @format.arity
94
+ when 0
95
+ f = @format[]
96
+ when 1
97
+ f = @format[cell]
98
+ when 2
99
+ f = @format[row, col]
100
+ else
101
+ f = @format[cell, row, col]
102
+ end
103
+ else
104
+ f = nil
105
+ end
106
+ [f].flatten.compact
107
+ end
108
+
109
+ end
110
+
111
+ end
@@ -121,6 +121,7 @@ module ANSI
121
121
  @is_finished = false
122
122
  end
123
123
 
124
+ #
124
125
  def inc(step = 1)
125
126
  @current += step
126
127
  @current = @total if @current > @total
@@ -128,6 +129,11 @@ module ANSI
128
129
  @previous = @current
129
130
  end
130
131
 
132
+ #
133
+ def clear
134
+ @out.print(" " * get_width + eol)
135
+ end
136
+
131
137
  def inspect
132
138
  "(ProgressBar: #{@current}/#{@total})"
133
139
  end
@@ -0,0 +1,163 @@
1
+ require 'ansi'
2
+ require 'ansi/terminal'
3
+
4
+ module ANSI
5
+
6
+ class Table
7
+
8
+ # The Table class can be used to output nicely formatted
9
+ # tables with division lines and alignment.
10
+ #
11
+ # table - array of array
12
+ #
13
+ # options[:align] - align :left or :right
14
+ # options[:padding] - space to add to each cell
15
+ # options[:fit] - fit to screen width
16
+ # options[:border] -
17
+ #
18
+ # The +format+ block must return ANSI codes to apply
19
+ # to each cell.
20
+ #
21
+ # Other Implementations:
22
+ #
23
+ # * http://github.com/visionmedia/terminal-table
24
+ # * http://github.com/aptinio/text-table
25
+ #
26
+ # TODO: Support for table headers and footers.
27
+ def initialize(table, options={}, &format)
28
+ @table = table
29
+ @padding = options[:padding] || 0
30
+ @align = options[:align]
31
+ @fit = options[:fit]
32
+ @border = options[:border]
33
+ #@ansi = [options[:ansi]].flatten
34
+ @format = format
35
+
36
+ @pad = " " * @padding
37
+ end
38
+
39
+ #
40
+ attr_accessor :table
41
+
42
+ # Fit to scree width.
43
+ attr_accessor :fit
44
+
45
+ #
46
+ attr_accessor :padding
47
+
48
+ #
49
+ attr_accessor :align
50
+
51
+ #
52
+ attr_accessor :format
53
+
54
+ #
55
+ attr_accessor :border
56
+
57
+ #
58
+ def to_s #(fit=false)
59
+ row_count = table.size
60
+ col_count = table[0].size
61
+
62
+ max = max_columns(fit)
63
+
64
+ div = dividing_line
65
+ top = div #.gsub('+', ".")
66
+ bot = div #.gsub('+', "'")
67
+
68
+ body = []
69
+ table.each_with_index do |row, r|
70
+ body_row = []
71
+ row.each_with_index do |cell, c|
72
+ t = cell_template(max[c])
73
+ body_row << (t % cell.to_s).ansi(*ansi_formating(cell, c, r))
74
+ end
75
+ body << "| " + body_row.join(' | ') + " |"
76
+ end
77
+
78
+ if border
79
+ body = body.join("\n#{div}\n")
80
+ else
81
+ body = body.join("\n")
82
+ end
83
+
84
+ "#{top}\n#{body}\n#{bot}\n"
85
+ end
86
+
87
+ private
88
+
89
+ # TODO: look at the lines and figure out how many columns will fit
90
+ def fit_width
91
+ width = Terminal.terminal_width
92
+ ((width.to_f / column_size) - (padding + 3)).to_i
93
+ end
94
+
95
+ #
96
+ def max_columns(fit=false)
97
+ max = Array.new(column_size, 0)
98
+ table.each do |row|
99
+ row.each_with_index do |col, index|
100
+ col = col.to_s
101
+ if fit
102
+ max[index] = [max[index], col.size, fit_width].max
103
+ else
104
+ max[index] = [max[index], col.size].max
105
+ end
106
+ end
107
+ end
108
+ max
109
+ end
110
+
111
+ # Number of columns.
112
+ def column_size
113
+ table.first.size
114
+ end
115
+
116
+ #
117
+ def cell_template(max)
118
+ case align
119
+ when :right, 'right'
120
+ "#{@pad}%#{max}s"
121
+ else
122
+ "%-#{max}s#{@pad}"
123
+ end
124
+ end
125
+
126
+ #
127
+ def ansi_formating(cell, col, row)
128
+ if @format
129
+ case @format.arity
130
+ when 0
131
+ f = @format[]
132
+ when 1
133
+ f = @format[cell]
134
+ when 2
135
+ f = @format[row, col]
136
+ else
137
+ f = @format[cell, row, col]
138
+ end
139
+ else
140
+ f = nil
141
+ end
142
+ [f].flatten.compact
143
+ end
144
+
145
+ # TODO: make more efficient
146
+ def dividing_line
147
+ tmp = max_columns(fit).map{ |m| "%#{m}s" }.join(" | ")
148
+ tmp = "| #{tmp} |"
149
+ lin = (tmp % (['-'] * column_size)).gsub(/[^\|]/, '-').gsub('|', '+')
150
+ end
151
+
152
+ #def dividing_line_top
153
+ # dividing_line.gsub('+', '.')
154
+ #end
155
+
156
+ #def dividing_line_bottom
157
+ # dividing_line.gsub('+', "'")
158
+ #end
159
+
160
+ end
161
+
162
+ end
163
+
@@ -0,0 +1,4 @@
1
+ module ANSI
2
+ VERSION = '1.2.3'
3
+ DATE = '2011-04-08'
4
+ end
@@ -1,20 +1,20 @@
1
- require 'test/unit'
2
1
  require 'ansi/code'
3
2
 
4
- class TestANSICode < Test::Unit::TestCase
3
+ class TestANSICode < KO::TestCase
5
4
 
6
5
  include ANSI::Code
7
6
 
8
- def test_methods
7
+ test "base methods" do
9
8
  str = red + "Hello" + blue + "World"
10
9
  out = "\e[31mHello\e[34mWorld"
11
- assert_equal( out, str )
10
+ out == str
12
11
  end
13
12
 
14
- def test_blocks
13
+ test "block notation" do
15
14
  str = red { "Hello" } + blue { "World" }
16
15
  out = "\e[31mHello\e[0m\e[34mWorld\e[0m"
17
- assert_equal( out, str )
16
+ out == str
18
17
  end
19
18
 
20
19
  end
20
+
@@ -0,0 +1,28 @@
1
+ require 'ansi/bbcode'
2
+
3
+ class TC_BBCode < KO::TestCase
4
+
5
+ test "to_ansi" do
6
+ str = "this is [COLOR=red]red[/COLOR], this is [B]bold[/B]"
7
+ out = "this is \e[0;31mred\e[0m, this is \e[1mbold\e[0m\n"
8
+ out == ANSI::BBCode.bbcode_to_ansi(str)
9
+ end
10
+
11
+ test "to_html" do
12
+ str = "this is [COLOR=red]red[/COLOR], this is [B]bold[/B]"
13
+ out = "this is <font color=\"red\">red</font>, this is <strong>bold</strong><br />\n"
14
+ out == ANSI::BBCode.bbcode_to_html(str)
15
+ end
16
+
17
+ test "ansi_to_html" do
18
+ str = "this is \e[0;31mred\e[0m, this is \e[1mbold\e[0m\n" +
19
+ "this is a line without any ansi code\n" +
20
+ "this is \e[0;31mred\e[0m, this is \e[1mbold\e[0m\n"
21
+ out = "this is <font color=\"red\">red</font>, this is <strong>bold</strong><br />\n" +
22
+ "this is a line without any ansi code<br />\n" +
23
+ "this is <font color=\"red\">red</font>, this is <strong>bold</strong><br />\n"
24
+ out == ANSI::BBCode.ansi_to_html(str)
25
+ end
26
+
27
+ end
28
+
@@ -1,22 +1,21 @@
1
- require 'test/unit'
2
1
  require 'ansi/mixin'
3
2
 
4
- class TestANSIMixin < Test::Unit::TestCase
3
+ class TestANSIMixin < KO::TestCase
5
4
 
6
5
  class ::String
7
6
  include ANSI::Mixin
8
7
  end
9
8
 
10
- def test_methods
9
+ test "methods" do
11
10
  str = "Hello".red + "World".blue
12
11
  out = "\e[31mHello\e[0m\e[34mWorld\e[0m"
13
- assert_equal(out, str)
12
+ out == str
14
13
  end
15
14
 
16
- def test_display
15
+ test "display" do
17
16
  str = "Hello".display(4,10)
18
17
  out = "\e[s\e[4;10HHello\e[u"
19
- assert_equal(out, str)
18
+ out == str
20
19
  end
21
20
 
22
21
  end
@@ -1,10 +1,9 @@
1
- require 'test/unit'
2
1
  require 'stringio'
3
2
  require 'ansi/progressbar'
4
3
 
5
- class TC_ANSI_Progressbar < Test::Unit::TestCase
4
+ class TC_ANSI_Progressbar < KO::TestCase
6
5
 
7
- def test_progressbar
6
+ test "progressbar" do
8
7
  stio = StringIO.new
9
8
  pbar = ANSI::Progressbar.new("Test Bar", 10, stio) do |b|
10
9
  b.style(:title => [:red], :bar=>[:blue])
@@ -13,6 +12,7 @@ class TC_ANSI_Progressbar < Test::Unit::TestCase
13
12
  sleep 0.1
14
13
  pbar.inc
15
14
  end
15
+ true
16
16
  end
17
17
 
18
18
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ansi
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 25
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
7
8
  - 2
8
- - 2
9
- version: 1.2.2
9
+ - 3
10
+ version: 1.2.3
10
11
  platform: ruby
11
12
  authors:
12
13
  - Thomas Sawyer
@@ -15,10 +16,37 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-06-12 00:00:00 -04:00
19
+ date: 2011-04-08 00:00:00 -04:00
19
20
  default_executable:
20
- dependencies: []
21
-
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: syckle
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :development
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: ko
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
22
50
  description: ANSI codes at your fingertips!
23
51
  email: rubyworks-mailinglist@googlegroups.com
24
52
  executables: []
@@ -28,34 +56,36 @@ extensions: []
28
56
  extra_rdoc_files:
29
57
  - README.rdoc
30
58
  files:
31
- - Syckfile
32
- - eg/string_vs_block.rb
59
+ - .ruby
33
60
  - lib/ansi/bbcode.rb
34
61
  - lib/ansi/code.rb
62
+ - lib/ansi/columns.rb
35
63
  - lib/ansi/logger.rb
36
64
  - lib/ansi/mixin.rb
37
65
  - lib/ansi/progressbar.rb
38
66
  - lib/ansi/string.rb
67
+ - lib/ansi/table.rb
39
68
  - lib/ansi/terminal/curses.rb
40
69
  - lib/ansi/terminal/stty.rb
41
70
  - lib/ansi/terminal/termios.rb
42
71
  - lib/ansi/terminal/win32.rb
43
72
  - lib/ansi/terminal.rb
73
+ - lib/ansi/version.rb
44
74
  - lib/ansi.rb
45
- - test/test_ansicode.rb
46
- - test/test_bbcode.rb
47
- - test/test_mixin.rb
48
- - test/test_progressbar.rb
75
+ - test/case_ansicode.rb
76
+ - test/case_bbcode.rb
77
+ - test/case_mixin.rb
78
+ - test/case_progressbar.rb
49
79
  - PROFILE
50
80
  - LICENSE
51
81
  - README.rdoc
52
82
  - HISTORY
53
- - ROADMAP
83
+ - NOTICE
54
84
  - VERSION
55
85
  has_rdoc: true
56
86
  homepage: http://rubyworks.github.com/ansi
57
- licenses: []
58
-
87
+ licenses:
88
+ - Apache 2.0
59
89
  post_install_message:
60
90
  rdoc_options:
61
91
  - --title
@@ -65,28 +95,29 @@ rdoc_options:
65
95
  require_paths:
66
96
  - lib
67
97
  required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
68
99
  requirements:
69
100
  - - ">="
70
101
  - !ruby/object:Gem::Version
102
+ hash: 3
71
103
  segments:
72
104
  - 0
73
105
  version: "0"
74
106
  required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
75
108
  requirements:
76
109
  - - ">="
77
110
  - !ruby/object:Gem::Version
111
+ hash: 3
78
112
  segments:
79
113
  - 0
80
114
  version: "0"
81
115
  requirements: []
82
116
 
83
117
  rubyforge_project: ansi
84
- rubygems_version: 1.3.6
118
+ rubygems_version: 1.3.7
85
119
  signing_key:
86
120
  specification_version: 3
87
121
  summary: ANSI codes at your fingertips!
88
- test_files:
89
- - test/test_ansicode.rb
90
- - test/test_bbcode.rb
91
- - test/test_mixin.rb
92
- - test/test_progressbar.rb
122
+ test_files: []
123
+
data/ROADMAP DELETED
@@ -1,11 +0,0 @@
1
- = ROADMAP
2
-
3
- == 1.3
4
-
5
- === Tables
6
-
7
- Consider adding something a Table class.
8
-
9
- See http://github.com/visionmedia/terminal-table
10
- and http://github.com/aptinio/text-table
11
-
data/Syckfile DELETED
@@ -1,74 +0,0 @@
1
- ---
2
- email:
3
- service : Email
4
- file : ~
5
- subject : ~
6
- mailto : ruby-talk@ruby-lang.org
7
- active : true
8
-
9
- grancher:
10
- service: grancher
11
- active: true
12
-
13
- gemcutter:
14
- service: GemCutter
15
- active: true
16
-
17
- box:
18
- service: Box
19
- types : [gem]
20
- active : true
21
-
22
- ridoc:
23
- service: RIDoc
24
- include: ~
25
- exclude: ~
26
- active : true
27
-
28
- rdoc:
29
- service : RDoc
30
- template: newfish
31
- include : ~
32
- exclude : [ Syckfile ]
33
- active : true
34
-
35
- syntax:
36
- service : Syntax
37
- loadpath : ~
38
- exclude : ~
39
- active : false
40
-
41
- testrb:
42
- service : testrb
43
- tests : ~
44
- exclude : ~
45
- loadpath : ~
46
- requires : ~
47
- live : false
48
- active : false
49
-
50
- dnote:
51
- service : DNote
52
- loadpath : ~
53
- labels : ~
54
- exclude : [work]
55
- output : ~
56
- format : ~
57
- active : true
58
-
59
- stats:
60
- service : Stats
61
- title : ~
62
- loadpath : ~
63
- exclude : ~
64
- output : ~
65
- active : true
66
-
67
- vclog:
68
- service : VClog
69
- formats : [json]
70
- #layout : rel # gnu
71
- typed : false
72
- output : ~
73
- active : false
74
-
@@ -1,9 +0,0 @@
1
- require 'benchmark'
2
- require 'ansi/code'
3
-
4
- n = 50000
5
- Benchmark.bmbm(10) do |x|
6
- x.report("string:"){ n.times{|i| ANSI::Code.red(i.to_s) } }
7
- x.report("block :"){ n.times{|i| ANSI::Code.red{i.to_s} } }
8
- end
9
-
@@ -1,19 +0,0 @@
1
- require 'ansi/bbcode'
2
- require 'test/unit'
3
-
4
- class TC_BBCode < Test::Unit::TestCase
5
-
6
- def test_to_ansi
7
- str = "this is [COLOR=red]red[/COLOR], this is [B]bold[/B]"
8
- out = "this is \e[0;31mred\e[0m, this is \e[1mbold\e[0m\n"
9
- assert_equal( out, ANSI::BBCode.bbcode_to_ansi(str) )
10
- end
11
-
12
- def test_to_html
13
- str = "this is [COLOR=red]red[/COLOR], this is [B]bold[/B]"
14
- out = "this is <font color=\"red\">red</font>, this is <strong>bold</strong><br />\n"
15
- assert_equal( out, ANSI::BBCode.bbcode_to_html(str) )
16
- end
17
-
18
- end
19
-