readline-ng 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -1
- data/lib/readline-ng/chunked_string.rb +24 -0
- data/lib/readline-ng.rb +12 -5
- data/readline.rb +11 -0
- data/spec/readline-ng_spec.rb +11 -4
- metadata +3 -1
data/.travis.yml
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
module ReadlineNG
|
2
|
+
class ChunkedString
|
3
|
+
|
4
|
+
def initialize(str="")
|
5
|
+
@buf = str
|
6
|
+
end
|
7
|
+
|
8
|
+
def <<(str)
|
9
|
+
@buf += str
|
10
|
+
end
|
11
|
+
|
12
|
+
def each_chunk
|
13
|
+
until @buf.empty?
|
14
|
+
t = @buf.slice!(0)
|
15
|
+
if t == "\e"
|
16
|
+
t += @buf.slice!(0..1)
|
17
|
+
end
|
18
|
+
|
19
|
+
yield t
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/readline-ng.rb
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
module ReadlineNG
|
2
2
|
|
3
|
+
%w[chunked_string].each do |f|
|
4
|
+
require "readline-ng/#{f}"
|
5
|
+
end
|
6
|
+
|
7
|
+
n = ::ReadlineNG::ChunkedString.new
|
8
|
+
|
3
9
|
VERSION_MAJOR = 0
|
4
10
|
VERSION_MINOR = 0
|
5
|
-
VERSION_PATCH =
|
11
|
+
VERSION_PATCH = 8
|
6
12
|
VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}"
|
7
13
|
|
8
14
|
CONTROL_BS = "\x08"
|
@@ -13,8 +19,8 @@ module ReadlineNG
|
|
13
19
|
KB_BS = "\x7F"
|
14
20
|
KB_CR = "\x0d"
|
15
21
|
|
16
|
-
KB_LEFT = "\
|
17
|
-
KB_RIGHT = "\
|
22
|
+
KB_LEFT = "\e[C"
|
23
|
+
KB_RIGHT = "\e[D"
|
18
24
|
|
19
25
|
BLANK = " "
|
20
26
|
|
@@ -34,6 +40,7 @@ module ReadlineNG
|
|
34
40
|
|
35
41
|
def initialize(visible=true, opts = {})
|
36
42
|
@buf = ""
|
43
|
+
@chunked = ChunkedString.new
|
37
44
|
@index = 0
|
38
45
|
@visible = visible
|
39
46
|
@lines = []
|
@@ -67,8 +74,8 @@ module ReadlineNG
|
|
67
74
|
end
|
68
75
|
|
69
76
|
def tick
|
70
|
-
|
71
|
-
|
77
|
+
@chunked << STDIN.read_nonblock(128)
|
78
|
+
@chunked.each_chunk { |c| process(c) }
|
72
79
|
filter # Expect a 3rd party dev to override this
|
73
80
|
rescue Errno::EAGAIN
|
74
81
|
nil
|
data/readline.rb
ADDED
data/spec/readline-ng_spec.rb
CHANGED
@@ -59,24 +59,31 @@ describe ReadlineNG do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should respect the left key" do
|
62
|
-
STDIN.stub(:read_nonblock).and_return("asdf",
|
62
|
+
STDIN.stub(:read_nonblock).and_return("asdf", ReadlineNG::KB_LEFT*2, "__\r")
|
63
63
|
@reader.get_line.should == "as__df"
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should not allow the user to left before an empty buffer" do
|
67
|
-
STDIN.stub(:read_nonblock).and_return(
|
67
|
+
STDIN.stub(:read_nonblock).and_return(ReadlineNG::KB_LEFT*2, "__", ReadlineNG::KB_LEFT*2, "\r")
|
68
68
|
@reader.get_line.should == "__"
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should respect the right key" do
|
72
|
-
STDIN.stub(:read_nonblock).and_return("asdf",
|
72
|
+
STDIN.stub(:read_nonblock).and_return("asdf", ReadlineNG::KB_LEFT*2, "__", ReadlineNG::KB_RIGHT, "++\r" )
|
73
73
|
@reader.get_line.should == "as_++_df"
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should not allow the user to right after an empty buffer" do
|
77
|
-
STDIN.stub(:read_nonblock).and_return(
|
77
|
+
STDIN.stub(:read_nonblock).and_return(ReadlineNG::KB_RIGHT*2, "__", ReadlineNG::KB_RIGHT*2, "\r")
|
78
78
|
@reader.get_line.should == "__"
|
79
79
|
end
|
80
80
|
|
81
|
+
it "should recieve and process single quotes" do
|
82
|
+
STDIN.stub(:read_nonblock).and_return("'''", "\r")
|
83
|
+
@reader.get_line.should == "'''"
|
84
|
+
end
|
85
|
+
|
86
|
+
# TODO it "should erase the displayed line when input is terminated" do
|
87
|
+
|
81
88
|
end
|
82
89
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: readline-ng
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -73,7 +73,9 @@ files:
|
|
73
73
|
- README.md
|
74
74
|
- Rakefile
|
75
75
|
- lib/readline-ng.rb
|
76
|
+
- lib/readline-ng/chunked_string.rb
|
76
77
|
- readline-ng.gemspec
|
78
|
+
- readline.rb
|
77
79
|
- spec/readline-ng_spec.rb
|
78
80
|
homepage: http://github.com/richoH/readline-ng
|
79
81
|
licenses: []
|