readline-ng 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/readline-ng.rb +38 -6
- data/test/newline.rb +11 -0
- data/test/test_helper.rb +0 -0
- metadata +4 -2
data/lib/readline-ng.rb
CHANGED
@@ -2,7 +2,7 @@ module ReadlineNG
|
|
2
2
|
|
3
3
|
VERSION_MAJOR = 0
|
4
4
|
VERSION_MINOR = 0
|
5
|
-
VERSION_PATCH =
|
5
|
+
VERSION_PATCH = 4
|
6
6
|
VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}"
|
7
7
|
|
8
8
|
CONTROL_BS = "\x08"
|
@@ -12,6 +12,8 @@ module ReadlineNG
|
|
12
12
|
|
13
13
|
KB_BS = "\x7F"
|
14
14
|
KB_CR = "\x0d"
|
15
|
+
KB_LEFT = "LEFT" # XXX PLACEHOLDERS
|
16
|
+
KB_RIGHT = "RIGHT"
|
15
17
|
|
16
18
|
BLANK = " "
|
17
19
|
|
@@ -24,15 +26,17 @@ module ReadlineNG
|
|
24
26
|
# make a whole lot of sense, although potentially giving out rope is not a
|
25
27
|
# terrible idea here
|
26
28
|
|
27
|
-
attr_accessor :lines, :visible
|
29
|
+
attr_accessor :lines, :visible, :polling_resolution
|
28
30
|
|
29
31
|
def filter
|
30
32
|
end
|
31
33
|
|
32
|
-
def initialize(visible=true)
|
34
|
+
def initialize(visible=true, opts = {})
|
33
35
|
@buf = ""
|
36
|
+
@ind = 0
|
34
37
|
@visible = visible
|
35
38
|
@lines = []
|
39
|
+
@polling_resolution = opts[:polling_resolution] || 20
|
36
40
|
if @@initialized
|
37
41
|
STDERR.puts "A ReadlineNG reader is already instanciated, expect weirdness"
|
38
42
|
else
|
@@ -46,10 +50,17 @@ module ReadlineNG
|
|
46
50
|
end
|
47
51
|
end
|
48
52
|
|
53
|
+
def sleep(n)
|
54
|
+
(n * polling_resolution).times do
|
55
|
+
tick
|
56
|
+
sleep 1.0/polling_resolution
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
49
60
|
def puts_above(string)
|
50
61
|
if visible
|
51
62
|
backspace(@buf.length)
|
52
|
-
_print string
|
63
|
+
_print string.gsub("\n", "\n\r")
|
53
64
|
_puts CONTROL_CR
|
54
65
|
_print @buf
|
55
66
|
end
|
@@ -92,9 +103,25 @@ module ReadlineNG
|
|
92
103
|
when KB_BS
|
93
104
|
@buf.chop!
|
94
105
|
backspace
|
106
|
+
when KB_LEFT
|
107
|
+
unless @ind == 0
|
108
|
+
_print CONTROL_BS
|
109
|
+
@ind -= 1
|
110
|
+
end
|
111
|
+
when KB_RIGHT
|
112
|
+
unless @ind == @buf.length
|
113
|
+
_print @buf[@ind]
|
114
|
+
@ind += 1
|
115
|
+
end
|
95
116
|
else
|
96
|
-
@buf
|
97
|
-
|
117
|
+
@buf.insert(@ind, c)
|
118
|
+
@ind += 1
|
119
|
+
if @ind == @buf.length
|
120
|
+
_print c
|
121
|
+
else
|
122
|
+
# TODO Only backspace to the new character
|
123
|
+
redraw
|
124
|
+
end
|
98
125
|
end
|
99
126
|
end
|
100
127
|
|
@@ -102,6 +129,11 @@ module ReadlineNG
|
|
102
129
|
print CONTROL_BS*n,BLANK*n,CONTROL_BS*n
|
103
130
|
end
|
104
131
|
|
132
|
+
def redraw
|
133
|
+
backspace(@buf.length)
|
134
|
+
_print(@buf)
|
135
|
+
end
|
136
|
+
|
105
137
|
def _print(c)
|
106
138
|
print c if visible
|
107
139
|
end
|
data/test/newline.rb
ADDED
data/test/test_helper.rb
ADDED
File without changes
|
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.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-19 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Essentially, readline++
|
15
15
|
email:
|
@@ -22,6 +22,8 @@ files:
|
|
22
22
|
- README
|
23
23
|
- lib/readline-ng.rb
|
24
24
|
- readline-ng.gemspec
|
25
|
+
- test/newline.rb
|
26
|
+
- test/test_helper.rb
|
25
27
|
homepage: http://github.com/richoH/readline-ng
|
26
28
|
licenses: []
|
27
29
|
post_install_message:
|