tty-reader 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +1 -0
- data/lib/tty/reader.rb +21 -21
- data/lib/tty/reader/console.rb +5 -5
- data/lib/tty/reader/history.rb +2 -2
- data/lib/tty/reader/key_event.rb +2 -2
- data/lib/tty/reader/keys.rb +15 -15
- data/lib/tty/reader/line.rb +7 -7
- data/lib/tty/reader/mode.rb +1 -1
- data/lib/tty/reader/version.rb +1 -1
- data/lib/tty/reader/win_api.rb +1 -1
- data/lib/tty/reader/win_console.rb +5 -5
- metadata +18 -54
- data/Rakefile +0 -10
- data/benchmarks/speed_read_char.rb +0 -34
- data/benchmarks/speed_read_line.rb +0 -34
- data/bin/console +0 -6
- data/bin/setup +0 -8
- data/examples/keypress.rb +0 -16
- data/examples/keypress_nonblock.rb +0 -17
- data/examples/line.rb +0 -7
- data/examples/multi_prompt.rb +0 -9
- data/examples/multiline.rb +0 -7
- data/examples/noecho.rb +0 -6
- data/examples/shell.rb +0 -12
- data/spec/spec_helper.rb +0 -51
- data/spec/unit/history_spec.rb +0 -177
- data/spec/unit/key_event_spec.rb +0 -102
- data/spec/unit/line_spec.rb +0 -158
- data/spec/unit/publish_keypress_event_spec.rb +0 -109
- data/spec/unit/read_keypress_spec.rb +0 -96
- data/spec/unit/read_line_spec.rb +0 -119
- data/spec/unit/read_multiline_spec.rb +0 -76
- data/spec/unit/subscribe_spec.rb +0 -74
- data/tasks/console.rake +0 -11
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
- data/tty-reader.gemspec +0 -40
@@ -1,76 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Reader, '#read_multiline' do
|
4
|
-
let(:input) { StringIO.new }
|
5
|
-
let(:output) { StringIO.new }
|
6
|
-
let(:env) { { "TTY_TEST" => true } }
|
7
|
-
|
8
|
-
subject(:reader) { described_class.new(input: input, output: output, env: env) }
|
9
|
-
|
10
|
-
it 'reads no lines' do
|
11
|
-
input << "\C-d"
|
12
|
-
input.rewind
|
13
|
-
answer = reader.read_multiline
|
14
|
-
expect(answer).to eq([])
|
15
|
-
end
|
16
|
-
|
17
|
-
it "reads a line and terminates on Ctrl+d" do
|
18
|
-
input << "Single line\C-d"
|
19
|
-
input.rewind
|
20
|
-
answer = reader.read_multiline
|
21
|
-
expect(answer).to eq(["Single line"])
|
22
|
-
end
|
23
|
-
|
24
|
-
it "reads a line and terminates on Ctrl+z" do
|
25
|
-
input << "Single line\C-z"
|
26
|
-
input.rewind
|
27
|
-
answer = reader.read_multiline
|
28
|
-
expect(answer).to eq(["Single line"])
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'reads few lines' do
|
32
|
-
input << "First line\nSecond line\nThird line\n\C-d"
|
33
|
-
input.rewind
|
34
|
-
answer = reader.read_multiline
|
35
|
-
expect(answer).to eq(["First line\n", "Second line\n", "Third line\n"])
|
36
|
-
end
|
37
|
-
|
38
|
-
it "skips empty lines" do
|
39
|
-
input << "\n\nFirst line\n\n\n\n\nSecond line\C-d"
|
40
|
-
input.rewind
|
41
|
-
answer = reader.read_multiline
|
42
|
-
expect(answer).to eq(["First line\n", "Second line"])
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'reads and yiels every line' do
|
46
|
-
input << "First line\nSecond line\nThird line\C-z"
|
47
|
-
input.rewind
|
48
|
-
lines = []
|
49
|
-
reader.read_multiline { |line| lines << line }
|
50
|
-
expect(lines).to eq(["First line\n", "Second line\n", "Third line"])
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'reads multibyte lines' do
|
54
|
-
input << "국경의 긴 터널을 빠져나오자\n설국이었다.\C-d"
|
55
|
-
input.rewind
|
56
|
-
lines = []
|
57
|
-
reader.read_multiline { |line| lines << line }
|
58
|
-
expect(lines).to eq(["국경의 긴 터널을 빠져나오자\n", '설국이었다.'])
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'reads lines with a prompt' do
|
62
|
-
input << "1\n2\n3\C-d"
|
63
|
-
input.rewind
|
64
|
-
reader.read_multiline(">> ")
|
65
|
-
expect(output.string).to eq([
|
66
|
-
">> ",
|
67
|
-
"\e[2K\e[1G>> 1",
|
68
|
-
"\e[2K\e[1G>> 1\n",
|
69
|
-
">> ",
|
70
|
-
"\e[2K\e[1G>> 2",
|
71
|
-
"\e[2K\e[1G>> 2\n",
|
72
|
-
">> ",
|
73
|
-
"\e[2K\e[1G>> 3",
|
74
|
-
].join)
|
75
|
-
end
|
76
|
-
end
|
data/spec/unit/subscribe_spec.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Reader, '#subscribe' do
|
4
|
-
let(:input) { StringIO.new }
|
5
|
-
let(:output) { StringIO.new }
|
6
|
-
let(:env) { { "TTY_TEST" => true } }
|
7
|
-
|
8
|
-
it "subscribes to receive events" do
|
9
|
-
stub_const("Context", Class.new do
|
10
|
-
def initialize(events)
|
11
|
-
@events = events
|
12
|
-
end
|
13
|
-
|
14
|
-
def keypress(event)
|
15
|
-
@events << [:keypress, event.value]
|
16
|
-
end
|
17
|
-
end)
|
18
|
-
|
19
|
-
reader = TTY::Reader.new(input: input, output: output, env: env)
|
20
|
-
events = []
|
21
|
-
context = Context.new(events)
|
22
|
-
reader.subscribe(context)
|
23
|
-
|
24
|
-
input << "aa\n"
|
25
|
-
input.rewind
|
26
|
-
answer = reader.read_line
|
27
|
-
|
28
|
-
expect(answer).to eq("aa\n")
|
29
|
-
expect(events).to eq([
|
30
|
-
[:keypress, "a"],
|
31
|
-
[:keypress, "a"],
|
32
|
-
[:keypress, "\n"]
|
33
|
-
])
|
34
|
-
|
35
|
-
events.clear
|
36
|
-
|
37
|
-
reader.unsubscribe(context)
|
38
|
-
|
39
|
-
input.rewind
|
40
|
-
answer = reader.read_line
|
41
|
-
expect(events).to eq([])
|
42
|
-
end
|
43
|
-
|
44
|
-
it "subscribes to listen to events only in a block" do
|
45
|
-
stub_const("Context", Class.new do
|
46
|
-
def initialize(events)
|
47
|
-
@events = events
|
48
|
-
end
|
49
|
-
|
50
|
-
def keypress(event)
|
51
|
-
@events << [:keypress, event.value]
|
52
|
-
end
|
53
|
-
end)
|
54
|
-
|
55
|
-
reader = TTY::Reader.new(input: input, output: output, env: env)
|
56
|
-
events = []
|
57
|
-
context = Context.new(events)
|
58
|
-
|
59
|
-
input << "aa\nbb\n"
|
60
|
-
input.rewind
|
61
|
-
|
62
|
-
reader.subscribe(context) do
|
63
|
-
reader.read_line
|
64
|
-
end
|
65
|
-
answer = reader.read_line
|
66
|
-
|
67
|
-
expect(answer).to eq("bb\n")
|
68
|
-
expect(events).to eq([
|
69
|
-
[:keypress, "a"],
|
70
|
-
[:keypress, "a"],
|
71
|
-
[:keypress, "\n"]
|
72
|
-
])
|
73
|
-
end
|
74
|
-
end
|
data/tasks/console.rake
DELETED
data/tasks/coverage.rake
DELETED
data/tasks/spec.rake
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
|
6
|
-
desc 'Run all specs'
|
7
|
-
RSpec::Core::RakeTask.new(:spec) do |task|
|
8
|
-
task.pattern = 'spec/{unit,integration}{,/*/**}/*_spec.rb'
|
9
|
-
end
|
10
|
-
|
11
|
-
namespace :spec do
|
12
|
-
desc 'Run unit specs'
|
13
|
-
RSpec::Core::RakeTask.new(:unit) do |task|
|
14
|
-
task.pattern = 'spec/unit{,/*/**}/*_spec.rb'
|
15
|
-
end
|
16
|
-
|
17
|
-
desc 'Run integration specs'
|
18
|
-
RSpec::Core::RakeTask.new(:integration) do |task|
|
19
|
-
task.pattern = 'spec/integration{,/*/**}/*_spec.rb'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
rescue LoadError
|
24
|
-
%w[spec spec:unit spec:integration].each do |name|
|
25
|
-
task name do
|
26
|
-
$stderr.puts "In order to run #{name}, do `gem install rspec`"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/tty-reader.gemspec
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
lib = File.expand_path("../lib", __FILE__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require "tty/reader/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "tty-reader"
|
7
|
-
spec.version = TTY::Reader::VERSION
|
8
|
-
spec.authors = ["Piotr Murach"]
|
9
|
-
spec.email = ["me@piotrmurach.com"]
|
10
|
-
spec.summary = %q{A set of methods for processing keyboard input in character, line and multiline modes.}
|
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
|
-
spec.homepage = "https://piotrmurach.github.io/tty"
|
13
|
-
spec.license = "MIT"
|
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
|
24
|
-
spec.files = Dir['{lib,spec,examples,benchmarks}/**/*.rb']
|
25
|
-
spec.files += Dir['{bin,tasks}/*', 'tty-reader.gemspec']
|
26
|
-
spec.files += Dir['README.md', 'CHANGELOG.md', 'LICENSE.txt', 'Rakefile']
|
27
|
-
spec.bindir = "exe"
|
28
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
-
spec.require_paths = ["lib"]
|
30
|
-
|
31
|
-
spec.required_ruby_version = '>= 2.0.0'
|
32
|
-
|
33
|
-
spec.add_dependency "wisper", "~> 2.0.0"
|
34
|
-
spec.add_dependency "tty-screen", "~> 0.7"
|
35
|
-
spec.add_dependency "tty-cursor", "~> 0.7"
|
36
|
-
|
37
|
-
spec.add_development_dependency "bundler", ">= 1.5.0"
|
38
|
-
spec.add_development_dependency "rake"
|
39
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
40
|
-
end
|