highline 2.0.3 → 3.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c2652997ba01a32e3b6357a60c0567724e235d3763fa7dd000a6adbf71a6d75
4
- data.tar.gz: 93fa0727991ba6d16e36a3a76f48784b54c15b8d4e8b32a0703a12c665e62601
3
+ metadata.gz: 00a520ba256dca588d4af090b8a9c41d808bd208966d3d3eabaf17a5e5516ad1
4
+ data.tar.gz: c0ab504488edce75cb6e290a119467ffb91ebbd9abbab3acedcc3da7198ad554
5
5
  SHA512:
6
- metadata.gz: aae3c4c97d87a3b3fd5e12fcb234acc5a3470e3392942db6b369ea42c83fdd2ae90104b8a6957f8250616c35c16f1ab5acb11edeeb585f505f392367293154e9
7
- data.tar.gz: 1dc931251446b234c9fff7c2389cd4d156a2fdd8619dc3f57a74cc06b8b50cf4c10ae7943fdfb6b20c2ef1359721d38faa03c875c5ef973bf38a87942173c060
6
+ metadata.gz: '09efdc10dabb3dfedf2155faff822c845f819119f18abdcaa298607df6cf279ed955d693e31db5038509a16dbbee35f61fa18dc88591cfa6d2aa9543213d0129'
7
+ data.tar.gz: c0a80e2ed2caaada155c2b66433dcafec06e0abb63bfe206470e65697b46f8a9888bbc7d2c64bb21f7cbf46218b5561a00f62f115f9d4355d098cbf911cf1523
@@ -0,0 +1,45 @@
1
+ name: Tests
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ strategy:
8
+ fail-fast: false
9
+ matrix:
10
+ os: [ubuntu-latest]
11
+ ruby-version:
12
+ - head
13
+ - '3.2'
14
+ - '3.1'
15
+ - '3.0'
16
+ - jruby
17
+ - jruby-head
18
+ - truffleruby
19
+ - truffleruby-head
20
+ - truffleruby+graalvm
21
+ include:
22
+ - os: windows-latest
23
+ ruby-version: head
24
+ - os: windows-latest
25
+ ruby-version: '3.1'
26
+ - os: windows-latest
27
+ ruby-version: mingw
28
+ - os: windows-latest
29
+ ruby-version: mswin
30
+ - os: windows-latest
31
+ ruby-version: ucrt
32
+ - os: macos-latest
33
+ ruby-version: 'head'
34
+ - os: macos-latest
35
+ ruby-version: '3.1'
36
+ runs-on: ${{ matrix.os }}
37
+ steps:
38
+ - uses: actions/checkout@v3
39
+ - name: Set up Ruby ${{ matrix.ruby-version }}
40
+ uses: ruby/setup-ruby@v1
41
+ with:
42
+ ruby-version: ${{ matrix.ruby-version }}
43
+ bundler-cache: true # 'bundle install' and cache
44
+ - name: Run tests
45
+ run: bundle exec rake test
data/Changelog.md CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  Below is a complete listing of changes for each revision of HighLine.
4
4
 
5
+ ### 3.0.0.pre.1 / 2023-04-27
6
+ * PR #263 - Release 3.0.0.pre.1
7
+ * Raise minimum Ruby version requirement to 3.0
8
+ * PR #262 - Do not call stty on non-tty (@kbrock)
9
+ * PR #260 / I #43 - Ctrl-U (erase line) handling (@abinoam, issue by @gutenye)
10
+ * PR #259 / I #236 - Handle Ctrl-C when Question#echo = false (@abinoam, @Fahhetah, issue by @aspyct)
11
+ * PR #258 / I #246 - Add validation class support (@abinoam, issue by @Joshfindit)
12
+ * Make it dry-types compatible through the use of `#valid?`
13
+ * Solve the multiple answers in one line problem with a combination of custom coercion (parser) and custom validation
14
+ * PR #257 / I #233 - Show Question#default hint for non String values (@abinoam, issue by @branch14)
15
+ * Add Question#default_hint_show to allow disabling it.
16
+ * PR #256 / I #249 - Fix Array validation in Question#in (@abinoam, issue by @esotericpig)
17
+
18
+ ### 2.1.0 / 2022-12-31
19
+ * PR #255 - Change minimum Ruby version requirement to 2.3 (@abinoam)
20
+ * PR #254 - Improve Github Actions file (@abinoam)
21
+ * PR #253, PR #251 - Setup GitHub Actions and remove Travis (@petergoldstein, rev by @AlexWayfer)
22
+ * PR #250 - Fix file permissions (@bdunne)
23
+
5
24
  ### 2.0.3 / 2019-10-11
6
25
  * PR #245 - Suppress `Psych.safe_load` arg warn (@koic)
7
26
 
data/Gemfile CHANGED
@@ -7,16 +7,13 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
7
7
  # Specify your gem's dependencies in tgem.gemspec
8
8
  gemspec
9
9
 
10
- platform :ruby do
11
- # Running only on MRI
12
- gem "simplecov", group: :test
13
- end
10
+ gem "simplecov", group: :test, require: false
14
11
 
15
12
  group :code_quality do
16
13
  gem "flog", require: false
17
14
  gem "pronto", require: false, platform: :ruby
18
15
  gem "pronto-flay", require: false, platform: :ruby
19
- gem "pronto-poper", require: false, platform: :ruby
16
+ # gem "pronto-poper", require: false, platform: :ruby
20
17
  gem "pronto-reek", require: false, platform: :ruby
21
18
  gem "pronto-rubocop", require: false, platform: :ruby
22
19
  end
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  HighLine
2
2
  ========
3
3
 
4
- [![Build Status](https://travis-ci.org/JEG2/highline.svg?branch=master)](https://travis-ci.org/JEG2/highline)
5
- [![Build status](https://ci.appveyor.com/api/projects/status/4p05fijpah77d28x/branch/master?svg=true)](https://ci.appveyor.com/project/JEG2/highline/branch/master)
4
+ [![Tests](https://github.com/JEG2/highline/actions/workflows/ci.yml/badge.svg)](https://github.com/JEG2/highline/actions/workflows/ci.yml)
6
5
  [![Gem Version](https://badge.fury.io/rb/highline.svg)](https://badge.fury.io/rb/highline)
7
6
  [![Code Climate](https://codeclimate.com/github/JEG2/highline/badges/gpa.svg)](https://codeclimate.com/github/JEG2/highline)
8
7
  [![Test Coverage](https://codeclimate.com/github/JEG2/highline/badges/coverage.svg)](https://codeclimate.com/github/JEG2/highline/coverage)
@@ -44,12 +43,48 @@ puts "You have answered: #{answer}"
44
43
 
45
44
  cli.ask("Company? ") { |q| q.default = "none" }
46
45
 
46
+ ## Disable default value hint showing
47
+
48
+ my_special_default_object = Object.new
49
+
50
+ cli.ask("Question? ") do |q|
51
+ q.default = my_special_default_object
52
+ q.default_hint_show = false
53
+ end
54
+
47
55
 
48
56
  # Validation
49
57
 
50
58
  cli.ask("Age? ", Integer) { |q| q.in = 0..105 }
51
59
  cli.ask("Name? (last, first) ") { |q| q.validate = /\A\w+, ?\w+\Z/ }
52
60
 
61
+ ## Validation with custom class
62
+ class ZeroToTwentyFourValidator
63
+ def self.valid?(answer)
64
+ (0..24).include? answer.to_i
65
+ end
66
+
67
+ def self.inspect
68
+ "(0..24) rule"
69
+ end
70
+ end
71
+
72
+ cli.ask("What hour of the day is it?: ", Integer) do |q|
73
+ q.validate = ZeroToTwentyFourValidator
74
+ end
75
+
76
+ ## Validation with Dry::Types
77
+ ## `Dry::Types` provides a `valid?` method so it can be used effortlessly
78
+
79
+ require 'dry-type'
80
+
81
+ module Types
82
+ include Dry.Types
83
+ end
84
+
85
+ cli.ask("Type an integer:", Integer) do |q|
86
+ q.validate = Types::Coercible::Integer
87
+ end
53
88
 
54
89
  # Type conversion for answers:
55
90
 
@@ -0,0 +1,39 @@
1
+ require 'highline'
2
+
3
+ cli = HighLine.new
4
+
5
+ # The parser
6
+ class ArrayOfNumbersFromString
7
+ def self.parse(string)
8
+ string.scan(/\d+/).map(&:to_i)
9
+ end
10
+ end
11
+
12
+ # The validator
13
+ class ArrayOfNumbersFromStringInRange
14
+ def self.in?(range)
15
+ new(range)
16
+ end
17
+
18
+ attr_reader :range
19
+
20
+ def initialize(range)
21
+ @range = range
22
+ end
23
+
24
+ def valid?(answer)
25
+ ary = ArrayOfNumbersFromString.parse(answer)
26
+ ary.all? ->(number) { range.include? number }
27
+ end
28
+
29
+ def inspect
30
+ "in range #@range validator"
31
+ end
32
+ end
33
+
34
+ answer = cli.ask("Which number? (0 or <Enter> to skip): ", ArrayOfNumbersFromString) { |q|
35
+ q.validate = ArrayOfNumbersFromStringInRange.in?(0..10)
36
+ q.default = 0
37
+ }
38
+
39
+ puts "Your answer was: #{answer} and it was correctly validated and coerced into an #{answer.class}"
data/highline.gemspec CHANGED
@@ -27,9 +27,10 @@ DESCRIPTION
27
27
 
28
28
  spec.extra_rdoc_files = %w[README.md TODO Changelog.md LICENSE]
29
29
 
30
- spec.required_ruby_version = ">= 1.9.3"
30
+ spec.required_ruby_version = ">= 3.0"
31
31
 
32
32
  spec.add_development_dependency "bundler"
33
33
  spec.add_development_dependency "rake"
34
34
  spec.add_development_dependency "minitest"
35
+ spec.add_development_dependency "dry-types"
35
36
  end
@@ -13,7 +13,7 @@ require "tempfile"
13
13
  #
14
14
 
15
15
  module IOConsoleCompatible
16
- def getch
16
+ def getch(min:nil, time:nil, intr: nil)
17
17
  getc
18
18
  end
19
19
 
data/lib/highline/menu.rb CHANGED
File without changes
@@ -9,7 +9,7 @@ class HighLine
9
9
  extend Forwardable
10
10
 
11
11
  def_delegators :@question,
12
- :answer, :answer=, :check_range,
12
+ :answer, :answer=,
13
13
  :directory, :answer_type, :choices_complete
14
14
 
15
15
  # It should be initialized with a Question object.
@@ -26,10 +26,7 @@ class HighLine
26
26
  # it makes the conversion and returns the answer.
27
27
  # @return [Object] the converted answer.
28
28
  def convert
29
- return unless answer_type
30
-
31
- self.answer = convert_by_answer_type
32
- check_range
29
+ self.answer = convert_by_answer_type if answer_type
33
30
  answer
34
31
  end
35
32
 
@@ -56,6 +56,7 @@ class HighLine
56
56
  @completion = @answer_type
57
57
 
58
58
  @echo = true
59
+ @default_hint_show = true
59
60
  @whitespace = :strip
60
61
  @case = nil
61
62
  @in = nil
@@ -136,10 +137,17 @@ class HighLine
136
137
  attr_accessor :case
137
138
  # Used to provide a default answer to this question.
138
139
  attr_accessor :default
140
+ # Set it to a truthy or falsy value to enable or disable showing the default
141
+ # value hint between vertical bars (pipes) when asking the question.
142
+ # Defaults to +true+
143
+ attr_accessor :default_hint_show
139
144
  #
140
145
  # If set to a Regexp, the answer must match (before type conversion).
141
146
  # Can also be set to a Proc which will be called with the provided
142
147
  # answer to validate with a +true+ or +false+ return.
148
+ # It's possible to use a custom validator class. It must respond to
149
+ # `#valid?`. The result of `#inspect` will be used in error messages.
150
+ # See README.md for details.
143
151
  #
144
152
  attr_accessor :validate
145
153
  # Used to control range checks for answer.
@@ -252,7 +260,7 @@ class HighLine
252
260
  # Same as {#answer_type}.
253
261
 
254
262
  def build_responses(message_source = answer_type)
255
- append_default if [::String, Symbol].include? default.class
263
+ append_default_to_template if default_hint_show
256
264
 
257
265
  new_hash = build_responses_new_hash(message_source)
258
266
  # Update our internal responses with the new hash
@@ -497,7 +505,8 @@ class HighLine
497
505
  def valid_answer?
498
506
  !validate ||
499
507
  (validate.is_a?(Regexp) && answer =~ validate) ||
500
- (validate.is_a?(Proc) && validate[answer])
508
+ (validate.is_a?(Proc) && validate[answer]) ||
509
+ (validate.respond_to?(:valid?) && validate.valid?(answer))
501
510
  end
502
511
 
503
512
  #
@@ -607,15 +616,20 @@ class HighLine
607
616
  # Trailing whitespace is preserved so the function of HighLine.say() is
608
617
  # not affected.
609
618
  #
610
- def append_default
619
+ def append_default_to_template
620
+ return unless default.respond_to? :to_s
621
+
622
+ default_str = default.to_s
623
+ return if default_str.empty?
624
+
611
625
  if template =~ /([\t ]+)\Z/
612
- template << "|#{default}|#{Regexp.last_match(1)}"
626
+ template << "|#{default_str}|#{Regexp.last_match(1)}"
613
627
  elsif template == ""
614
- template << "|#{default}| "
628
+ template << "|#{default_str}| "
615
629
  elsif template[-1, 1] == "\n"
616
- template[-2, 0] = " |#{default}|"
630
+ template[-2, 0] = " |#{default_str}|"
617
631
  else
618
- template << " |#{default}|"
632
+ template << " |#{default_str}|"
619
633
  end
620
634
  end
621
635
 
@@ -31,6 +31,7 @@ class HighLine
31
31
  raise NotValidQuestionError unless question.valid_answer?
32
32
 
33
33
  question.convert
34
+ question.check_range
34
35
 
35
36
  if question.confirm
36
37
  confirmation = @highline.send(:confirm, question)
File without changes
@@ -27,7 +27,7 @@ class HighLine
27
27
 
28
28
  # (see Terminal#get_character)
29
29
  def get_character
30
- input.getch # from ruby io/console
30
+ input.getch(intr: true) # from ruby io/console
31
31
  rescue Errno::ENOTTY
32
32
  input.getc
33
33
  end
@@ -20,7 +20,9 @@ class HighLine
20
20
  rescue LoadError
21
21
  end
22
22
 
23
- if /solaris/ =~ RUBY_PLATFORM &&
23
+ if !@output.tty?
24
+ [80, 24]
25
+ elsif /solaris/ =~ RUBY_PLATFORM &&
24
26
  `stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/
25
27
  [Regexp.last_match(2), Regexp.last_match(1)].map(&:to_i)
26
28
  elsif `stty size` =~ /^(\d+)\s(\d+)$/
@@ -32,13 +34,13 @@ class HighLine
32
34
 
33
35
  # (see Terminal#raw_no_echo_mode)
34
36
  def raw_no_echo_mode
35
- @state = `stty -g`
36
- system "stty raw -echo -icanon isig"
37
+ save_stty
38
+ system "stty raw -echo -icanon isig" if input.tty?
37
39
  end
38
40
 
39
41
  # (see Terminal#restore_mode)
40
42
  def restore_mode
41
- system "stty #{@state}"
43
+ restore_stty
42
44
  print "\r"
43
45
  end
44
46
 
@@ -176,7 +176,7 @@ class HighLine
176
176
  # Saves terminal state using shell stty command.
177
177
  def save_stty
178
178
  @stty_save = begin
179
- `stty -g`.chomp
179
+ `stty -g`.chomp if input.tty?
180
180
  rescue StandardError
181
181
  nil
182
182
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  class HighLine
4
4
  # The version of the installed library.
5
- VERSION = "2.0.3".freeze
5
+ VERSION = "3.0.0.pre.1".freeze
6
6
  end
data/lib/highline.rb CHANGED
@@ -538,6 +538,7 @@ class HighLine
538
538
  terminal.raw_no_echo_mode_exec do
539
539
  loop do
540
540
  character = terminal.get_character
541
+ raise Interrupt if character == "\u0003"
541
542
  break unless character
542
543
  break if ["\n", "\r"].include? character
543
544
 
@@ -545,6 +546,9 @@ class HighLine
545
546
  if character == "\b" || character == "\u007F"
546
547
  chopped = line.chop!
547
548
  output_erase_char if chopped && question.echo
549
+ elsif character == "\cU"
550
+ line.size.times { output_erase_char } if question.echo
551
+ line = ""
548
552
  elsif character == "\e"
549
553
  ignore_arrow_key
550
554
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: highline
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 3.0.0.pre.1
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: 2019-10-11 00:00:00.000000000 Z
11
+ date: 2023-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dry-types
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: |
56
70
  A high-level IO library that provides validation, type conversion, and more for
57
71
  command-line interfaces. HighLine also includes a complete menu system that can
@@ -66,10 +80,10 @@ extra_rdoc_files:
66
80
  - Changelog.md
67
81
  - LICENSE
68
82
  files:
83
+ - ".github/workflows/ci.yml"
69
84
  - ".gitignore"
70
85
  - ".rubocop.yml"
71
86
  - ".simplecov"
72
- - ".travis.yml"
73
87
  - AUTHORS
74
88
  - COPYING
75
89
  - Changelog.md
@@ -78,12 +92,12 @@ files:
78
92
  - README.md
79
93
  - Rakefile
80
94
  - TODO
81
- - appveyor.yml
82
95
  - doc/.cvsignore
83
96
  - examples/ansi_colors.rb
84
97
  - examples/asking_for_arrays.rb
85
98
  - examples/basic_usage.rb
86
99
  - examples/color_scheme.rb
100
+ - examples/custom_parser_custom_validator.rb
87
101
  - examples/get_character.rb
88
102
  - examples/limit.rb
89
103
  - examples/menus.rb
@@ -137,14 +151,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
151
  requirements:
138
152
  - - ">="
139
153
  - !ruby/object:Gem::Version
140
- version: 1.9.3
154
+ version: '3.0'
141
155
  required_rubygems_version: !ruby/object:Gem::Requirement
142
156
  requirements:
143
- - - ">="
157
+ - - ">"
144
158
  - !ruby/object:Gem::Version
145
- version: '0'
159
+ version: 1.3.1
146
160
  requirements: []
147
- rubygems_version: 3.0.6
161
+ rubygems_version: 3.4.6
148
162
  signing_key:
149
163
  specification_version: 4
150
164
  summary: HighLine is a high-level command-line IO library.
data/.travis.yml DELETED
@@ -1,43 +0,0 @@
1
- ---
2
- language: ruby
3
- dist: trusty
4
- cache: bundler
5
- script: "bundle exec rake test"
6
- rvm:
7
- - 2.0
8
- - 2.1
9
- - 2.2
10
- - 2.3
11
- - 2.4
12
- - jruby-19mode # JRuby in 1.9 mode
13
- - jruby-head
14
-
15
- notifications:
16
- email: false
17
- matrix:
18
- allow_failures:
19
- - rvm: 1.9
20
- - rvm: ruby-head
21
- - rvm: rbx-3.81
22
- - rvm: jruby-19mode # JRuby in 1.9 mode
23
- - rvm: jruby-head
24
- fast_finish: true
25
- include:
26
- - rvm: 1.9
27
- before_install:
28
- - "gem update --system -N"
29
- - "gem update bundler -N"
30
- - rvm: 2.5
31
- before_install:
32
- - gem install bundler
33
- - rvm: 2.6
34
- before_install:
35
- - gem install bundler
36
- - rvm: ruby-head
37
- before_install:
38
- - gem install bundler
39
- - rvm: rbx-3.81
40
- before_install:
41
- - gem install bundler
42
-
43
- bundler_args: --without code_quality
data/appveyor.yml DELETED
@@ -1,37 +0,0 @@
1
- version: 2.0.{build}-{branch}
2
-
3
- cache:
4
- - vendor/bundle
5
-
6
- environment:
7
- matrix:
8
- - RUBY_VERSION: "193"
9
- - RUBY_VERSION: "200"
10
- - RUBY_VERSION: "200-x64"
11
- - RUBY_VERSION: "21"
12
- - RUBY_VERSION: "21-x64"
13
- - RUBY_VERSION: "22"
14
- - RUBY_VERSION: "22-x64"
15
- - RUBY_VERSION: "23"
16
- - RUBY_VERSION: "23-x64"
17
- - RUBY_VERSION: "24"
18
- - RUBY_VERSION: "24-x64"
19
-
20
- matrix:
21
- allow_failures:
22
- - RUBY_VERSION: "193"
23
-
24
- install:
25
- - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
26
- - bundle config --local path vendor/bundle
27
- - bundle install --retry=3 --without code_quality
28
-
29
- build: off
30
-
31
- before_test:
32
- - ruby -v
33
- - gem -v
34
- - bundle -v
35
-
36
- test_script:
37
- - bundle exec rake