highline 2.0.0.pre.develop.9 → 2.0.0.pre.develop.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +59 -5
  3. data/.travis.yml +9 -4
  4. data/Changelog.md +11 -0
  5. data/Gemfile +12 -19
  6. data/Rakefile +5 -11
  7. data/examples/ansi_colors.rb +6 -11
  8. data/examples/asking_for_arrays.rb +4 -3
  9. data/examples/basic_usage.rb +29 -22
  10. data/examples/color_scheme.rb +11 -10
  11. data/examples/get_character.rb +6 -5
  12. data/examples/limit.rb +2 -1
  13. data/examples/menus.rb +11 -11
  14. data/examples/overwrite.rb +7 -6
  15. data/examples/page_and_wrap.rb +5 -4
  16. data/examples/password.rb +2 -1
  17. data/examples/repeat_entry.rb +7 -5
  18. data/examples/trapping_eof.rb +2 -1
  19. data/examples/using_readline.rb +2 -1
  20. data/highline.gemspec +25 -25
  21. data/lib/highline.rb +103 -111
  22. data/lib/highline/builtin_styles.rb +45 -41
  23. data/lib/highline/color_scheme.rb +32 -28
  24. data/lib/highline/compatibility.rb +3 -3
  25. data/lib/highline/custom_errors.rb +2 -1
  26. data/lib/highline/import.rb +8 -11
  27. data/lib/highline/list.rb +4 -8
  28. data/lib/highline/list_renderer.rb +207 -201
  29. data/lib/highline/menu.rb +75 -63
  30. data/lib/highline/menu/item.rb +2 -0
  31. data/lib/highline/paginator.rb +5 -6
  32. data/lib/highline/question.rb +38 -36
  33. data/lib/highline/question/answer_converter.rb +2 -2
  34. data/lib/highline/question_asker.rb +15 -17
  35. data/lib/highline/simulate.rb +11 -13
  36. data/lib/highline/statement.rb +12 -10
  37. data/lib/highline/string.rb +9 -8
  38. data/lib/highline/string_extensions.rb +30 -14
  39. data/lib/highline/style.rb +68 -45
  40. data/lib/highline/template_renderer.rb +5 -5
  41. data/lib/highline/terminal.rb +24 -31
  42. data/lib/highline/terminal/io_console.rb +2 -2
  43. data/lib/highline/terminal/ncurses.rb +4 -3
  44. data/lib/highline/terminal/unix_stty.rb +12 -9
  45. data/lib/highline/version.rb +1 -1
  46. data/lib/highline/wrapper.rb +12 -11
  47. metadata +34 -43
  48. data/test/acceptance/acceptance.rb +0 -62
  49. data/test/acceptance/acceptance_test.rb +0 -69
  50. data/test/acceptance/at_color_output_using_erb_templates.rb +0 -17
  51. data/test/acceptance/at_echo_false.rb +0 -23
  52. data/test/acceptance/at_readline.rb +0 -37
  53. data/test/io_console_compatible.rb +0 -37
  54. data/test/string_methods.rb +0 -35
  55. data/test/test_answer_converter.rb +0 -26
  56. data/test/test_color_scheme.rb +0 -94
  57. data/test/test_helper.rb +0 -22
  58. data/test/test_highline.rb +0 -1627
  59. data/test/test_import.rb +0 -55
  60. data/test/test_list.rb +0 -60
  61. data/test/test_menu.rb +0 -749
  62. data/test/test_paginator.rb +0 -73
  63. data/test/test_question_asker.rb +0 -20
  64. data/test/test_simulator.rb +0 -24
  65. data/test/test_string_extension.rb +0 -72
  66. data/test/test_string_highline.rb +0 -42
  67. data/test/test_style.rb +0 -613
  68. data/test/test_wrapper.rb +0 -188
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'forwardable'
3
+ require "forwardable"
4
4
 
5
5
  class HighLine
6
6
  # Renders an erb template taking a {Question} and a {HighLine} instance
@@ -42,9 +42,9 @@ class HighLine
42
42
  # is not available.
43
43
  # @return [String] error message.
44
44
  def method_missing(method, *args)
45
- "Method #{method} with args #{args.inspect} " +
46
- "is not available on #{self.inspect}. " +
47
- "Try #{methods(false).sort.inspect}"
45
+ "Method #{method} with args #{args.inspect} " \
46
+ "is not available on #{inspect}. " \
47
+ "Try #{methods(false).sort.inspect}"
48
48
  end
49
49
 
50
50
  # @return [Question, Menu] {#source} attribute.
@@ -59,4 +59,4 @@ class HighLine
59
59
  HighLine.const_get(name)
60
60
  end
61
61
  end
62
- end
62
+ end
@@ -16,24 +16,17 @@ class HighLine
16
16
  # input and output to.
17
17
  # The specialized Terminals all decend from this HighLine::Terminal class
18
18
  class Terminal
19
-
20
19
  # Probe for and return a suitable Terminal instance
21
20
  # @param input [IO] input stream
22
21
  # @param output [IO] output stream
23
22
  def self.get_terminal(input, output)
24
- terminal = nil
25
-
26
23
  # First of all, probe for io/console
27
24
  begin
28
25
  require "io/console"
29
26
  require "highline/terminal/io_console"
30
27
  terminal = HighLine::Terminal::IOConsole.new(input, output)
31
28
  rescue LoadError
32
- end
33
-
34
- # Fall back to UnixStty
35
- unless terminal
36
- require 'highline/terminal/unix_stty'
29
+ require "highline/terminal/unix_stty"
37
30
  terminal = HighLine::Terminal::UnixStty.new(input, output)
38
31
  end
39
32
 
@@ -57,8 +50,7 @@ class HighLine
57
50
 
58
51
  # An initialization callback.
59
52
  # It is called by {.get_terminal}.
60
- def initialize_system_extensions
61
- end
53
+ def initialize_system_extensions; end
62
54
 
63
55
  # @return [Array<Integer, Integer>] two value terminal
64
56
  # size like [columns, lines]
@@ -67,8 +59,7 @@ class HighLine
67
59
  end
68
60
 
69
61
  # Enter Raw No Echo mode.
70
- def raw_no_echo_mode
71
- end
62
+ def raw_no_echo_mode; end
72
63
 
73
64
  # Yieds a block to be executed in Raw No Echo mode and
74
65
  # then restore the terminal state.
@@ -80,40 +71,38 @@ class HighLine
80
71
  end
81
72
 
82
73
  # Restore terminal to its default mode
83
- def restore_mode
84
- end
74
+ def restore_mode; end
85
75
 
86
76
  # Get one character from the terminal
87
77
  # @return [String] one character
88
- def get_character
89
- end
78
+ def get_character; end # rubocop:disable Naming/AccessorMethodName
90
79
 
91
80
  # Get one line from the terminal and format accordling.
92
81
  # Use readline if question has readline mode set.
93
82
  # @param question [HighLine::Question]
94
83
  # @param highline [HighLine]
95
84
  # @param options [Hash]
96
- def get_line(question, highline, options={})
85
+ def get_line(question, highline)
97
86
  raw_answer =
98
- if question.readline
99
- get_line_with_readline(question, highline, options={})
100
- else
101
- get_line_default(highline)
102
- end
87
+ if question.readline
88
+ get_line_with_readline(question, highline)
89
+ else
90
+ get_line_default(highline)
91
+ end
103
92
 
104
93
  question.format_answer(raw_answer)
105
94
  end
106
95
 
107
96
  # Get one line using #readline_read
108
97
  # @param (see #get_line)
109
- def get_line_with_readline(question, highline, options={})
110
- require "readline" # load only if needed
98
+ def get_line_with_readline(question, highline)
99
+ require "readline" # load only if needed
111
100
 
112
101
  question_string = highline.render_statement(question)
113
102
 
114
103
  raw_answer = readline_read(question_string, question)
115
104
 
116
- if !raw_answer and highline.track_eof?
105
+ if !raw_answer && highline.track_eof?
117
106
  raise EOFError, "The input stream is exhausted."
118
107
  end
119
108
 
@@ -140,7 +129,7 @@ class HighLine
140
129
  Readline.readline(prompt, true)
141
130
  end
142
131
 
143
- $VERBOSE = old_verbose
132
+ $VERBOSE = old_verbose
144
133
 
145
134
  raw_answer
146
135
  end
@@ -148,8 +137,8 @@ class HighLine
148
137
  # Get one line from terminal using default #gets method.
149
138
  # @param highline (see #get_line)
150
139
  def get_line_default(highline)
151
- raise EOFError, "The input stream is exhausted." if highline.track_eof? and
152
- highline.input.eof?
140
+ raise EOFError, "The input stream is exhausted." if highline.track_eof? &&
141
+ highline.input.eof?
153
142
  highline.input.gets
154
143
  end
155
144
 
@@ -157,12 +146,12 @@ class HighLine
157
146
 
158
147
  # Running on JRuby?
159
148
  def jruby?
160
- defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
149
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
161
150
  end
162
151
 
163
152
  # Running on Rubinius?
164
153
  def rubinius?
165
- defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
154
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx"
166
155
  end
167
156
 
168
157
  # Running on Windows?
@@ -190,7 +179,11 @@ class HighLine
190
179
 
191
180
  # Saves terminal state using shell stty command.
192
181
  def save_stty
193
- @stty_save = `stty -g`.chomp rescue nil
182
+ @stty_save = begin
183
+ `stty -g`.chomp
184
+ rescue StandardError
185
+ nil
186
+ end
194
187
  end
195
188
 
196
189
  # Restores terminal state using shell stty command.
@@ -21,9 +21,9 @@ class HighLine
21
21
  end
22
22
 
23
23
  # (see Terminal#get_character)
24
- def get_character
24
+ def get_character # rubocop:disable Naming/AccessorMethodName
25
25
  input.getch # from ruby io/console
26
26
  end
27
27
  end
28
28
  end
29
- end
29
+ end
@@ -3,9 +3,10 @@
3
3
  class HighLine
4
4
  class Terminal
5
5
  # NCurses HighLine::Terminal
6
- # @note Code migrated +UNTESTED+ from the old code base to the new terminal api.
6
+ # @note Code migrated +UNTESTED+ from the old code base to the new
7
+ # terminal api.
7
8
  class NCurses < Terminal
8
- require 'ffi-ncurses'
9
+ require "ffi-ncurses"
9
10
 
10
11
  # (see Terminal#raw_no_echo_mode)
11
12
  def raw_no_echo_mode
@@ -34,4 +35,4 @@ class HighLine
34
35
  end
35
36
  end
36
37
  end
37
- end
38
+ end
@@ -5,25 +5,28 @@ class HighLine
5
5
  # HighLine::Terminal option that uses external "stty" program
6
6
  # to control terminal options.
7
7
  class UnixStty < Terminal
8
-
9
8
  # A Unix savvy method using stty to fetch the console columns, and rows.
10
9
  # ... stty does not work in JRuby
11
10
  # @return (see Terminal#terminal_size)
12
11
  def terminal_size
13
12
  begin
14
13
  require "io/console"
15
- winsize = IO.console.winsize.reverse rescue nil
14
+ winsize = begin
15
+ IO.console.winsize.reverse
16
+ rescue NoMethodError
17
+ nil
18
+ end
16
19
  return winsize if winsize
17
20
  rescue LoadError
18
21
  end
19
22
 
20
- if /solaris/ =~ RUBY_PLATFORM and
21
- `stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/
22
- [$2, $1].map { |x| x.to_i }
23
+ if /solaris/ =~ RUBY_PLATFORM &&
24
+ `stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/
25
+ [Regexp.last_match(2), Regexp.last_match(1)].map(&:to_i)
23
26
  elsif `stty size` =~ /^(\d+)\s(\d+)$/
24
- [$2.to_i, $1.to_i]
27
+ [Regexp.last_match(2).to_i, Regexp.last_match(1).to_i]
25
28
  else
26
- [ 80, 24 ]
29
+ [80, 24]
27
30
  end
28
31
  end
29
32
 
@@ -40,9 +43,9 @@ class HighLine
40
43
  end
41
44
 
42
45
  # (see Terminal#get_character)
43
- def get_character( input = STDIN )
46
+ def get_character(input = STDIN)
44
47
  input.getc
45
48
  end
46
49
  end
47
50
  end
48
- end
51
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  class HighLine
4
4
  # The version of the installed library.
5
- VERSION = "2.0.0-develop.9".freeze
5
+ VERSION = "2.0.0-develop.11".freeze
6
6
  end
@@ -1,12 +1,12 @@
1
1
  # coding: utf-8
2
2
 
3
- class HighLine
3
+ require "English"
4
4
 
5
+ class HighLine
5
6
  # A simple Wrapper module that is aware of ANSI escape codes.
6
7
  # It compensates for the ANSI escape codes so it works on the
7
8
  # actual (visual) line length.
8
9
  module Wrapper
9
-
10
10
  #
11
11
  # Wrap a sequence of _lines_ at _wrap_at_ characters per line. Existing
12
12
  # newlines will not be affected by this process, but additional newlines
@@ -18,24 +18,25 @@ class HighLine
18
18
  return text unless wrap_at
19
19
  wrap_at = Integer(wrap_at)
20
20
 
21
- wrapped = [ ]
21
+ wrapped = []
22
22
  text.each_line do |line|
23
23
  # take into account color escape sequences when wrapping
24
- wrap_at = wrap_at + (line.length - actual_length(line))
24
+ wrap_at += (line.length - actual_length(line))
25
25
  while line =~ /([^\n]{#{wrap_at + 1},})/
26
- search = $1.dup
27
- replace = $1.dup
28
- if index = replace.rindex(" ", wrap_at)
26
+ search = Regexp.last_match(1).dup
27
+ replace = Regexp.last_match(1).dup
28
+ index = replace.rindex(" ", wrap_at)
29
+ if index
29
30
  replace[index, 1] = "\n"
30
31
  replace.sub!(/\n[ \t]+/, "\n")
31
32
  line.sub!(search, replace)
32
33
  else
33
- line[$~.begin(1) + wrap_at, 0] = "\n"
34
+ line[$LAST_MATCH_INFO.begin(1) + wrap_at, 0] = "\n"
34
35
  end
35
36
  end
36
37
  wrapped << line
37
38
  end
38
- return wrapped.join
39
+ wrapped.join
39
40
  end
40
41
 
41
42
  #
@@ -45,8 +46,8 @@ class HighLine
45
46
  # @param string_with_escapes [String] any ANSI colored String
46
47
  # @return [Integer] length based on the visual size of the String
47
48
  # (without the escape codes)
48
- def self.actual_length( string_with_escapes )
49
+ def self.actual_length(string_with_escapes)
49
50
  string_with_escapes.to_s.gsub(/\e\[\d{1,2}m/, "").length
50
51
  end
51
52
  end
52
- end
53
+ end
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: 2.0.0.pre.develop.9
4
+ version: 2.0.0.pre.develop.11
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-06-25 00:00:00.000000000 Z
11
+ date: 2017-09-25 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
  - - ">="
@@ -96,27 +124,6 @@ files:
96
124
  - site/highline.css
97
125
  - site/images/logo.png
98
126
  - site/index.html
99
- - test/acceptance/acceptance.rb
100
- - test/acceptance/acceptance_test.rb
101
- - test/acceptance/at_color_output_using_erb_templates.rb
102
- - test/acceptance/at_echo_false.rb
103
- - test/acceptance/at_readline.rb
104
- - test/io_console_compatible.rb
105
- - test/string_methods.rb
106
- - test/test_answer_converter.rb
107
- - test/test_color_scheme.rb
108
- - test/test_helper.rb
109
- - test/test_highline.rb
110
- - test/test_import.rb
111
- - test/test_list.rb
112
- - test/test_menu.rb
113
- - test/test_paginator.rb
114
- - test/test_question_asker.rb
115
- - test/test_simulator.rb
116
- - test/test_string_extension.rb
117
- - test/test_string_highline.rb
118
- - test/test_style.rb
119
- - test/test_wrapper.rb
120
127
  homepage: https://github.com/JEG2/highline
121
128
  licenses:
122
129
  - Ruby
@@ -136,25 +143,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
143
  - !ruby/object:Gem::Version
137
144
  version: 1.3.1
138
145
  requirements: []
139
- rubyforge_project: highline
140
- rubygems_version: 2.6.11
146
+ rubyforge_project:
147
+ rubygems_version: 2.6.13
141
148
  signing_key:
142
149
  specification_version: 4
143
150
  summary: HighLine is a high-level command-line IO library.
144
- test_files:
145
- - test/io_console_compatible.rb
146
- - test/string_methods.rb
147
- - test/test_answer_converter.rb
148
- - test/test_color_scheme.rb
149
- - test/test_helper.rb
150
- - test/test_highline.rb
151
- - test/test_import.rb
152
- - test/test_list.rb
153
- - test/test_menu.rb
154
- - test/test_paginator.rb
155
- - test/test_question_asker.rb
156
- - test/test_simulator.rb
157
- - test/test_string_extension.rb
158
- - test/test_string_highline.rb
159
- - test/test_style.rb
160
- - test/test_wrapper.rb
151
+ test_files: []
@@ -1,62 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # coding: utf-8
3
-
4
- current_dir = File.dirname(File.expand_path(__FILE__))
5
-
6
- # All acceptance test files begins with 'at_'
7
- acceptance_test_files = Dir["#{current_dir}/at_*"]
8
-
9
- # Load each acceptance test file making
10
- # all tests to be run
11
- acceptance_test_files.each { |file| load file }
12
-
13
- # Print a report
14
-
15
- report = <<EOF
16
-
17
- ===
18
- Well done!
19
-
20
- Below you have a report with all the answers you gave.
21
- It has also some environment information to help us debugging.
22
-
23
- If any of the tests have not passed on your environment,
24
- please copy/past the text bellow and send to us.
25
-
26
- If you are familiar with GitHub you can report the failing test
27
- as a GitHub issue at https://github.com/JEG2/highline/issues.
28
- If possible, always check if your issue is already reported
29
- by someone else. If so, just report that you are also affected
30
- on the same alredy open issued.
31
-
32
- If you are more confortable with e-mail, you could send it to
33
- james@grayproductions.net
34
-
35
- === HighLine Acceptance Tests Report
36
- Date: #{Time.now.utc}
37
- HighLine::VERSION: #{HighLine::VERSION}
38
- Terminal: #{$terminal.terminal.class}
39
- RUBY_DESCRIPTION: #{RUBY_DESCRIPTION rescue 'not available'}
40
- Readline::VERSION: #{Readline::VERSION rescue 'not availabe'}
41
- ENV['SHELL']: #{ENV['SHELL']}
42
- ENV['TERM']: #{ENV['TERM']}
43
- ENV['TERM_PROGRAM']: #{ENV['TERM_PROGRAM']}
44
-
45
- Answers:
46
- #{HighLine::AcceptanceTest.answers_for_report}
47
- EOF
48
-
49
- puts report
50
-
51
- timestamp = Time.now.strftime('%Y%m%d%H%M%S')
52
- filename = "highlinetests-#{timestamp}.log"
53
-
54
- File.open "#{filename}", 'w+' do |f|
55
- f.puts report
56
- end
57
-
58
- puts
59
- puts "You can also see the above information in"
60
- puts "a timestamped file named #{filename}"
61
- puts "at the current directory."
62
- puts