highline 1.5.1 → 1.5.2
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 +5 -0
- data/INSTALL +6 -0
- data/lib/highline.rb +1 -1
- data/lib/highline/system_extensions.rb +110 -63
- data/test/tc_highline.rb +1 -1
- metadata +12 -5
data/CHANGELOG
CHANGED
data/INSTALL
CHANGED
@@ -14,6 +14,12 @@ version, simply enter the following into your command prompt:
|
|
14
14
|
You must have RubyGems[http://rubyforge.org/projects/rubygems/] installed for
|
15
15
|
the above to work.
|
16
16
|
|
17
|
+
If you want to build the gem locally, make sure you have
|
18
|
+
Rake[http://rubyforge.org/projects/rake/] installed then run the following
|
19
|
+
command:
|
20
|
+
|
21
|
+
$ rake package
|
22
|
+
|
17
23
|
== Installing Manually
|
18
24
|
|
19
25
|
Download the latest version of HighLine from the
|
data/lib/highline.rb
CHANGED
@@ -31,7 +31,7 @@ require "highline/color_scheme"
|
|
31
31
|
#
|
32
32
|
class HighLine
|
33
33
|
# The version of the installed library.
|
34
|
-
VERSION = "1.5.
|
34
|
+
VERSION = "1.5.2".freeze
|
35
35
|
|
36
36
|
# An internal HighLine error. User code does not need to trap this.
|
37
37
|
class QuestionError < StandardError
|
@@ -10,7 +10,9 @@
|
|
10
10
|
class HighLine
|
11
11
|
module SystemExtensions
|
12
12
|
module_function
|
13
|
-
|
13
|
+
|
14
|
+
JRUBY = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
15
|
+
|
14
16
|
#
|
15
17
|
# This section builds character reading and terminal size functions
|
16
18
|
# to suit the proper platform we're running on. Be warned: Here be
|
@@ -19,7 +21,7 @@ class HighLine
|
|
19
21
|
begin
|
20
22
|
# Cygwin will look like Windows, but we want to treat it like a Posix OS:
|
21
23
|
raise LoadError, "Cygwin is a Posix OS." if RUBY_PLATFORM =~ /\bcygwin\b/i
|
22
|
-
|
24
|
+
|
23
25
|
require "Win32API" # See if we're on Windows.
|
24
26
|
|
25
27
|
CHARACTER_MODE = "Win32API" # For Debugging purposes only.
|
@@ -30,40 +32,40 @@ class HighLine
|
|
30
32
|
#
|
31
33
|
def get_character( input = STDIN )
|
32
34
|
@stdin_handle ||= GetStdHandle(STD_INPUT_HANDLE)
|
33
|
-
|
35
|
+
|
34
36
|
begin
|
35
|
-
|
36
|
-
|
37
|
+
SetConsoleEcho(@stdin_handle, false)
|
38
|
+
input.getbyte
|
37
39
|
ensure
|
38
|
-
|
40
|
+
SetConsoleEcho(@stdin_handle, true)
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
44
|
# A Windows savvy method to fetch the console columns, and rows.
|
43
45
|
def terminal_size
|
44
46
|
stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE)
|
45
|
-
|
47
|
+
|
46
48
|
bufx, bufy, curx, cury, wattr, left, top, right, bottom, maxx, maxy =
|
47
|
-
|
49
|
+
GetConsoleScreenBufferInfo(stdout_handle)
|
48
50
|
return right - left + 1, bottom - top + 1
|
49
51
|
end
|
50
52
|
|
51
53
|
# windows savvy console echo toggler
|
52
54
|
def SetConsoleEcho( console_handle, on )
|
53
55
|
mode = GetConsoleMode(console_handle)
|
54
|
-
|
56
|
+
|
55
57
|
# toggle the console echo bit
|
56
58
|
if on
|
57
|
-
|
59
|
+
mode |= ENABLE_ECHO_INPUT
|
58
60
|
else
|
59
|
-
|
61
|
+
mode &= ~ENABLE_ECHO_INPUT
|
60
62
|
end
|
61
|
-
|
63
|
+
|
62
64
|
ok = SetConsoleMode(console_handle, mode)
|
63
65
|
end
|
64
|
-
|
66
|
+
|
65
67
|
# win32 console APIs
|
66
|
-
|
68
|
+
|
67
69
|
STD_INPUT_HANDLE = -10
|
68
70
|
STD_OUTPUT_HANDLE = -11
|
69
71
|
STD_ERROR_HANDLE = -12
|
@@ -81,18 +83,18 @@ class HighLine
|
|
81
83
|
@@apiGetConsoleMode = nil
|
82
84
|
@@apiSetConsoleMode = nil
|
83
85
|
@@apiGetConsoleScreenBufferInfo = nil
|
84
|
-
|
86
|
+
|
85
87
|
def GetStdHandle( handle_type )
|
86
88
|
@@apiGetStdHandle ||= Win32API.new( "kernel32", "GetStdHandle",
|
87
|
-
|
88
|
-
|
89
|
+
['L'], 'L' )
|
90
|
+
|
89
91
|
@@apiGetStdHandle.call( handle_type )
|
90
92
|
end
|
91
|
-
|
93
|
+
|
92
94
|
def GetConsoleMode( console_handle )
|
93
95
|
@@apiGetConsoleMode ||= Win32API.new( "kernel32", "GetConsoleMode",
|
94
|
-
|
95
|
-
|
96
|
+
['L', 'P'], 'I' )
|
97
|
+
|
96
98
|
mode = ' ' * 4
|
97
99
|
@@apiGetConsoleMode.call(console_handle, mode)
|
98
100
|
mode.unpack('L')[0]
|
@@ -100,25 +102,25 @@ class HighLine
|
|
100
102
|
|
101
103
|
def SetConsoleMode( console_handle, mode )
|
102
104
|
@@apiSetConsoleMode ||= Win32API.new( "kernel32", "SetConsoleMode",
|
103
|
-
|
105
|
+
['L', 'L'], 'I' )
|
104
106
|
|
105
107
|
@@apiSetConsoleMode.call(console_handle, mode) != 0
|
106
108
|
end
|
107
109
|
|
108
110
|
def GetConsoleScreenBufferInfo( console_handle )
|
109
111
|
@@apiGetConsoleScreenBufferInfo ||=
|
110
|
-
|
111
|
-
|
112
|
+
Win32API.new( "kernel32", "GetConsoleScreenBufferInfo",
|
113
|
+
['L', 'P'], 'L' )
|
112
114
|
|
113
115
|
format = 'SSSSSssssSS'
|
114
116
|
buf = ([0] * format.size).pack(format)
|
115
117
|
@@apiGetConsoleScreenBufferInfo.call(console_handle, buf)
|
116
118
|
buf.unpack(format)
|
117
119
|
end
|
118
|
-
|
120
|
+
|
119
121
|
rescue LoadError # If we're not on Windows try...
|
120
122
|
begin
|
121
|
-
require "termios" # Unix, first choice.
|
123
|
+
require "termios" # Unix, first choice termios.
|
122
124
|
|
123
125
|
CHARACTER_MODE = "termios" # For Debugging purposes only.
|
124
126
|
|
@@ -141,51 +143,96 @@ class HighLine
|
|
141
143
|
Termios.setattr(input, Termios::TCSANOW, old_settings)
|
142
144
|
end
|
143
145
|
end
|
144
|
-
rescue LoadError
|
145
|
-
|
146
|
+
rescue LoadError # If our first choice fails, try using ffi-ncurses.
|
147
|
+
begin
|
148
|
+
require 'ffi-ncurses' # The ffi gem is builtin to JRUBY and because stty does not
|
149
|
+
# work correctly in JRuby manually installing the ffi-ncurses
|
150
|
+
# gem is the only way to get highline to operate correctly in
|
151
|
+
# JRuby. The ncurses library is only present on unix platforms
|
152
|
+
# so this is not a solution for using highline in JRuby on
|
153
|
+
# windows.
|
154
|
+
|
155
|
+
CHARACTER_MODE = "ncurses" # For Debugging purposes only.
|
156
|
+
|
157
|
+
#
|
158
|
+
# ncurses savvy getc(). (JRuby choice.)
|
159
|
+
#
|
160
|
+
def get_character( input = STDIN )
|
161
|
+
FFI::NCurses.initscr
|
162
|
+
FFI::NCurses.cbreak
|
163
|
+
begin
|
164
|
+
FFI::NCurses.curs_set 0
|
165
|
+
input.getc
|
166
|
+
ensure
|
167
|
+
FFI::NCurses.endwin
|
168
|
+
end
|
169
|
+
end
|
146
170
|
|
147
|
-
#
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
171
|
+
rescue LoadError # If the ffi-ncurses choice fails, try using stty
|
172
|
+
if JRUBY
|
173
|
+
STDERR.puts "\n*** Using highline effectively in JRuby requires manually installing the ffi-ncurses gem.\n*** jruby -S gem install ffi-ncurses"
|
174
|
+
end
|
175
|
+
CHARACTER_MODE = "stty" # For Debugging purposes only.
|
176
|
+
|
177
|
+
#
|
178
|
+
# Unix savvy getc(). (Second choice.)
|
179
|
+
#
|
180
|
+
# *WARNING*: This method requires the external "stty" program!
|
181
|
+
#
|
182
|
+
def get_character( input = STDIN )
|
183
|
+
raw_no_echo_mode
|
184
|
+
|
185
|
+
begin
|
186
|
+
input.getbyte
|
187
|
+
ensure
|
188
|
+
restore_mode
|
189
|
+
end
|
190
|
+
end
|
154
191
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
192
|
+
#
|
193
|
+
# Switched the input mode to raw and disables echo.
|
194
|
+
#
|
195
|
+
# *WARNING*: This method requires the external "stty" program!
|
196
|
+
#
|
197
|
+
def raw_no_echo_mode
|
198
|
+
@state = `stty -g`
|
199
|
+
system "stty raw -echo cbreak isig"
|
200
|
+
end
|
201
|
+
|
202
|
+
#
|
203
|
+
# Restores a previously saved input mode.
|
204
|
+
#
|
205
|
+
# *WARNING*: This method requires the external "stty" program!
|
206
|
+
#
|
207
|
+
def restore_mode
|
208
|
+
system "stty #{@state}"
|
159
209
|
end
|
160
210
|
end
|
161
|
-
|
211
|
+
end
|
212
|
+
if CHARACTER_MODE == 'ncurses'
|
162
213
|
#
|
163
|
-
#
|
164
|
-
#
|
165
|
-
# *WARNING*: This method requires the external "stty" program!
|
166
|
-
#
|
167
|
-
def raw_no_echo_mode
|
168
|
-
@state = `stty -g`
|
169
|
-
system "stty raw -echo cbreak isig"
|
170
|
-
end
|
171
|
-
|
214
|
+
# A ncurses savvy method to fetch the console columns, and rows.
|
172
215
|
#
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
216
|
+
def terminal_size
|
217
|
+
size = [80, 40]
|
218
|
+
FFI::NCurses.initscr
|
219
|
+
begin
|
220
|
+
size = FFI::NCurses.getmaxyx(stdscr).reverse
|
221
|
+
ensure
|
222
|
+
FFI::NCurses.endwin
|
223
|
+
end
|
224
|
+
size
|
179
225
|
end
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
226
|
+
else
|
227
|
+
# A Unix savvy method using stty that to fetch the console columns, and rows.
|
228
|
+
# ... stty does not work in JRuby
|
229
|
+
def terminal_size
|
230
|
+
if /solaris/ =~ RUBY_PLATFORM and
|
231
|
+
`stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/
|
232
|
+
[$2, $1].map { |c| x.to_i }
|
233
|
+
else
|
234
|
+
`stty size`.split.map { |x| x.to_i }.reverse
|
235
|
+
end
|
189
236
|
end
|
190
237
|
end
|
191
238
|
end
|
data/test/tc_highline.rb
CHANGED
@@ -412,7 +412,7 @@ class TestHighLine < Test::Unit::TestCase
|
|
412
412
|
end
|
413
413
|
|
414
414
|
def test_mode
|
415
|
-
assert(%w[Win32API termios stty].include?(HighLine::CHARACTER_MODE))
|
415
|
+
assert(%w[Win32API termios ncurses stty].include?(HighLine::CHARACTER_MODE))
|
416
416
|
end
|
417
417
|
|
418
418
|
class NameClass
|
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.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Edward Gray II
|
@@ -9,11 +9,16 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-30 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description:
|
16
|
+
description: |
|
17
|
+
A high-level IO library that provides validation, type conversion, and more for
|
18
|
+
command-line interfaces. HighLine also includes a complete menu system that can
|
19
|
+
crank out anything from simple list selection to complete shells with just
|
20
|
+
minutes of work.
|
21
|
+
|
17
22
|
email: james@grayproductions.net
|
18
23
|
executables: []
|
19
24
|
|
@@ -58,6 +63,8 @@ files:
|
|
58
63
|
- LICENSE
|
59
64
|
has_rdoc: true
|
60
65
|
homepage: http://highline.rubyforge.org
|
66
|
+
licenses: []
|
67
|
+
|
61
68
|
post_install_message:
|
62
69
|
rdoc_options:
|
63
70
|
- --title
|
@@ -81,9 +88,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
88
|
requirements: []
|
82
89
|
|
83
90
|
rubyforge_project: highline
|
84
|
-
rubygems_version: 1.3.
|
91
|
+
rubygems_version: 1.3.5
|
85
92
|
signing_key:
|
86
|
-
specification_version:
|
93
|
+
specification_version: 3
|
87
94
|
summary: HighLine is a high-level command-line IO library.
|
88
95
|
test_files:
|
89
96
|
- test/ts_all.rb
|