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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c639e0a0e863970d33dd5f04f0503770980f79cb
4
- data.tar.gz: 4e23a7f040b753da355772655775c3a66e6dced3
3
+ metadata.gz: 384e4ddade0f40dc604fd6cbb4fed1f543f54fa3
4
+ data.tar.gz: 80ca4c698e1418b4a3476e27e4179bde0405721c
5
5
  SHA512:
6
- metadata.gz: 5d5f0ce4b01d5d777dbf46c01b4f5276aa1aaa1a1411240b690ad137fb9dc4c676dc4bf399eb90dfd1572aa1549d18afcb74e8c211d423b5c9b38bd5ab5ad2e4
7
- data.tar.gz: 97f72ad639d2b0b2bd40cc828ff4d10d552b0932e2fb946e8755a2c5c52dcdce957ac2db0a5e53a596f2e128db45878a314e202a1b6a6e70ac77010b8d7481e6
6
+ metadata.gz: 40e63c09636602c0a71582f8ea4033571202fe10721655b4853d74d3a391472ce6c574404fe750f543ec4f783b2e66afac247e21ec9ed729c521e0826d54187a
7
+ data.tar.gz: c35ebc20d89396e0af1f8b97716067308c726c290374fecfa71c1b9a9968dcd854f0a1d020e6e7a10407ded8f9fc52273e688538c1b33b54ee05f9c0a2d8fd8d
data/.rubocop.yml CHANGED
@@ -3,16 +3,20 @@
3
3
  # See options at:
4
4
  # https://github.com/bbatsov/rubocop/tree/master/config
5
5
 
6
+ AllCops:
7
+ TargetRubyVersion: 1.9
8
+
6
9
  # General
7
10
 
8
11
  # Multi-line method chaining should be done with leading dots.
9
- Style/DotPosition:
12
+ Layout/DotPosition:
10
13
  EnforcedStyle: trailing
11
14
  SupportedStyles:
12
15
  - leading
13
16
  - trailing
14
17
 
15
- # Enabling!
18
+ # Enabling
19
+ # --------
16
20
 
17
21
  Style/CollectionMethods:
18
22
  Description: 'Preferred collection methods.'
@@ -23,9 +27,59 @@ Style/StringMethods:
23
27
  Description: 'Checks if configured preferred methods are used over non-preferred.'
24
28
  Enabled: true
25
29
 
26
- # Disabling!
30
+ # Disabling
31
+ # ---------
32
+
33
+ # Modifying
34
+ # ---------
27
35
 
36
+ # Check quotes usage according to lint rule below.
28
37
  Style/StringLiterals:
29
- Description: 'Checks if uses of quotes match the configured preference.'
30
- StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#consistent-string-literals'
38
+ Enabled: true
39
+ EnforcedStyle: double_quotes
40
+
41
+ # Configuration parameters: SupportedStyles.
42
+ # SupportedStyles: snake_case, camelCase
43
+ Naming/MethodName:
44
+ EnforcedStyle: snake_case
45
+ Exclude:
46
+ - 'test/**/*'
47
+
48
+ # Cop supports --auto-correct.
49
+ # Configuration parameters: EnforcedStyle, SupportedStyles, AutoCorrectEncodingComment.
50
+ # SupportedStyles: when_needed, always, never
51
+ Style/Encoding:
52
+ Enabled: true
53
+ EnforcedStyle: always
54
+
55
+ # If we fix this, it will change method signature.
56
+ # Save it for major release.
57
+ Style/OptionalArguments:
58
+ Exclude:
59
+ - 'lib/highline/list_renderer.rb'
60
+
61
+ # TemplateRenderer should never fail on method missing.
62
+ Style/MethodMissing:
63
+ Exclude:
64
+ - 'lib/highline/template_renderer.rb'
65
+
66
+ # This is a breaking change for MRI 1.9.
67
+ # Revoke when updating to MRI 2.0 as minimum.
68
+ # Cop supports --auto-correct.
69
+ # Configuration parameters: MinSize, SupportedStyles.
70
+ # SupportedStyles: percent, brackets
71
+ Style/SymbolArray:
72
+ EnforcedStyle: brackets
73
+
74
+ # Cop supports --auto-correct.
75
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
76
+ # SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
77
+ Layout/IndentHeredoc:
78
+ Exclude:
79
+ - 'examples/page_and_wrap.rb'
80
+ - 'highline.gemspec'
81
+ - 'test/acceptance/acceptance.rb'
82
+
83
+ # Cop supports --auto-correct.
84
+ Lint/ScriptPermission:
31
85
  Enabled: false
data/.travis.yml CHANGED
@@ -2,12 +2,13 @@
2
2
  language: ruby
3
3
  dist: trusty
4
4
  sudo: false
5
+ cache: bundler
5
6
  script: "bundle exec rake test"
6
7
  rvm:
7
- - 1.9
8
8
  - 2.0
9
9
  - 2.1
10
10
  - 2.2
11
+ - 2.3
11
12
  - ruby-head
12
13
  - rbx-3.81
13
14
  - jruby-19mode # JRuby in 1.9 mode
@@ -23,6 +24,10 @@ matrix:
23
24
  - rvm: jruby-19mode # JRuby in 1.9 mode
24
25
  - rvm: jruby-head
25
26
  include:
26
- - rvm: 2.3
27
- script: "bundle exec rake test && bundle exec codeclimate-test-reporter" # Run only for 2.3
28
- bundler_args: --without development
27
+ - rvm: 1.9
28
+ before_install:
29
+ - "gem update --system -N"
30
+ - "gem update bundler -N"
31
+ - rvm: 2.4
32
+ script: "bundle exec rake test && bundle exec codeclimate-test-reporter" # Run only for 2.4
33
+ bundler_args: --without code_quality
data/Changelog.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  Below is a complete listing of changes for each revision of HighLine.
4
4
 
5
+ ### 2.0.0-develop.11 / 2017-09-25
6
+ * PR #215 - Apply several Rubocop stylistic suggestions (@abinoam)
7
+ * Update gemspec/Gemfile to newer standards
8
+ * Update travis configuration fixing 1.9 problem
9
+ * Adjust .rubocop.yml with things we don't want to change
10
+
11
+ ### 2.0.0-develop.10 / 2017-06-29
12
+ * PR #214 - Remove `$terminal` (global variable) (@abinoam)
13
+ * Use HighLine.default_instance instead
14
+ * Reorganize/Group code at lib/highline.rb
15
+
5
16
  ### 2.0.0-develop.9 / 2017-06-24
6
17
 
7
18
  * PR #211 / PR #212 - HighLine#use_color= and use_color? as instance methods (@abinoam, @phiggins)
data/Gemfile CHANGED
@@ -1,13 +1,11 @@
1
- source "https://rubygems.org"
1
+ # encoding: utf-8
2
2
 
3
- gem "rake", require: false
4
- gem "rdoc", require: false
3
+ source "https://rubygems.org"
5
4
 
6
- group :development, :test do
7
- gem "code_statistics", require: false
8
- gem "minitest", require: false
9
- end
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
10
6
 
7
+ # Specify your gem's dependencies in tgem.gemspec
8
+ gemspec
11
9
 
12
10
  # Reporting only at one ruby version of travis matrix (no repetition)
13
11
  gem "codeclimate-test-reporter", group: :test, require: false
@@ -17,16 +15,11 @@ platform :ruby do
17
15
  gem "simplecov", group: :test
18
16
  end
19
17
 
20
- group :development do
21
- gem 'pronto'
22
- gem 'pronto-reek', require: false
23
- gem 'pronto-rubocop', require: false
24
- gem 'pronto-poper', require: false
25
-
26
- # Using strict versions of flay and pronto-flay while
27
- # PR https://github.com/mmozuras/pronto-flay/pull/11/files
28
- # is not merged
29
- gem 'flay', '2.7.0'
30
- gem 'pronto-flay', '0.6.1', require: false
31
- gem 'flog'
18
+ group :code_quality do
19
+ gem "flog", require: false
20
+ gem "pronto", require: false
21
+ gem "pronto-flay", require: false
22
+ gem "pronto-poper", require: false
23
+ gem "pronto-reek", require: false
24
+ gem "pronto-rubocop", require: false
32
25
  end
data/Rakefile CHANGED
@@ -1,21 +1,15 @@
1
+ # encoding: utf-8
2
+
1
3
  require "rake/testtask"
2
- require "rubygems/package_task"
3
4
  require "bundler/gem_tasks"
4
- require "code_statistics"
5
-
6
- require "rubygems"
7
5
 
8
- task :default => [:test]
6
+ task default: [:test]
9
7
 
10
8
  Rake::TestTask.new do |test|
11
- test.libs = ["lib", "test"]
9
+ test.libs = %w[lib test]
12
10
  test.verbose = true
13
11
  test.warning = true
14
- test.test_files = FileList['test/test*.rb']
15
- end
16
-
17
- Gem::PackageTask.new(SPEC) do |package|
18
- # do nothing: I just need a gem but this block is required
12
+ test.test_files = FileList["test/test*.rb"]
19
13
  end
20
14
 
21
15
  desc "Run some interactive acceptance tests"
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
 
3
4
  # ansi_colors.rb
4
5
  #
@@ -9,19 +10,13 @@ require "rubygems"
9
10
  require "highline/import"
10
11
 
11
12
  # Supported color sequences.
12
- colors = %w{black red green yellow blue magenta cyan white}
13
+ colors = %w[black red green yellow blue magenta cyan white]
13
14
 
14
15
  # Using color() with symbols.
15
16
  colors.each_with_index do |c, i|
16
17
  say("This should be <%= color('#{c}', :#{c}) %>!")
17
- if i == 0
18
- say( "This should be " +
19
- "<%= color('white on #{c}', :white, :on_#{c}) %>!")
20
- else
21
- say( "This should be " +
22
- "<%= color( '#{colors[i - 1]} on #{c}',
23
- :#{colors[i - 1]}, :on_#{c} ) %>!")
24
- end
18
+ say("This should be <%= color('#{colors[i - 1]} on #{c}', \
19
+ :#{colors[i - 1]}, :on_#{c} ) %>!")
25
20
  end
26
21
 
27
22
  # Using color with constants.
@@ -32,7 +27,7 @@ say("This should be <%= color('underlined', UNDERLINE) %>!")
32
27
  say("This might even <%= BLINK %>blink<%= CLEAR %>!")
33
28
 
34
29
  # It even works with list wrapping.
35
- erb_digits = %w{Zero One Two Three Four} +
30
+ erb_digits = %w[Zero One Two Three Four] +
36
31
  ["<%= color('Five', :blue) %%>"] +
37
- %w{Six Seven Eight Nine}
32
+ %w[Six Seven Eight Nine]
38
33
  say("<%= list(#{erb_digits.inspect}, :columns_down, 3) %>")
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
 
3
4
  # asking_for_arrays.rb
4
5
  #
@@ -9,11 +10,11 @@ require "rubygems"
9
10
  require "highline/import"
10
11
  require "pp"
11
12
 
12
- puts "Using: #{$terminal.terminal.class}"
13
+ puts "Using: #{HighLine.default_instance.class}"
13
14
  puts
14
15
 
15
- grades = ask( "Enter test scores (or a blank line to quit):",
16
- lambda { |ans| ans =~ /^-?\d+$/ ? Integer(ans) : ans} ) do |q|
16
+ grades = ask("Enter test scores (or a blank line to quit):",
17
+ ->(ans) { ans =~ /^-?\d+$/ ? Integer(ans) : ans }) do |q|
17
18
  q.gather = ""
18
19
  end
19
20
 
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
 
3
4
  # basic_usage.rb
4
5
  #
@@ -9,35 +10,38 @@ require "rubygems"
9
10
  require "highline/import"
10
11
  require "yaml"
11
12
 
12
- puts "Using: #{$terminal.terminal.class}"
13
+ puts "Using: #{HighLine.default_instance.terminal.class}"
13
14
  puts
14
15
 
15
- contacts = [ ]
16
+ contacts = []
16
17
 
18
+ # Just define a parse class method and use the class
19
+ # as a parser for HighLine#ask
20
+ #
17
21
  class NameClass
18
- def self.parse( string )
19
- if string =~ /^\s*(\w+),\s*(\w+)\s*$/
20
- self.new($2, $1)
21
- else
22
- raise ArgumentError, "Invalid name format."
23
- end
22
+ def self.parse(string)
23
+ raise ArgumentError, "Invalid name format." unless
24
+ string =~ /^\s*(\w+),\s*(\w+)\s*$/
25
+
26
+ new(Regexp.last_match(2), Regexp.last_match(1))
24
27
  end
25
28
 
26
29
  def initialize(first, last)
27
- @first, @last = first, last
30
+ @first = first
31
+ @last = last
28
32
  end
29
33
 
30
34
  attr_reader :first, :last
31
35
  end
32
36
 
33
- begin
34
- entry = Hash.new
37
+ loop do
38
+ entry = {}
35
39
 
36
40
  # basic output
37
41
  say("Enter a contact:")
38
42
 
39
43
  # basic input
40
- entry[:name] = ask("Name? (last, first) ", NameClass) do |q|
44
+ entry[:name] = ask("Name? (last, first) ", NameClass) do |q|
41
45
  q.validate = /\A\w+, ?\w+\Z/
42
46
  end
43
47
  entry[:company] = ask("Company? ") { |q| q.default = "none" }
@@ -47,27 +51,30 @@ begin
47
51
  q.case = :up
48
52
  q.validate = /\A[A-Z]{2}\Z/
49
53
  end
50
- entry[:zip] = ask("Zip? ") do |q|
54
+ entry[:zip] = ask("Zip? ") do |q|
51
55
  q.validate = /\A\d{5}(?:-?\d{4})?\Z/
52
56
  end
53
- entry[:phone] = ask( "Phone? ",
54
- lambda { |p| p.delete("^0-9").
55
- sub(/\A(\d{3})/, '(\1) ').
56
- sub(/(\d{4})\Z/, '-\1') } ) do |q|
57
- q.validate = lambda { |p| p.delete("^0-9").length == 10 }
57
+ entry[:phone] = ask("Phone? ",
58
+ lambda { |p|
59
+ p.delete("^0-9").
60
+ sub(/\A(\d{3})/, '(\1) ').
61
+ sub(/(\d{4})\Z/, '-\1')
62
+ }) do |q|
63
+ q.validate = ->(p) { p.delete("^0-9").length == 10 }
58
64
  q.responses[:not_valid] = "Enter a phone numer with area code."
59
65
  end
60
66
  entry[:age] = ask("Age? ", Integer) { |q| q.in = 0..105 }
61
67
  entry[:birthday] = ask("Birthday? ", Date)
62
- entry[:interests] = ask( "Interests? (comma separated list) ",
63
- lambda { |str| str.split(/,\s*/) } )
68
+ entry[:interests] = ask("Interests? (comma separated list) ",
69
+ ->(str) { str.split(/,\s*/) })
64
70
  entry[:description] = ask("Enter a description for this contact.") do |q|
65
71
  q.whitespace = :strip_and_collapse
66
72
  end
67
73
 
68
74
  contacts << entry
69
- # shortcut for yes and no questions
70
- end while agree("Enter another contact? ", true)
75
+ # shortcut for yes and no questions
76
+ break unless agree("Enter another contact? ", true)
77
+ end
71
78
 
72
79
  if agree("Save these contacts? ", true)
73
80
  file_name = ask("Enter a file name: ") do |q|
@@ -1,20 +1,21 @@
1
1
  #!/usr/bin/env ruby -w
2
+ # encoding: utf-8
2
3
 
3
4
  # color_scheme.rb
4
5
  #
5
6
  # Created by Jeremy Hinegardner on 2007-01-24
6
7
  # Copyright 2007 Jeremy Hinegardner. All rights reserved
7
8
 
8
- require 'rubygems'
9
- require 'highline/import'
9
+ require "rubygems"
10
+ require "highline/import"
10
11
 
11
12
  # Create a color scheme, naming color patterns with symbol names.
12
13
  ft = HighLine::ColorScheme.new do |cs|
13
- cs[:headline] = [ :bold, :yellow, :on_black ]
14
- cs[:horizontal_line] = [ :bold, :white, :on_blue]
15
- cs[:even_row] = [ :green ]
16
- cs[:odd_row] = [ :magenta ]
17
- end
14
+ cs[:headline] = [:bold, :yellow, :on_black]
15
+ cs[:horizontal_line] = [:bold, :white, :on_blue]
16
+ cs[:even_row] = [:green]
17
+ cs[:odd_row] = [:magenta]
18
+ end
18
19
 
19
20
  # Assign that color scheme to HighLine...
20
21
  HighLine.color_scheme = ft
@@ -26,7 +27,7 @@ say("<%= color('-'*20, :horizontal_line) %>")
26
27
  # Setup a toggle for rows.
27
28
  i = true
28
29
  ("A".."D").each do |row|
29
- row_color = i ? :even_row : :odd_row
30
- say("<%= color('#{row}', '#{row_color}') %>")
31
- i = !i
30
+ row_color = i ? :even_row : :odd_row
31
+ say("<%= color('#{row}', '#{row_color}') %>")
32
+ i = !i
32
33
  end
@@ -1,15 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
 
3
4
  require "rubygems"
4
5
  require "highline/import"
5
6
 
6
- puts "Using: #{$terminal.terminal.class}"
7
+ puts "Using: #{HighLine.default_instance.terminal.class}"
7
8
  puts
8
9
 
9
10
  choices = "ynaq"
10
11
  answer = ask("Your choice [#{choices}]? ") do |q|
11
- q.echo = false
12
- q.character = true
13
- q.validate = /\A[#{choices}]\Z/
14
- end
12
+ q.echo = false
13
+ q.character = true
14
+ q.validate = /\A[#{choices}]\Z/
15
+ end
15
16
  say("Your choice: #{answer}")
data/examples/limit.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby -w
2
+ # encoding: utf-8
2
3
 
3
4
  # limit.rb
4
5
  #
@@ -8,7 +9,7 @@
8
9
  require "rubygems"
9
10
  require "highline/import"
10
11
 
11
- puts "Using: #{$terminal.terminal.class}"
12
+ puts "Using: #{HighLine.default_instance.terminal.class}"
12
13
  puts
13
14
 
14
15
  text = ask("Enter text (max 10 chars): ") { |q| q.limit = 10 }