tty-reader 0.6.0 → 0.7.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6193cf64fd770d652ff66d89ff395c28f52181521242ce432b3b651aa7b13d63
4
- data.tar.gz: 7fa878638a8851265dfed9f8970f03fd360f975007c8ad0c865bf2bb304c64a1
3
+ metadata.gz: 5cafac5b8e629299d317c79b4bc5ff9b5f88873dbbcb966b152a773509c118a8
4
+ data.tar.gz: ebc42b1a9eb21652b74edf393f9555be025d9cfb3e84c9be14b667dc3012b59e
5
5
  SHA512:
6
- metadata.gz: 91136b6cecab81d4705560af21775ae5e4140e860c1d2413e8c01b545652623f2d17c2a146494fcf790d0c3e996a4b38cab1a80741f1900d3422eb4018e861ac
7
- data.tar.gz: bf159f08943f118a48c133171410bd5e9f8f6e8da0f83be54745e653648f9d3de7863025667a4a08da19d8ba27ab1c1c6cab0add921777de23a7a0b069c2ac15
6
+ metadata.gz: b7d0b5652ed3e3b7f6080c7a31c066457d00d20aefe780f2f581e221f06760a19bfe654c5d5b7edaa6317d2fed9f934a3a58adc36296e73b5529d74cf1147c92
7
+ data.tar.gz: b713a61cf2c195d11ae63a4ccc4b0901347286913e41fa014d1bf641bc65e7ff958ba1e334354e7d8622848caf2229363a799402a240946042aec217e4ef1577
@@ -1,5 +1,11 @@
1
1
  # Change log
2
2
 
3
+ ## [v0.7.0] - 2019-11-24
4
+
5
+ ### Added
6
+ * Add support for a multi-line prompt by Katelyn Schiesser(@slowbro)
7
+ * Add metadata to gemspec
8
+
3
9
  ## [v0.6.0] - 2019-05-27
4
10
 
5
11
  ### Added
@@ -60,6 +66,7 @@
60
66
 
61
67
  * Initial implementation and release
62
68
 
69
+ [v0.7.0]: https://github.com/piotrmurach/tty-reader/compare/v0.6.0...v0.7.0
63
70
  [v0.6.0]: https://github.com/piotrmurach/tty-reader/compare/v0.5.0...v0.6.0
64
71
  [v0.5.0]: https://github.com/piotrmurach/tty-reader/compare/v0.4.0...v0.5.0
65
72
  [v0.4.0]: https://github.com/piotrmurach/tty-reader/compare/v0.3.0...v0.4.0
@@ -0,0 +1,9 @@
1
+ require_relative "../lib/tty-reader"
2
+
3
+ reader = TTY::Reader.new
4
+
5
+ reader.on(:keyctrl_x, :keyescape) { puts "Exiting..."; exit }
6
+
7
+ loop do
8
+ reader.read_line("one\ntwo\nthree")
9
+ end
@@ -236,7 +236,10 @@ module TTY
236
236
  #
237
237
  # @api public
238
238
  def prompt_size
239
- self.class.sanitize(@prompt).size
239
+ p = self.class.sanitize(@prompt).split(/\r?\n/)
240
+ # return the length of each line + screen width for every line past the first
241
+ # which accounts for multi-line prompts
242
+ p.join.length + ((p.length - 1) * TTY::Screen.width )
240
243
  end
241
244
 
242
245
  # Text size
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TTY
4
4
  class Reader
5
- VERSION = '0.6.0'
5
+ VERSION = '0.7.0'
6
6
  end # Reader
7
7
  end # TTY
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if ENV['COVERAGE'] || ENV['TRAVIS']
2
4
  require 'simplecov'
3
5
  require 'coveralls'
4
6
 
5
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
6
8
  SimpleCov::Formatter::HTMLFormatter,
7
9
  Coveralls::SimpleCov::Formatter
8
- ]
10
+ ])
9
11
 
10
12
  SimpleCov.start do
11
13
  command_name 'spec'
@@ -13,7 +13,7 @@ RSpec.describe TTY::Reader::History do
13
13
  end
14
14
 
15
15
  it "allows to cycle through non-empty buffer" do
16
- history = described_class.new(3, {cycle: true})
16
+ history = described_class.new(3, cycle: true)
17
17
  history << "line"
18
18
  expect(history.next?).to eq(true)
19
19
  expect(history.previous?).to eq(true)
@@ -93,4 +93,27 @@ RSpec.describe TTY::Reader, '#read_line' do
93
93
 
94
94
  expect(answer).to eq("한글")
95
95
  end
96
+
97
+ it "supports multiline prompts" do
98
+ allow(TTY::Screen).to receive(:width).and_return(50)
99
+ prompt = "one\ntwo\nthree"
100
+ input << "aa\n"
101
+ input.rewind
102
+
103
+ answer = reader.read_line(prompt)
104
+
105
+ expect(answer).to eq("aa\n")
106
+ expect(output.string).to eq([
107
+ prompt,
108
+ "\e[2K\e[1G\e[1A" * 2,
109
+ "\e[2K\e[1G",
110
+ prompt + "a",
111
+ "\e[2K\e[1G\e[1A" * 2,
112
+ "\e[2K\e[1G",
113
+ prompt + "aa",
114
+ "\e[2K\e[1G\e[1A" * 2,
115
+ "\e[2K\e[1G",
116
+ prompt + "aa\n"
117
+ ].join)
118
+ end
96
119
  end
@@ -11,7 +11,16 @@ Gem::Specification.new do |spec|
11
11
  spec.description = %q{A set of methods for processing keyboard input in character, line and multiline modes. It maintains history of entered input with an ability to recall and re-edit those inputs. It lets you register to listen for keystroke events and trigger custom key events yourself.}
12
12
  spec.homepage = "https://piotrmurach.github.io/tty"
13
13
  spec.license = "MIT"
14
-
14
+ if spec.respond_to?(:metadata=)
15
+ spec.metadata = {
16
+ "allowed_push_host" => "https://rubygems.org",
17
+ "bug_tracker_uri" => "https://github.com/piotrmurach/tty-reader/issues",
18
+ "changelog_uri" => "https://github.com/piotrmurach/tty-reader/blob/master/CHANGELOG.md",
19
+ "documentation_uri" => "https://www.rubydoc.info/gems/tty-reader",
20
+ "homepage_uri" => spec.homepage,
21
+ "source_code_uri" => "https://github.com/piotrmurach/tty-reader"
22
+ }
23
+ end
15
24
  spec.files = Dir['{lib,spec,examples,benchmarks}/**/*.rb']
16
25
  spec.files += Dir['{bin,tasks}/*', 'tty-reader.gemspec']
17
26
  spec.files += Dir['README.md', 'CHANGELOG.md', 'LICENSE.txt', 'Rakefile']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty-reader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-27 00:00:00.000000000 Z
11
+ date: 2019-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: wisper
@@ -115,6 +115,7 @@ files:
115
115
  - examples/keypress.rb
116
116
  - examples/keypress_nonblock.rb
117
117
  - examples/line.rb
118
+ - examples/multi_prompt.rb
118
119
  - examples/multiline.rb
119
120
  - examples/noecho.rb
120
121
  - examples/shell.rb
@@ -145,7 +146,13 @@ files:
145
146
  homepage: https://piotrmurach.github.io/tty
146
147
  licenses:
147
148
  - MIT
148
- metadata: {}
149
+ metadata:
150
+ allowed_push_host: https://rubygems.org
151
+ bug_tracker_uri: https://github.com/piotrmurach/tty-reader/issues
152
+ changelog_uri: https://github.com/piotrmurach/tty-reader/blob/master/CHANGELOG.md
153
+ documentation_uri: https://www.rubydoc.info/gems/tty-reader
154
+ homepage_uri: https://piotrmurach.github.io/tty
155
+ source_code_uri: https://github.com/piotrmurach/tty-reader
149
156
  post_install_message:
150
157
  rdoc_options: []
151
158
  require_paths:
@@ -161,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
168
  - !ruby/object:Gem::Version
162
169
  version: '0'
163
170
  requirements: []
164
- rubygems_version: 3.0.3
171
+ rubygems_version: 3.0.6
165
172
  signing_key:
166
173
  specification_version: 4
167
174
  summary: A set of methods for processing keyboard input in character, line and multiline