ansi 1.4.3 → 1.6.0

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.
@@ -1,37 +1,37 @@
1
- = ANSI::Mixin
1
+ # ANSI::Mixin
2
2
 
3
3
  The ANSI::Mixin module is design for including into
4
4
  String-like classes. It will support any class that defines
5
5
  a #to_s method.
6
6
 
7
- require 'ansi/mixin'
7
+ require 'ansi/mixin'
8
8
 
9
9
  In this demonstration we will simply include it in the
10
10
  core String class.
11
11
 
12
- class ::String
13
- include ANSI::Mixin
14
- end
12
+ class ::String
13
+ include ANSI::Mixin
14
+ end
15
15
 
16
16
  Now all strings will have access to ANSI's style and color
17
17
  codes via simple method calls.
18
18
 
19
- "roses".red.assert == "\e[31mroses\e[0m"
19
+ "roses".red.assert == "\e[31mroses\e[0m"
20
20
 
21
- "violets".blue.assert == "\e[34mviolets\e[0m"
21
+ "violets".blue.assert == "\e[34mviolets\e[0m"
22
22
 
23
- "sugar".italic.assert == "\e[3msugar\e[0m"
23
+ "sugar".italic.assert == "\e[3msugar\e[0m"
24
24
 
25
25
  The method can be combined, of course.
26
26
 
27
- "you".italic.bold.assert == "\e[1m\e[3myou\e[0m\e[0m"
27
+ "you".italic.bold.assert == "\e[1m\e[3myou\e[0m\e[0m"
28
28
 
29
29
  The mixin also supports background methods.
30
30
 
31
- "envy".on_green.assert == "\e[42menvy\e[0m"
31
+ "envy".on_green.assert == "\e[42menvy\e[0m"
32
32
 
33
33
  And it also supports the combined foreground-on-background
34
34
  methods.
35
35
 
36
- "b&w".white_on_black.assert == "\e[37m\e[40mb&w\e[0m"
36
+ "b&w".white_on_black.assert == "\e[37m\e[40mb&w\e[0m"
37
37
 
@@ -1,52 +1,52 @@
1
- = ANSI::String
1
+ # ANSI::String
2
2
 
3
3
  The ANSI::String class is a very sophisticated implementation
4
4
  of Ruby's standard String class, but one that can handle
5
5
  ANSI codes seamlessly.
6
6
 
7
- require 'ansi/string'
7
+ require 'ansi/string'
8
8
 
9
- flower1 = ANSI::String.new("Roses")
10
- flower2 = ANSI::String.new("Violets")
9
+ flower1 = ANSI::String.new("Roses")
10
+ flower2 = ANSI::String.new("Violets")
11
11
 
12
12
  Like any other string.
13
13
 
14
- flower1.to_s.assert == "Roses"
15
- flower2.to_s.assert == "Violets"
14
+ flower1.to_s.assert == "Roses"
15
+ flower2.to_s.assert == "Violets"
16
16
 
17
17
  Bet now we can add color.
18
18
 
19
- flower1.red!
20
- flower2.blue!
19
+ flower1.red!
20
+ flower2.blue!
21
21
 
22
- flower1.to_s.assert == "\e[31mRoses\e[0m"
23
- flower2.to_s.assert == "\e[34mViolets\e[0m"
22
+ flower1.to_s.assert == "\e[31mRoses\e[0m"
23
+ flower2.to_s.assert == "\e[34mViolets\e[0m"
24
24
 
25
25
  Despite that the string representation now contains ANSI codes,
26
26
  we can still manipulate the string in much the same way that
27
27
  we manipulate an ordinary string.
28
28
 
29
- flower1.size.assert == 5
30
- flower2.size.assert == 7
29
+ flower1.size.assert == 5
30
+ flower2.size.assert == 7
31
31
 
32
32
  Like ordinary strings we can concatenate the two strings
33
33
 
34
- flowers = flower1 + ' ' + flower2
35
- flowers.to_s.assert == "\e[31mRoses\e[0m \e[34mViolets\e[0m"
34
+ flowers = flower1 + ' ' + flower2
35
+ flowers.to_s.assert == "\e[31mRoses\e[0m \e[34mViolets\e[0m"
36
36
 
37
- flowers.size.assert == 13
37
+ flowers.size.assert == 13
38
38
 
39
39
  Standard case conversion such as #upcase and #downcase work.
40
40
 
41
- flower1.upcase.to_s.assert == "\e[31mROSES\e[0m"
42
- flower1.downcase.to_s.assert == "\e[31mroses\e[0m"
41
+ flower1.upcase.to_s.assert == "\e[31mROSES\e[0m"
42
+ flower1.downcase.to_s.assert == "\e[31mroses\e[0m"
43
43
 
44
44
  Some of the most difficult methods to re-implement were the
45
45
  substitution methods such as #sub and #gsub. They are still
46
46
  somewhat more limited than the original string methods, but
47
47
  their primary functionality should work.
48
48
 
49
- flower1.gsub('s', 'z').to_s.assert == "\e[31mRozez\e[0m"
49
+ flower1.gsub('s', 'z').to_s.assert == "\e[31mRozez\e[0m"
50
50
 
51
51
  There are still a number of methods that need implementation.
52
52
  ANSI::String is currently a very partial implementation. But
@@ -0,0 +1,89 @@
1
+ # ANSI::Columns
2
+
3
+ The +Columns+ class makes it easy to create nice looking text columns,
4
+ sorted from top to bottom, right to left (as opposed to the other way
5
+ around).
6
+
7
+ require 'ansi/columns'
8
+
9
+ list = %w{a b c d e f g h i j k l}
10
+
11
+ columns = ANSI::Columns.new(list)
12
+
13
+ columns.to_s(4)
14
+
15
+ The output will be:
16
+
17
+ a d g j
18
+ b e h k
19
+ c f i l
20
+
21
+ Besides an array of elements, Columns.new can take a string in which
22
+ the elements are divided by newlines characters. The default column
23
+ size can also be given to the initializer.
24
+
25
+ list = "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl"
26
+
27
+ columns = ANSI::Columns.new(list, :columns=>6)
28
+
29
+ columns.to_s
30
+
31
+ The output will be:
32
+
33
+ a c e g i k
34
+ b d f h j l
35
+
36
+ If the column count is +nil+, then the number of columns will be calculated
37
+ as a best fit for the current terminal window.
38
+
39
+ ## Padding
40
+
41
+ Columns can adjust the padding between cells.
42
+
43
+ list = %w{a b c d e f g h i j k l}
44
+
45
+ columns = ANSI::Columns.new(list, :padding=>2)
46
+
47
+ columns.to_s(4)
48
+
49
+ The output will be:
50
+
51
+ a d g j
52
+ b e h k
53
+ c f i l
54
+
55
+ ## Alignment
56
+
57
+ Columns can also be aligned either left or right.
58
+
59
+ list = %w{xx xx xx yy y yy z zz z}
60
+
61
+ columns = ANSI::Columns.new(list, :align=>:right)
62
+
63
+ columns.to_s(3)
64
+
65
+ The output will be:
66
+
67
+ xx yy z
68
+ xx y zz
69
+ xx yy z
70
+
71
+ ## Format
72
+
73
+ Lastly, columns can be augmented with ANSI codes. This is done through
74
+ a formatting block. The block can take up to three parameters, the cell
75
+ content, the column and row numbers, or the cell and the column and row
76
+ numbers.
77
+
78
+ list = %w{a b c d e f g h i j k l}
79
+
80
+ columns = ANSI::Columns.new(list){ |c,r| r % 2 == 0 ? :red : :blue }
81
+
82
+ out = columns.to_s(4)
83
+
84
+ out.assert == (
85
+ "\e[31ma \e[0m\e[31md \e[0m\e[31mg \e[0m\e[31mj \e[0m\n" +
86
+ "\e[34mb \e[0m\e[34me \e[0m\e[34mh \e[0m\e[34mk \e[0m\n" +
87
+ "\e[31mc \e[0m\e[31mf \e[0m\e[31mi \e[0m\e[31ml \e[0m\n"
88
+ )
89
+
data/demo/08_table.md ADDED
@@ -0,0 +1,28 @@
1
+ # ANSI::Table
2
+
3
+ The ANSI::Table class can be used to output tabular data with nicely
4
+ formated ASCII cell borders.
5
+
6
+ require 'ansi/table'
7
+
8
+ The constructor takes an 2-dimensional array.
9
+
10
+ data = [
11
+ [ 10, 20, 30 ],
12
+ [ 20, 10, 20 ],
13
+ [ 50, 40, 20 ]
14
+ ]
15
+
16
+ table = ANSI::Table.new(data)
17
+
18
+ table.to_s
19
+
20
+ The output will be:
21
+
22
+ +----+----+----+
23
+ | 10 | 20 | 30 |
24
+ | 20 | 10 | 20 |
25
+ | 50 | 40 | 20 |
26
+ +----+----+----+
27
+
28
+
data/demo/09_diff.md ADDED
@@ -0,0 +1,47 @@
1
+ # ANSI::Diff
2
+
3
+ require 'ansi/diff'
4
+
5
+ a = 'abcYefg'
6
+ b = 'abcXefg'
7
+
8
+ diff = ANSI::Diff.new(a,b)
9
+
10
+ diff.to_s.assert == "\e[31mabc\e[0m\e[33mYefg\e[0m\n\e[31mabc\e[0mXefg"
11
+
12
+ Try another.
13
+
14
+ a = 'abc'
15
+ b = 'abcdef'
16
+
17
+ diff = ANSI::Diff.new(a,b)
18
+
19
+ diff.to_s.assert == "\e[31mabc\e[0m\n\e[31mabc\e[0mdef"
20
+
21
+ And another.
22
+
23
+ a = 'abcXXXghi'
24
+ b = 'abcdefghi'
25
+
26
+ diff = ANSI::Diff.new(a,b)
27
+
28
+ diff.to_s.assert == "\e[31mabc\e[0m\e[33mXXXghi\e[0m\n\e[31mabc\e[0mdefghi"
29
+
30
+ And another.
31
+
32
+ a = 'abcXXXdefghi'
33
+ b = 'abcdefghi'
34
+
35
+ diff = ANSI::Diff.new(a,b)
36
+
37
+ diff.to_s.assert == "\e[31mabc\e[0m\e[33mXXX\e[0m\e[35mdefghi\e[0m\n\e[31mabc\e[0m\e[35mdefghi\e[0m"
38
+
39
+ Comparison that is mostly different.
40
+
41
+ a = 'abcpppz123'
42
+ b = 'abcxyzzz43'
43
+
44
+ diff = ANSI::Diff.new(a,b)
45
+
46
+ diff.to_s.assert == "\e[31mabc\e[0m\e[33mpppz123\e[0m\n\e[31mabc\e[0mxyzzz43"
47
+
data/demo/10_bbcode.md ADDED
@@ -0,0 +1,24 @@
1
+ # ANSI::BBCode
2
+
3
+ The BBCode module provides methods for converting between
4
+ BBCodes, basic HTML and ANSI codes.
5
+
6
+ require 'ansi/bbcode'
7
+
8
+ BBCodes are color and style codes in square brackets, quite
9
+ popular with on line forums.
10
+
11
+ bbcode = "this is [COLOR=red]red[/COLOR], this is [B]bold[/B]"
12
+
13
+ We can convert this to ANSI code simply enough:
14
+
15
+ ansi = ANSI::BBCode.bbcode_to_ansi(bbcode)
16
+
17
+ ansi.assert == "this is \e[0;31mred\e[0m, this is \e[1mbold\e[0m\n"
18
+
19
+ In addition the BBCode module supports conversion to simple HTML.
20
+
21
+ html = ANSI::BBCode.bbcode_to_html(bbcode)
22
+
23
+ html.assert == "this is <font color=\"red\">red</font>, this is <strong>bold</strong><br />\n"
24
+
@@ -0,0 +1,8 @@
1
+ # ANSI::Terminal
2
+
3
+ We should be able to get the terminal width via the `terminal_width` method.
4
+
5
+ width = ANSI::Terminal.terminal_width
6
+
7
+ Integer.assert === width
8
+
data/lib/ansi/chart.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  module ANSI
2
2
 
3
- require 'ansi/version'
4
-
5
3
  # Table of codes used throughout the system.
6
4
  #
7
5
  # @see http://en.wikipedia.org/wiki/ANSI_escape_code
@@ -9,7 +7,7 @@ module ANSI
9
7
  :clear => 0,
10
8
  :reset => 0,
11
9
  :bright => 1,
12
- :bold => 1,
10
+ :bold => 1,
13
11
  :faint => 2,
14
12
  :dark => 2,
15
13
  :italic => 3,
@@ -23,7 +21,6 @@ module ANSI
23
21
  :inverse => 7,
24
22
  :reverse => 7,
25
23
  :negative => 7,
26
- :concealed => 8,
27
24
  :swap => 7,
28
25
  :conceal => 8,
29
26
  :concealed => 8,
@@ -87,12 +84,17 @@ module ANSI
87
84
 
88
85
  #
89
86
  SPECIAL_CHART = {
90
- :save => "\e[s", # Save current cursor positon.
91
- :restore => "\e[u", # Restore saved cursor positon.
92
- :clear_line => "\e[K", # Clear to the end of the current line.
93
- :clr => "\e[K", # Clear to the end of the current line.
94
- :clear_screen => "\e[2J", # Clear the screen and move cursor to home.
95
- :cls => "\e[2J", # Clear the screen and move cursor to home.
87
+ :save => "\e[s", # Save current cursor positon.
88
+ :restore => "\e[u", # Restore saved cursor positon.
89
+ :clear_eol => "\e[K", # Clear to the end of the current line.
90
+ :clr => "\e[K", # Clear to the end of the current line.
91
+ :clear_right => "\e[0K", # Clear to the end of the current line.
92
+ :clear_left => "\e[1K", # Clear to the start of the current line.
93
+ :clear_line => "\e[2K", # Clear the entire current line.
94
+ :clear_screen => "\e[2J", # Clear the screen and move cursor to home.
95
+ :cls => "\e[2J", # Clear the screen and move cursor to home.
96
+ :cursor_hide => "\e[?25l", # Hide the cursor.
97
+ :cursor_show => "\e[?25h" # Show the cursor.
96
98
  }
97
99
 
98
100
  end
data/lib/ansi/code.rb CHANGED
@@ -1,5 +1,11 @@
1
1
  module ANSI
2
2
 
3
+ # Global variable can be used to prevent ANSI codes
4
+ # from being used in ANSI's methods that do so to string.
5
+ #
6
+ # NOTE: This has no effect on methods that return ANSI codes.
7
+ $ansi = true
8
+
3
9
  if RUBY_PLATFORM =~ /(win32|w32)/
4
10
  begin
5
11
  require 'Win32/Console/ANSI'
@@ -11,18 +17,12 @@ module ANSI
11
17
 
12
18
  require 'ansi/constants'
13
19
 
14
- # Global variialbe can be used to prevent ANSI codes
15
- # from being used in ANSI's methods that do so to string.
16
- #
17
- # NOTE: This has no effect of methods that return ANSI codes.
18
- $ansi = true
19
-
20
20
  # TODO: up, down, right, left, etc could have yielding methods too?
21
21
 
22
22
  # ANSI Codes
23
23
  #
24
24
  # Ansi::Code module makes it very easy to use ANSI codes.
25
- # These are esspecially nice for beautifying shell output.
25
+ # These are especially nice for beautifying shell output.
26
26
  #
27
27
  # Ansi::Code.red + "Hello" + Ansi::Code.blue + "World"
28
28
  # => "\e[31mHello\e[34mWorld"
@@ -32,7 +32,7 @@ module ANSI
32
32
  #
33
33
  # IMPORTANT! Do not mixin Ansi::Code, instead use {ANSI::Mixin}.
34
34
  #
35
- # See {ANSI::Code::CHART} for list of all supported codes.
35
+ # See {ANSI::CHART} for list of all supported codes.
36
36
  #
37
37
  module Code
38
38
  extend self
@@ -56,59 +56,6 @@ module ANSI
56
56
  %w{black red green yellow blue magenta cyan white}
57
57
  end
58
58
 
59
- =begin
60
- styles.each do |style|
61
- module_eval <<-END, __FILE__, __LINE__
62
- def #{style}(string=nil)
63
- if string
64
- return string unless $ansi
65
- #warn "use ANSI block notation for future versions"
66
- return "\#{#{style.upcase}}\#{string}\#{ENDCODE}"
67
- end
68
- if block_given?
69
- return yield unless $ansi
70
- return "\#{#{style.upcase}}\#{yield}\#{ENDCODE}"
71
- end
72
- #{style.upcase}
73
- end
74
- END
75
- end
76
- =end
77
-
78
- =begin
79
- # Dynamically create color methods.
80
-
81
- colors.each do |color|
82
- module_eval <<-END, __FILE__, __LINE__
83
- def #{color}(string=nil)
84
- if string
85
- return string unless $ansi
86
- #warn "use ANSI block notation for future versions"
87
- return "\#{#{color.upcase}}\#{string}\#{ENDCODE}"
88
- end
89
- if block_given?
90
- return yield unless $ansi
91
- return "\#{#{color.upcase}}\#{yield}\#{ENDCODE}"
92
- end
93
- #{color.upcase}
94
- end
95
-
96
- def on_#{color}(string=nil)
97
- if string
98
- return string unless $ansi
99
- #warn "use ANSI block notation for future versions"
100
- return "\#{ON_#{color.upcase}}\#{string}\#{ENDCODE}"
101
- end
102
- if block_given?
103
- return yield unless $ansi
104
- return "\#{ON_#{color.upcase}}\#{yield}\#{ENDCODE}"
105
- end
106
- ON_#{color.upcase}
107
- end
108
- END
109
- end
110
- =end
111
-
112
59
  # Return ANSI code given a list of symbolic names.
113
60
  def [](*codes)
114
61
  code(*codes)
@@ -165,10 +112,10 @@ module ANSI
165
112
  end
166
113
 
167
114
  # TODO: How to deal with position codes when $ansi is false?
168
- # Should we reaise an error or just not push the codes?
115
+ # Should we raise an error or just not push the codes?
169
116
  # For now, we will leave this it as is.
170
117
 
171
- # Like +move+ but returns to original positon after
118
+ # Like +move+ but returns to original position after
172
119
  # yielding the block.
173
120
  def display(line, column=0) #:yield:
174
121
  result = "\e[s"
@@ -188,25 +135,27 @@ module ANSI
188
135
  "\e[#{line.to_i};#{column.to_i}H"
189
136
  end
190
137
 
191
- # Move cursor up a specificed number of spaces.
138
+ # Move cursor up a specified number of spaces.
192
139
  def up(spaces=1)
193
140
  "\e[#{spaces.to_i}A"
194
141
  end
195
142
 
196
- # Move cursor down a specificed number of spaces.
143
+ # Move cursor down a specified number of spaces.
197
144
  def down(spaces=1)
198
145
  "\e[#{spaces.to_i}B"
199
146
  end
200
147
 
201
- # Move cursor left a specificed number of spaces.
148
+ # Move cursor left a specified number of spaces.
202
149
  def left(spaces=1)
203
150
  "\e[#{spaces.to_i}D"
204
151
  end
152
+ alias :back :left
205
153
 
206
- # Move cursor right a specificed number of spaces.
154
+ # Move cursor right a specified number of spaces.
207
155
  def right(spaces=1)
208
156
  "\e[#{spaces.to_i}C"
209
157
  end
158
+ alias :forward :right
210
159
 
211
160
  ##
212
161
  #def position
@@ -228,6 +177,7 @@ module ANSI
228
177
  if block_given?
229
178
  string = yield.to_s
230
179
  else
180
+ # first argument must be the string
231
181
  string = codes.shift.to_s
232
182
  end
233
183
 
@@ -260,7 +210,7 @@ module ANSI
260
210
  # Alias for #ansi method.
261
211
  #
262
212
  # @deprecated
263
- # Here for backward scompatibility.
213
+ # Here for backward compatibility.
264
214
  alias_method :style, :ansi
265
215
 
266
216
  # Alias for #unansi method.
@@ -285,7 +235,7 @@ module ANSI
285
235
  # Also resolves :random and :on_random.
286
236
  #
287
237
  # @param codes [Array<Symbol,Integer]
288
- # Symbols or integers to covnert to ANSI code.
238
+ # Symbols or integers to convert to ANSI code.
289
239
  #
290
240
  # @return [String] ANSI code
291
241
  def code(*codes)
@@ -296,11 +246,18 @@ module ANSI
296
246
  when Integer
297
247
  code
298
248
  when Array
299
- rgb(*code)
300
- when :random
249
+ rgb_code(*code)
250
+ when :random, 'random'
301
251
  random
302
- when :on_random
252
+ when :on_random, 'on_random'
303
253
  random(true)
254
+ when String
255
+ # TODO: code =~ /\d\d\d\d\d\d/ ?
256
+ if code.start_with?('#')
257
+ hex_code(code)
258
+ else
259
+ CHART[code.to_sym]
260
+ end
304
261
  else
305
262
  CHART[code.to_sym]
306
263
  end
@@ -318,30 +275,69 @@ module ANSI
318
275
  (background ? 40 : 30) + rand(8)
319
276
  end
320
277
 
278
+ # Creates an XTerm 256 color escape code from RGB value(s). The
279
+ # RGB value can be three arguments red, green and blue respectively
280
+ # each from 0 to 255, or the RGB value can be a single CSS-style
281
+ # hex string.
282
+ #
283
+ # @param background [Boolean]
284
+ # Use `true` for background color, otherwise foreground color.
285
+ #
286
+ def rgb(*args)
287
+ case args.size
288
+ when 1, 2
289
+ hex, background = *args
290
+ esc = "\e[" + hex_code(hex, background) + "m"
291
+ when 3, 4
292
+ red, green, blue, background = *args
293
+ esc = "\e[" + rgb_code(red, green, blue, background) + "m"
294
+ else
295
+ raise ArgumentError
296
+ end
297
+
298
+ if block_given?
299
+ return yield.to_s unless $ansi
300
+ return "#{esc}#{yield}#{ENDCODE}"
301
+ else
302
+ return esc
303
+ end
304
+ end
305
+
306
+ #private
307
+
321
308
  # Creates an xterm-256 color from rgb value.
322
309
  #
323
310
  # @param background [Boolean]
324
311
  # Use `true` for background color, otherwise foreground color.
325
312
  #
326
- def rgb(red, green, blue, background=false)
327
- "#{background ? 48 : 38};5;#{rgb_value(red, green, blue)}"
313
+ def rgb_code(red, green, blue, background=false)
314
+ "#{background ? 48 : 38};5;#{rgb_256(red, green, blue)}"
328
315
  end
329
316
 
330
- # Creates an xterm-256 color from a CSS-style color string.
331
- def hex(string, background=false)
317
+ # Creates an xterm-256 color code from a CSS-style color string.
318
+ #
319
+ # @param string [String]
320
+ # Hex string in CSS style, .e.g. `#5FA0C2`.
321
+ #
322
+ # @param background [Boolean]
323
+ # Use `true` for background color, otherwise foreground color.
324
+ #
325
+ def hex_code(string, background=false)
332
326
  string.tr!('#','')
333
327
  x = (string.size == 6 ? 2 : 1)
334
328
  r, g, b = [0,1,2].map{ |i| string[i*x,2].to_i(16) }
335
- rgb(r, g, b, background)
329
+ rgb_code(r, g, b, background)
336
330
  end
337
331
 
338
- private
339
-
340
- # Gets closest xterm-256 color.
332
+ # Given red, green and blue values between 0 and 255, this method
333
+ # returns the closest XTerm 256 color value.
334
+ #
341
335
  def rgb_256(r, g, b)
342
- r, g, b = [r, g, b].map{ |c| rgb_valid(c); (6 * (c.to_f / 256.0)).to_i }
336
+ # TODO: what was rgb_valid for?
337
+ #r, g, b = [r, g, b].map{ |c| rgb_valid(c); (6 * (c.to_f / 256.0)).to_i }
338
+ r, g, b = [r, g, b].map{ |c| (6 * (c.to_f / 256.0)).to_i }
343
339
  v = (r * 36 + g * 6 + b + 16).abs
344
- raise ArgumentError, "RGB value outside 0-255 range" if v > 255
340
+ raise ArgumentError, "RGB value is outside 0-255 range -- #{v}" if v > 255
345
341
  v
346
342
  end
347
343
 
data/lib/ansi/columns.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'ansi'
2
1
  require 'ansi/terminal'
3
2
 
4
3
  module ANSI
@@ -10,14 +10,13 @@ module ANSI
10
10
  #
11
11
  # Curses savvy getc().
12
12
  #
13
- #
14
13
  def get_character(input = STDIN)
15
14
  Curses.getch()
16
15
  end
17
16
 
18
17
  def terminal_size
19
18
  Curses.init_screen
20
- w, r = Curses.cols, Curses.rows
19
+ w, r = Curses.cols, Curses.lines
21
20
  Curses.close_screen
22
21
  return w, r
23
22
  end
@@ -9,11 +9,11 @@ module ANSI
9
9
  #CHARACTER_MODE = "stty" # For Debugging purposes only.
10
10
 
11
11
  #
12
- # Unix savvy getc(). (Second choice.)
12
+ # Unix savvy getc(). (second choice)
13
13
  #
14
14
  # *WARNING*: This method requires the external "stty" program!
15
15
  #
16
- def get_character( input = STDIN )
16
+ def get_character(input = STDIN)
17
17
  raw_no_echo_mode
18
18
 
19
19
  begin
data/lib/ansi/terminal.rb CHANGED
@@ -22,7 +22,7 @@ module ANSI
22
22
  # Be warned: Here be dragons!
23
23
  #
24
24
  begin
25
- require 'ansi/terminal/' + (mode = modes.pop)
25
+ require 'ansi/terminal/' + (mode = modes.shift)
26
26
  CHARACTER_MODE = mode
27
27
  rescue LoadError
28
28
  retry