highline 1.7.10 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +5 -0
  3. data/.rubocop.yml +84 -0
  4. data/.simplecov +5 -0
  5. data/.travis.yml +35 -9
  6. data/Changelog.md +214 -15
  7. data/Gemfile +16 -5
  8. data/README.md +202 -0
  9. data/Rakefile +8 -20
  10. data/appveyor.yml +37 -0
  11. data/examples/ansi_colors.rb +6 -11
  12. data/examples/asking_for_arrays.rb +6 -2
  13. data/examples/basic_usage.rb +31 -21
  14. data/examples/color_scheme.rb +11 -10
  15. data/examples/get_character.rb +8 -4
  16. data/examples/limit.rb +4 -0
  17. data/examples/menus.rb +16 -10
  18. data/examples/overwrite.rb +9 -5
  19. data/examples/page_and_wrap.rb +5 -4
  20. data/examples/password.rb +4 -0
  21. data/examples/repeat_entry.rb +10 -5
  22. data/examples/trapping_eof.rb +2 -1
  23. data/examples/using_readline.rb +2 -1
  24. data/highline.gemspec +25 -27
  25. data/lib/highline/builtin_styles.rb +129 -0
  26. data/lib/highline/color_scheme.rb +49 -32
  27. data/lib/highline/compatibility.rb +11 -4
  28. data/lib/highline/custom_errors.rb +57 -0
  29. data/lib/highline/import.rb +19 -12
  30. data/lib/highline/io_console_compatible.rb +37 -0
  31. data/lib/highline/list.rb +177 -0
  32. data/lib/highline/list_renderer.rb +261 -0
  33. data/lib/highline/menu/item.rb +32 -0
  34. data/lib/highline/menu.rb +306 -111
  35. data/lib/highline/paginator.rb +52 -0
  36. data/lib/highline/question/answer_converter.rb +103 -0
  37. data/lib/highline/question.rb +281 -131
  38. data/lib/highline/question_asker.rb +150 -0
  39. data/lib/highline/simulate.rb +24 -13
  40. data/lib/highline/statement.rb +88 -0
  41. data/lib/highline/string.rb +36 -0
  42. data/lib/highline/string_extensions.rb +83 -64
  43. data/lib/highline/style.rb +196 -63
  44. data/lib/highline/template_renderer.rb +62 -0
  45. data/lib/highline/terminal/io_console.rb +36 -0
  46. data/lib/highline/terminal/ncurses.rb +38 -0
  47. data/lib/highline/terminal/unix_stty.rb +51 -0
  48. data/lib/highline/terminal.rb +190 -0
  49. data/lib/highline/version.rb +3 -1
  50. data/lib/highline/wrapper.rb +53 -0
  51. data/lib/highline.rb +390 -788
  52. metadata +56 -35
  53. data/INSTALL +0 -59
  54. data/README.rdoc +0 -74
  55. data/lib/highline/system_extensions.rb +0 -254
  56. data/setup.rb +0 -1360
  57. data/test/string_methods.rb +0 -32
  58. data/test/tc_color_scheme.rb +0 -96
  59. data/test/tc_highline.rb +0 -1402
  60. data/test/tc_import.rb +0 -52
  61. data/test/tc_menu.rb +0 -439
  62. data/test/tc_simulator.rb +0 -33
  63. data/test/tc_string_extension.rb +0 -33
  64. data/test/tc_string_highline.rb +0 -38
  65. data/test/tc_style.rb +0 -578
metadata CHANGED
@@ -1,17 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: highline
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.10
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Edward Gray II
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-24 00:00:00.000000000 Z
11
+ date: 2019-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: code_statistics
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
15
43
  requirement: !ruby/object:Gem::Requirement
16
44
  requirements:
17
45
  - - ">="
@@ -33,23 +61,24 @@ email: james@graysoftinc.com
33
61
  executables: []
34
62
  extensions: []
35
63
  extra_rdoc_files:
36
- - README.rdoc
37
- - INSTALL
64
+ - README.md
38
65
  - TODO
39
66
  - Changelog.md
40
67
  - LICENSE
41
68
  files:
42
69
  - ".gitignore"
70
+ - ".rubocop.yml"
71
+ - ".simplecov"
43
72
  - ".travis.yml"
44
73
  - AUTHORS
45
74
  - COPYING
46
75
  - Changelog.md
47
76
  - Gemfile
48
- - INSTALL
49
77
  - LICENSE
50
- - README.rdoc
78
+ - README.md
51
79
  - Rakefile
52
80
  - TODO
81
+ - appveyor.yml
53
82
  - doc/.cvsignore
54
83
  - examples/ansi_colors.rb
55
84
  - examples/asking_for_arrays.rb
@@ -66,40 +95,42 @@ files:
66
95
  - examples/using_readline.rb
67
96
  - highline.gemspec
68
97
  - lib/highline.rb
98
+ - lib/highline/builtin_styles.rb
69
99
  - lib/highline/color_scheme.rb
70
100
  - lib/highline/compatibility.rb
101
+ - lib/highline/custom_errors.rb
71
102
  - lib/highline/import.rb
103
+ - lib/highline/io_console_compatible.rb
104
+ - lib/highline/list.rb
105
+ - lib/highline/list_renderer.rb
72
106
  - lib/highline/menu.rb
107
+ - lib/highline/menu/item.rb
108
+ - lib/highline/paginator.rb
73
109
  - lib/highline/question.rb
110
+ - lib/highline/question/answer_converter.rb
111
+ - lib/highline/question_asker.rb
74
112
  - lib/highline/simulate.rb
113
+ - lib/highline/statement.rb
114
+ - lib/highline/string.rb
75
115
  - lib/highline/string_extensions.rb
76
116
  - lib/highline/style.rb
77
- - lib/highline/system_extensions.rb
117
+ - lib/highline/template_renderer.rb
118
+ - lib/highline/terminal.rb
119
+ - lib/highline/terminal/io_console.rb
120
+ - lib/highline/terminal/ncurses.rb
121
+ - lib/highline/terminal/unix_stty.rb
78
122
  - lib/highline/version.rb
79
- - setup.rb
123
+ - lib/highline/wrapper.rb
80
124
  - site/.cvsignore
81
125
  - site/highline.css
82
126
  - site/images/logo.png
83
127
  - site/index.html
84
- - test/string_methods.rb
85
- - test/tc_color_scheme.rb
86
- - test/tc_highline.rb
87
- - test/tc_import.rb
88
- - test/tc_menu.rb
89
- - test/tc_simulator.rb
90
- - test/tc_string_extension.rb
91
- - test/tc_string_highline.rb
92
- - test/tc_style.rb
93
128
  homepage: https://github.com/JEG2/highline
94
129
  licenses:
95
130
  - Ruby
96
131
  metadata: {}
97
132
  post_install_message:
98
- rdoc_options:
99
- - "--title"
100
- - HighLine Documentation
101
- - "--main"
102
- - README
133
+ rdoc_options: []
103
134
  require_paths:
104
135
  - lib
105
136
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -113,18 +144,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
144
  - !ruby/object:Gem::Version
114
145
  version: '0'
115
146
  requirements: []
116
- rubyforge_project: highline
117
- rubygems_version: 2.6.14
147
+ rubygems_version: 3.0.6
118
148
  signing_key:
119
149
  specification_version: 4
120
150
  summary: HighLine is a high-level command-line IO library.
121
- test_files:
122
- - test/string_methods.rb
123
- - test/tc_color_scheme.rb
124
- - test/tc_highline.rb
125
- - test/tc_import.rb
126
- - test/tc_menu.rb
127
- - test/tc_simulator.rb
128
- - test/tc_string_extension.rb
129
- - test/tc_string_highline.rb
130
- - test/tc_style.rb
151
+ test_files: []
data/INSTALL DELETED
@@ -1,59 +0,0 @@
1
- = Installing HighLine
2
-
3
- RubyGems is the preferred easy install method for HighLine. However, you can
4
- install HighLine manually as described below.
5
-
6
- == Requirements
7
-
8
- HighLine from version >= 1.7.0 requires ruby >= 1.9.3
9
-
10
- == Installing the Gem
11
-
12
- HighLine is intended to be installed via the
13
- RubyGems[http://rubyforge.org/projects/rubygems/] system. To get the latest
14
- version, simply enter the following into your command prompt:
15
-
16
- $ sudo gem install highline
17
-
18
- You must have RubyGems[http://rubyforge.org/projects/rubygems/] installed for
19
- the above to work.
20
-
21
- If you want to build the gem locally, make sure you have
22
- Rake[http://rubyforge.org/projects/rake/] installed then run the following
23
- command:
24
-
25
- $ rake package
26
-
27
- == Installing Manually
28
-
29
- Download the latest version of HighLine from the
30
- {RubyForge project page}[http://rubyforge.org/frs/?group_id=683]. Navigate to
31
- the root project directory and enter:
32
-
33
- $ sudo ruby setup.rb
34
-
35
- == Installing HighLine on JRuby
36
-
37
- If you are using HighLine on JRuby, many features will not work properly
38
- without a working ncurses installation. First, ensure that you have
39
- ncurses installed and then install the ffi-ncurses gem.
40
-
41
- If ffi-ncurses fails to find your ncurses library, you may need to set the
42
- RUBY_FFI_NCURSES envirionment variable, i.e:
43
-
44
- RUBY_FFI_NCURSES_LIB=ncursesw ruby examples/hello.rb
45
-
46
- For details, see the ffi-ncurses documentation at:
47
- http://github.com/seanohalpin/ffi-ncurses
48
-
49
- == Using termios
50
-
51
- While not a requirement, HighLine will take advantage of the termios library if
52
- installed (on Unix). This slightly improves HighLine's character reading
53
- capabilities and thus is recommended for all Unix users.
54
-
55
- If using the HighLine gem, you should be able to add termios as easily as:
56
-
57
- $ sudo gem install termios
58
-
59
- For manual installs, consult the termios documentation.
data/README.rdoc DELETED
@@ -1,74 +0,0 @@
1
- = HighLine
2
-
3
- by James Edward Gray II
4
-
5
- {<img src="https://travis-ci.org/JEG2/highline.svg" alt="Build Status" />}[https://travis-ci.org/JEG2/highline]
6
- {<img src="https://img.shields.io/gem/v/highline.svg?style=flat" />}[http://rubygems.org/gems/highline]
7
-
8
- == Description
9
-
10
- Welcome to HighLine.
11
-
12
- HighLine was designed to ease the tedious tasks of doing console input and
13
- output with low-level methods like gets() and puts(). HighLine provides a
14
- robust system for requesting data from a user, without needing to code all the
15
- error checking and validation rules and without needing to convert the typed
16
- Strings into what your program really needs. Just tell HighLine what you're
17
- after, and let it do all the work.
18
-
19
- == Documentation
20
-
21
- See HighLine and HighLine::Question for documentation.
22
-
23
- Start hacking in your code with HighLine with:
24
-
25
- require 'highline/import'
26
-
27
- == Examples
28
-
29
- Basic usage:
30
-
31
- ask("Company? ") { |q| q.default = "none" }
32
-
33
- Validation:
34
-
35
- ask("Age? ", Integer) { |q| q.in = 0..105 }
36
- ask("Name? (last, first) ") { |q| q.validate = /\A\w+, ?\w+\Z/ }
37
-
38
- Type conversion for answers:
39
-
40
- ask("Birthday? ", Date)
41
- ask("Interests? (comma sep list) ", lambda { |str| str.split(/,\s*/) })
42
-
43
- Reading passwords:
44
-
45
- ask("Enter your password: ") { |q| q.echo = false }
46
- ask("Enter your password: ") { |q| q.echo = "x" }
47
-
48
- ERb based output (with HighLine's ANSI color tools):
49
-
50
- say("This should be <%= color('bold', BOLD) %>!")
51
-
52
- Menus:
53
-
54
- choose do |menu|
55
- menu.prompt = "Please choose your favorite programming language? "
56
-
57
- menu.choice(:ruby) { say("Good choice!") }
58
- menu.choices(:python, :perl) { say("Not from around here, are you?") }
59
- end
60
-
61
- For more examples see the examples/ directory of this project.
62
-
63
- == Requirements
64
-
65
- HighLine from version >= 1.7.0 requires ruby >= 1.9.3
66
-
67
- == Installing
68
-
69
- See the INSTALL file for instructions.
70
-
71
- == Questions and/or Comments
72
-
73
- Feel free to email {James Edward Gray II}[mailto:james@grayproductions.net] or
74
- {Gregory Brown}[mailto:gregory.t.brown@gmail.com] with any questions.
@@ -1,254 +0,0 @@
1
- # system_extensions.rb
2
- #
3
- # Created by James Edward Gray II on 2006-06-14.
4
- # Copyright 2006 Gray Productions. All rights reserved.
5
- #
6
- # This is Free Software. See LICENSE and COPYING for details.
7
-
8
- require "highline/compatibility"
9
-
10
- class HighLine
11
- module SystemExtensions
12
- JRUBY = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
13
-
14
- if JRUBY
15
- JRUBY_OVER_17 = JRUBY_VERSION =~ /^1.7/ || JRUBY_VERSION =~ /^9/
16
-
17
- def initialize_system_extensions
18
- require 'java'
19
- require 'readline'
20
- if JRUBY_OVER_17
21
- java_import 'jline.console.ConsoleReader'
22
-
23
- input = @input && @input.to_inputstream
24
- output = @output && @output.to_outputstream
25
-
26
- @java_console = ConsoleReader.new(input, output)
27
- @java_console.set_history_enabled(false)
28
- @java_console.set_bell_enabled(true)
29
- @java_console.set_pagination_enabled(false)
30
- @java_terminal = @java_console.getTerminal
31
- elsif JRUBY_VERSION =~ /^1.6/
32
- java_import 'java.io.OutputStreamWriter'
33
- java_import 'java.nio.channels.Channels'
34
- java_import 'jline.ConsoleReader'
35
- java_import 'jline.Terminal'
36
-
37
- @java_input = Channels.newInputStream(@input.to_channel)
38
- @java_output = OutputStreamWriter.new(Channels.newOutputStream(@output.to_channel))
39
- @java_terminal = Terminal.getTerminal
40
- @java_console = ConsoleReader.new(@java_input, @java_output)
41
- @java_console.setUseHistory(false)
42
- @java_console.setBellEnabled(true)
43
- @java_console.setUsePagination(false)
44
- end
45
- end
46
- end
47
-
48
- extend self
49
-
50
- #
51
- # This section builds character reading and terminal size functions
52
- # to suit the proper platform we're running on. Be warned: Here be
53
- # dragons!
54
- #
55
- if RUBY_PLATFORM =~ /mswin(?!ce)|mingw|bccwin/i
56
- begin
57
- require "fiddle"
58
-
59
- module WinAPI
60
- include Fiddle
61
- Handle = RUBY_VERSION >= "2.0.0" ? Fiddle::Handle : DL::Handle
62
- Kernel32 = Handle.new("kernel32")
63
- Crt = Handle.new("msvcrt") rescue Handle.new("crtdll")
64
-
65
- def self._getch
66
- @@_m_getch ||= Function.new(Crt["_getch"], [], TYPE_INT)
67
- @@_m_getch.call
68
- end
69
-
70
- def self.GetStdHandle(handle_type)
71
- @@get_std_handle ||= Function.new(Kernel32["GetStdHandle"], [-TYPE_INT], -TYPE_INT)
72
- @@get_std_handle.call(handle_type)
73
- end
74
-
75
- def self.GetConsoleScreenBufferInfo(cons_handle, lp_buffer)
76
- @@get_console_screen_buffer_info ||=
77
- Function.new(Kernel32["GetConsoleScreenBufferInfo"], [TYPE_LONG, TYPE_VOIDP], TYPE_INT)
78
- @@get_console_screen_buffer_info.call(cons_handle, lp_buffer)
79
- end
80
- end
81
- rescue LoadError
82
- require "dl/import"
83
-
84
- module WinAPI
85
- if defined?(DL::Importer)
86
- # Ruby 1.9
87
- extend DL::Importer
88
- else
89
- # Ruby 1.8
90
- extend DL::Importable
91
- end
92
- begin
93
- dlload "msvcrt", "kernel32"
94
- rescue DL::DLError
95
- dlload "crtdll", "kernel32"
96
- end
97
- extern "unsigned long _getch()"
98
- extern "unsigned long GetConsoleScreenBufferInfo(unsigned long, void*)"
99
- extern "unsigned long GetStdHandle(unsigned long)"
100
-
101
- # Ruby 1.8 DL::Importable.import does mname[0,1].downcase so FooBar becomes fooBar
102
- if defined?(getConsoleScreenBufferInfo)
103
- alias_method :GetConsoleScreenBufferInfo, :getConsoleScreenBufferInfo
104
- module_function :GetConsoleScreenBufferInfo
105
- end
106
- if defined?(getStdHandle)
107
- alias_method :GetStdHandle, :getStdHandle
108
- module_function :GetStdHandle
109
- end
110
- end
111
- end
112
-
113
- CHARACTER_MODE = "Win32API" # For Debugging purposes only.
114
-
115
- #
116
- # Windows savvy getc().
117
- #
118
- # *WARNING*: This method ignores <tt>input</tt> and reads one
119
- # character from +STDIN+!
120
- #
121
- def get_character( input = STDIN )
122
- WinAPI._getch
123
- end
124
-
125
- # We do not define a raw_no_echo_mode for Windows as _getch turns off echo
126
- def raw_no_echo_mode
127
- end
128
-
129
- def restore_mode
130
- end
131
-
132
- # A Windows savvy method to fetch the console columns, and rows.
133
- def terminal_size
134
- format = 'SSSSSssssSS'
135
- buf = ([0] * format.size).pack(format)
136
- stdout_handle = WinAPI.GetStdHandle(0xFFFFFFF5)
137
-
138
- WinAPI.GetConsoleScreenBufferInfo(stdout_handle, buf)
139
- _, _, _, _, _,
140
- left, top, right, bottom, _, _ = buf.unpack(format)
141
- return right - left + 1, bottom - top + 1
142
- end
143
- else # If we're not on Windows try...
144
- begin
145
- require "termios" # Unix, first choice termios.
146
-
147
- CHARACTER_MODE = "termios" # For Debugging purposes only.
148
-
149
- def raw_no_echo_mode
150
- @state = Termios.getattr(@input)
151
- new_settings = @state.dup
152
- new_settings.c_lflag &= ~(Termios::ECHO | Termios::ICANON)
153
- new_settings.c_cc[Termios::VMIN] = 1
154
- Termios.setattr(@input, Termios::TCSANOW, new_settings)
155
- end
156
-
157
- def restore_mode
158
- Termios.setattr(@input, Termios::TCSANOW, @state)
159
- end
160
- rescue LoadError # If our first choice fails, try using JLine
161
- if JRUBY # if we are on JRuby. JLine is bundled with JRuby.
162
- CHARACTER_MODE = "jline" # For Debugging purposes only.
163
-
164
- def terminal_size
165
- if JRUBY_OVER_17
166
- [ @java_terminal.get_width, @java_terminal.get_height ]
167
- else
168
- [ @java_terminal.getTerminalWidth, @java_terminal.getTerminalHeight ]
169
- end
170
- end
171
-
172
- def raw_no_echo_mode
173
- @state = @java_console.getEchoCharacter
174
- @java_console.setEchoCharacter 0
175
- end
176
-
177
- def restore_mode
178
- @java_console.setEchoCharacter @state
179
- end
180
- else # If we are not on JRuby, try ncurses
181
- begin
182
- require 'ffi-ncurses'
183
- CHARACTER_MODE = "ncurses" # For Debugging purposes only.
184
-
185
- def raw_no_echo_mode
186
- FFI::NCurses.initscr
187
- FFI::NCurses.cbreak
188
- end
189
-
190
- def restore_mode
191
- FFI::NCurses.endwin
192
- end
193
-
194
- #
195
- # A ncurses savvy method to fetch the console columns, and rows.
196
- #
197
- def terminal_size
198
- size = [80, 40]
199
- FFI::NCurses.initscr
200
- begin
201
- size = FFI::NCurses.getmaxyx(FFI::NCurses.stdscr).reverse
202
- ensure
203
- FFI::NCurses.endwin
204
- end
205
- size
206
- end
207
- rescue LoadError # Finally, if all else fails, use stty
208
- # *WARNING*: This requires the external "stty" program!
209
- CHARACTER_MODE = "stty" # For Debugging purposes only.
210
-
211
- def raw_no_echo_mode
212
- @state = `stty -g`
213
- system "stty raw -echo -icanon isig"
214
- end
215
-
216
- def restore_mode
217
- system "stty #{@state}"
218
- print "\r"
219
- end
220
- end
221
- end
222
- end
223
-
224
- # For termios and stty
225
- if not method_defined?(:terminal_size)
226
- # A Unix savvy method using stty to fetch the console columns, and rows.
227
- # ... stty does not work in JRuby
228
- def terminal_size
229
- begin
230
- require "io/console"
231
- winsize = IO.console.winsize.reverse rescue nil
232
- return winsize if winsize
233
- rescue LoadError
234
- end
235
-
236
- if /solaris/ =~ RUBY_PLATFORM and
237
- `stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/
238
- [$2, $1].map { |x| x.to_i }
239
- elsif `stty size` =~ /^(\d+)\s(\d+)$/
240
- [$2.to_i, $1.to_i]
241
- else
242
- [ 80, 24 ]
243
- end
244
- end
245
- end
246
- end
247
-
248
- if not method_defined?(:get_character)
249
- def get_character( input = STDIN )
250
- input.getbyte
251
- end
252
- end
253
- end
254
- end