highline 1.6.11 → 1.6.12
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/CHANGELOG +4 -0
- data/{README → README.rdoc} +0 -0
- data/Rakefile +3 -6
- data/highline.gemspec +5 -5
- data/lib/highline.rb +1 -1
- data/lib/highline/question.rb +1 -1
- data/lib/highline/simulate.rb +50 -0
- data/lib/highline/string_extensions.rb +33 -0
- data/lib/highline/style.rb +2 -3
- data/lib/highline/system_extensions.rb +16 -8
- data/test/tc_style.rb +1 -1
- metadata +6 -5
data/CHANGELOG
CHANGED
data/{README → README.rdoc}
RENAMED
File without changes
|
data/Rakefile
CHANGED
@@ -4,24 +4,21 @@ require "rubygems/package_task"
|
|
4
4
|
|
5
5
|
require "rubygems"
|
6
6
|
|
7
|
-
dir = File.dirname(__FILE__)
|
8
|
-
lib = File.join(dir, "lib", "highline.rb")
|
9
|
-
version = File.read(lib)[/^\s*VERSION\s*=\s*(['"])(\d+\.\d+\.\d+)\1/, 2]
|
10
|
-
|
11
7
|
task :default => [:test]
|
12
8
|
|
13
9
|
Rake::TestTask.new do |test|
|
14
10
|
test.libs << "test"
|
15
11
|
test.test_files = [ "test/ts_all.rb"]
|
16
12
|
test.verbose = true
|
13
|
+
test.ruby_opts << "-w"
|
17
14
|
end
|
18
15
|
|
19
16
|
Rake::RDocTask.new do |rdoc|
|
20
|
-
rdoc.rdoc_files.include( "README", "INSTALL",
|
17
|
+
rdoc.rdoc_files.include( "README.rdoc", "INSTALL",
|
21
18
|
"TODO", "CHANGELOG",
|
22
19
|
"AUTHORS", "COPYING",
|
23
20
|
"LICENSE", "lib/" )
|
24
|
-
rdoc.main = "README"
|
21
|
+
rdoc.main = "README.rdoc"
|
25
22
|
rdoc.rdoc_dir = "doc/html"
|
26
23
|
rdoc.title = "HighLine Documentation"
|
27
24
|
end
|
data/highline.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
DIR
|
2
|
-
LIB
|
3
|
-
|
1
|
+
DIR = File.dirname(__FILE__)
|
2
|
+
LIB = File.join(DIR, *%w[lib highline.rb])
|
3
|
+
GEM_VERSION = open(LIB) { |lib|
|
4
4
|
lib.each { |line|
|
5
5
|
if v = line[/^\s*VERSION\s*=\s*(['"])(\d+\.\d+\.\d+)\1/, 2]
|
6
6
|
break v
|
@@ -10,14 +10,14 @@ VERSION = open(LIB) { |lib|
|
|
10
10
|
|
11
11
|
SPEC = Gem::Specification.new do |spec|
|
12
12
|
spec.name = "highline"
|
13
|
-
spec.version =
|
13
|
+
spec.version = GEM_VERSION
|
14
14
|
spec.platform = Gem::Platform::RUBY
|
15
15
|
spec.summary = "HighLine is a high-level command-line IO library."
|
16
16
|
spec.files = `git ls-files`.split("\n")
|
17
17
|
|
18
18
|
spec.test_files = `git ls-files -- test/*.rb`.split("\n")
|
19
19
|
spec.has_rdoc = true
|
20
|
-
spec.extra_rdoc_files = %w
|
20
|
+
spec.extra_rdoc_files = %w[README.rdoc INSTALL TODO CHANGELOG LICENSE]
|
21
21
|
spec.rdoc_options << '--title' << 'HighLine Documentation' <<
|
22
22
|
'--main' << 'README'
|
23
23
|
|
data/lib/highline.rb
CHANGED
@@ -30,7 +30,7 @@ require "highline/style"
|
|
30
30
|
#
|
31
31
|
class HighLine
|
32
32
|
# The version of the installed library.
|
33
|
-
VERSION = "1.6.
|
33
|
+
VERSION = "1.6.12".freeze
|
34
34
|
|
35
35
|
# An internal HighLine error. User code does not need to trap this.
|
36
36
|
class QuestionError < StandardError
|
data/lib/highline/question.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
# simulate.rb
|
4
|
+
#
|
5
|
+
# Created by Andy Rossmeissl on 2012-04-29.
|
6
|
+
# Copyright 2005 Gray Productions. All rights reserved.
|
7
|
+
#
|
8
|
+
# This is Free Software. See LICENSE and COPYING for details.
|
9
|
+
#
|
10
|
+
# adapted from https://gist.github.com/194554
|
11
|
+
class HighLine
|
12
|
+
|
13
|
+
# Simulates Highline input for use in tests.
|
14
|
+
class Simulate
|
15
|
+
|
16
|
+
# Creates a simulator with an array of Strings as a script
|
17
|
+
def initialize(strings)
|
18
|
+
@strings = strings
|
19
|
+
end
|
20
|
+
|
21
|
+
# Simulate StringIO#gets by shifting a string off of the script
|
22
|
+
def gets
|
23
|
+
@strings.shift
|
24
|
+
end
|
25
|
+
|
26
|
+
# Simulate StringIO#getbyte by shifting a single character off of the next line of the script
|
27
|
+
def getbyte
|
28
|
+
line = gets
|
29
|
+
if line.length > 0
|
30
|
+
char = line.slice! 0
|
31
|
+
@strings.unshift line
|
32
|
+
char
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# The simulator handles its own EOF
|
37
|
+
def eof?
|
38
|
+
false
|
39
|
+
end
|
40
|
+
|
41
|
+
# A wrapper method that temporarily replaces the Highline instance in $terminal with an instance of this object for the duration of the block
|
42
|
+
def self.with(*strings)
|
43
|
+
@input = $terminal.instance_variable_get :@input
|
44
|
+
$terminal.instance_variable_set :@input, new(strings)
|
45
|
+
yield
|
46
|
+
ensure
|
47
|
+
$terminal.instance_variable_set :@input, @input
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -32,17 +32,29 @@ class HighLine
|
|
32
32
|
def self.included(base)
|
33
33
|
HighLine::COLORS.each do |color|
|
34
34
|
base.class_eval <<-END
|
35
|
+
if public_instance_methods.map { |m| m.to_s }.
|
36
|
+
include? "#{color.downcase}"
|
37
|
+
undef :#{color.downcase}
|
38
|
+
end
|
35
39
|
def #{color.downcase}
|
36
40
|
color(:#{color.downcase})
|
37
41
|
end
|
38
42
|
END
|
39
43
|
base.class_eval <<-END
|
44
|
+
if public_instance_methods.map { |m| m.to_s }.
|
45
|
+
include? "on_#{color.downcase}"
|
46
|
+
undef :on_#{color.downcase}
|
47
|
+
end
|
40
48
|
def on_#{color.downcase}
|
41
49
|
on(:#{color.downcase})
|
42
50
|
end
|
43
51
|
END
|
44
52
|
HighLine::STYLES.each do |style|
|
45
53
|
base.class_eval <<-END
|
54
|
+
if public_instance_methods.map { |m| m.to_s }.
|
55
|
+
include? "#{style.downcase}"
|
56
|
+
undef :#{style.downcase}
|
57
|
+
end
|
46
58
|
def #{style.downcase}
|
47
59
|
color(:#{style.downcase})
|
48
60
|
end
|
@@ -51,31 +63,52 @@ class HighLine
|
|
51
63
|
end
|
52
64
|
|
53
65
|
base.class_eval do
|
66
|
+
if public_instance_methods.map { |m| m.to_s }.include? "color"
|
67
|
+
undef :color
|
68
|
+
end
|
69
|
+
if public_instance_methods.map { |m| m.to_s }.include? "foreground"
|
70
|
+
undef :foreground
|
71
|
+
end
|
54
72
|
def color(*args)
|
55
73
|
self.class.new(HighLine.color(self, *args))
|
56
74
|
end
|
57
75
|
alias_method :foreground, :color
|
58
76
|
|
77
|
+
if public_instance_methods.map { |m| m.to_s }.include? "on"
|
78
|
+
undef :on
|
79
|
+
end
|
59
80
|
def on(arg)
|
60
81
|
color(('on_' + arg.to_s).to_sym)
|
61
82
|
end
|
62
83
|
|
84
|
+
if public_instance_methods.map { |m| m.to_s }.include? "uncolor"
|
85
|
+
undef :uncolor
|
86
|
+
end
|
63
87
|
def uncolor
|
64
88
|
self.class.new(HighLine.uncolor(self))
|
65
89
|
end
|
66
90
|
|
91
|
+
if public_instance_methods.map { |m| m.to_s }.include? "rgb"
|
92
|
+
undef :rgb
|
93
|
+
end
|
67
94
|
def rgb(*colors)
|
68
95
|
color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join
|
69
96
|
raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/
|
70
97
|
color("rgb_#{color_code}".to_sym)
|
71
98
|
end
|
72
99
|
|
100
|
+
if public_instance_methods.map { |m| m.to_s }.include? "on_rgb"
|
101
|
+
undef :on_rgb
|
102
|
+
end
|
73
103
|
def on_rgb(*colors)
|
74
104
|
color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join
|
75
105
|
raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/
|
76
106
|
color("on_rgb_#{color_code}".to_sym)
|
77
107
|
end
|
78
108
|
|
109
|
+
if public_instance_methods.map { |m| m.to_s }.include? "method_missing"
|
110
|
+
undef :method_missing
|
111
|
+
end
|
79
112
|
# TODO Chain existing method_missing
|
80
113
|
def method_missing(method, *args, &blk)
|
81
114
|
if method.to_s =~ /^(on_)?rgb_([0-9a-fA-F]{6})$/
|
data/lib/highline/style.rb
CHANGED
@@ -100,7 +100,7 @@ class HighLine
|
|
100
100
|
string.gsub(/\e\[\d+(;\d+)*m/, '')
|
101
101
|
end
|
102
102
|
|
103
|
-
attr_reader :name, :
|
103
|
+
attr_reader :name, :list
|
104
104
|
attr_accessor :rgb, :builtin
|
105
105
|
|
106
106
|
# Single color/styles have :name, :code, :rgb (possibly), :builtin
|
@@ -114,7 +114,6 @@ class HighLine
|
|
114
114
|
@builtin = defn[:builtin]
|
115
115
|
if @rgb
|
116
116
|
hex = self.class.rgb_hex(@rgb)
|
117
|
-
rgb = self.class.rgb_parts(hex)
|
118
117
|
@name ||= 'rgb_' + hex
|
119
118
|
elsif @list
|
120
119
|
@name ||= @list
|
@@ -162,7 +161,7 @@ class HighLine
|
|
162
161
|
new_code = $1 + ($2.to_i + options[:increment]).to_s + $3
|
163
162
|
end
|
164
163
|
new_rgb = options[:rgb] || @rgb
|
165
|
-
|
164
|
+
self.class.new(self.to_hash.merge(:name=>new_name, :code=>new_code, :rgb=>new_rgb))
|
166
165
|
end
|
167
166
|
|
168
167
|
def on
|
@@ -14,7 +14,7 @@ class HighLine
|
|
14
14
|
module_function
|
15
15
|
|
16
16
|
JRUBY = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
17
|
-
|
17
|
+
|
18
18
|
#
|
19
19
|
# This section builds character reading and terminal size functions
|
20
20
|
# to suit the proper platform we're running on. Be warned: Here be
|
@@ -30,10 +30,10 @@ class HighLine
|
|
30
30
|
|
31
31
|
#
|
32
32
|
# Windows savvy getc().
|
33
|
-
#
|
33
|
+
#
|
34
34
|
# *WARNING*: This method ignores <tt>input</tt> and reads one
|
35
35
|
# character from +STDIN+!
|
36
|
-
#
|
36
|
+
#
|
37
37
|
def get_character( input = STDIN )
|
38
38
|
Win32API.new("msvcrt", "_getch", [ ], "L").Call
|
39
39
|
rescue Exception
|
@@ -53,10 +53,10 @@ class HighLine
|
|
53
53
|
format = 'SSSSSssssSS'
|
54
54
|
buf = ([0] * format.size).pack(format)
|
55
55
|
stdout_handle = m_GetStdHandle.call(0xFFFFFFF5)
|
56
|
-
|
56
|
+
|
57
57
|
m_GetConsoleScreenBufferInfo.call(stdout_handle, buf)
|
58
|
-
|
59
|
-
left, top, right, bottom,
|
58
|
+
_, _, _, _, _,
|
59
|
+
left, top, right, bottom, _, _ = buf.unpack(format)
|
60
60
|
return right - left + 1, bottom - top + 1
|
61
61
|
end
|
62
62
|
rescue LoadError # If we're not on Windows try...
|
@@ -72,7 +72,7 @@ class HighLine
|
|
72
72
|
#
|
73
73
|
def get_character( input = STDIN )
|
74
74
|
return input.getbyte if input.is_a? StringIO
|
75
|
-
|
75
|
+
|
76
76
|
old_settings = Termios.getattr(input)
|
77
77
|
|
78
78
|
new_settings = old_settings.dup
|
@@ -111,7 +111,7 @@ class HighLine
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
-
rescue LoadError
|
114
|
+
rescue LoadError # If the ffi-ncurses choice fails, try using stty
|
115
115
|
CHARACTER_MODE = "stty" # For Debugging purposes only.
|
116
116
|
|
117
117
|
#
|
@@ -163,6 +163,14 @@ class HighLine
|
|
163
163
|
end
|
164
164
|
size
|
165
165
|
end
|
166
|
+
elsif JRUBY
|
167
|
+
# JRuby running on Unix can fetch the number of columns and rows from the builtin Jline library
|
168
|
+
require 'java'
|
169
|
+
java_import 'jline.Terminal'
|
170
|
+
def terminal_size
|
171
|
+
java_terminal = @java_terminal || Terminal.getTerminal
|
172
|
+
[ java_terminal.getTerminalWidth, java_terminal.getTerminalHeight ]
|
173
|
+
end
|
166
174
|
else
|
167
175
|
# A Unix savvy method using stty that to fetch the console columns, and rows.
|
168
176
|
# ... stty does not work in JRuby
|
data/test/tc_style.rb
CHANGED
@@ -134,7 +134,7 @@ class TestStyle < Test::Unit::TestCase
|
|
134
134
|
HighLine::COLORS.each do |color|
|
135
135
|
style = HighLine.const_get('ON_' + color+'_STYLE')
|
136
136
|
assert_instance_of HighLine::Style, style
|
137
|
-
assert_equal
|
137
|
+
assert_equal "ON_#{color}".downcase.to_sym, style.name
|
138
138
|
assert style.builtin
|
139
139
|
code = HighLine.const_get('ON_' + color)
|
140
140
|
assert_instance_of String, code, "Bad code for ON_#{color}"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: highline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.12
|
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: 2012-
|
12
|
+
date: 2012-05-09 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'A high-level IO library that provides validation, type conversion,
|
15
15
|
and more for
|
@@ -25,7 +25,7 @@ email: james@graysoftinc.com
|
|
25
25
|
executables: []
|
26
26
|
extensions: []
|
27
27
|
extra_rdoc_files:
|
28
|
-
- README
|
28
|
+
- README.rdoc
|
29
29
|
- INSTALL
|
30
30
|
- TODO
|
31
31
|
- CHANGELOG
|
@@ -37,7 +37,7 @@ files:
|
|
37
37
|
- COPYING
|
38
38
|
- INSTALL
|
39
39
|
- LICENSE
|
40
|
-
- README
|
40
|
+
- README.rdoc
|
41
41
|
- Rakefile
|
42
42
|
- TODO
|
43
43
|
- doc/.cvsignore
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- lib/highline/import.rb
|
60
60
|
- lib/highline/menu.rb
|
61
61
|
- lib/highline/question.rb
|
62
|
+
- lib/highline/simulate.rb
|
62
63
|
- lib/highline/string_extensions.rb
|
63
64
|
- lib/highline/style.rb
|
64
65
|
- lib/highline/system_extensions.rb
|
@@ -100,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
101
|
version: '0'
|
101
102
|
requirements: []
|
102
103
|
rubyforge_project: highline
|
103
|
-
rubygems_version: 1.8.
|
104
|
+
rubygems_version: 1.8.24
|
104
105
|
signing_key:
|
105
106
|
specification_version: 3
|
106
107
|
summary: HighLine is a high-level command-line IO library.
|