rubytext 0.0.96 → 0.0.97
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 +4 -4
- data/lib/output.rb +39 -6
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63fd4f07417878ad5d57fa7e320c0994c2eb66ca041496f3343e5653d3d917d2
|
4
|
+
data.tar.gz: f0ab6a636a4cbade143d65601cae90f1eae786f413e86afb415c06cd59b4197f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 403c07f49e761a3b5cbb92121f8ba3342e3b03d3fd6c45f2c977639fa0feb96080611c330c441ebcd80b9af159a42e7657e398bf217157c90d370b7d7620f654
|
7
|
+
data.tar.gz: 8fb97b2927abe08075348d1a49651b37c0eca436539a89f3d278099a0edea84d970018dbcc4b8213a730e48c8b98cda40d2930a62e37f631c621f8de0d2fd482
|
data/lib/output.rb
CHANGED
@@ -139,16 +139,19 @@ class RubyText::Window
|
|
139
139
|
end
|
140
140
|
|
141
141
|
class GetString
|
142
|
-
def initialize(win = STDSCR, str = "", i = 0)
|
142
|
+
def initialize(win = STDSCR, str = "", i = 0, history: nil)
|
143
143
|
@win = win
|
144
144
|
@r0, @c0 = @win.rc
|
145
145
|
@str, @i = str, i
|
146
|
-
@
|
147
|
-
@
|
146
|
+
@history = history
|
147
|
+
@h = @history.length - 1
|
148
|
+
@maxlen = 0
|
148
149
|
end
|
149
150
|
|
150
151
|
def enter
|
151
152
|
@win.crlf
|
153
|
+
@history << @str
|
154
|
+
@h = @history.length - 1
|
152
155
|
end
|
153
156
|
|
154
157
|
def left_arrow
|
@@ -172,12 +175,35 @@ class RubyText::Window
|
|
172
175
|
@str[@i] = ""
|
173
176
|
@win.left
|
174
177
|
@win.rcprint @r0, @c0, @str + " "
|
175
|
-
|
176
178
|
# @r, @c = @win.rc
|
177
179
|
# @win[@r0, @c0+@str.length+1] = ' '
|
178
180
|
# @win.go @r, @c
|
179
181
|
end
|
180
182
|
|
183
|
+
def history_prev
|
184
|
+
return if @history.empty?
|
185
|
+
@win.go @r0, @c0
|
186
|
+
@maxlen = @history.map(&:length).max
|
187
|
+
@win.print(" "*@maxlen)
|
188
|
+
@h = (@h - 1) % @history.length
|
189
|
+
@str = @history[@h]
|
190
|
+
@i = @str.length
|
191
|
+
@win.go @r0, @c0
|
192
|
+
@win.print @str
|
193
|
+
end
|
194
|
+
|
195
|
+
def history_next
|
196
|
+
return if @history.empty?
|
197
|
+
@h = (@h + 1) % @history.length
|
198
|
+
@win.go @r0, @c0
|
199
|
+
@maxlen = @history.map(&:length).max
|
200
|
+
@win.print(" "*@maxlen)
|
201
|
+
@str = @history[@h]
|
202
|
+
@i = @str.length
|
203
|
+
@win.go @r0, @c0
|
204
|
+
@win.print @str
|
205
|
+
end
|
206
|
+
|
181
207
|
def add(ch)
|
182
208
|
@str.insert(@i, ch)
|
183
209
|
@win.right
|
@@ -190,9 +216,10 @@ class RubyText::Window
|
|
190
216
|
end
|
191
217
|
end
|
192
218
|
|
193
|
-
def gets # still needs improvement
|
219
|
+
def gets(history: nil) # still needs improvement
|
194
220
|
# echo assumed to be OFF, keypad ON
|
195
|
-
|
221
|
+
@history = history
|
222
|
+
gs = GetString.new(self, history: history)
|
196
223
|
loop do
|
197
224
|
ch = self.getch
|
198
225
|
case ch
|
@@ -205,6 +232,12 @@ class RubyText::Window
|
|
205
232
|
gs.left_arrow
|
206
233
|
when 261 # right-arrow
|
207
234
|
gs.right_arrow
|
235
|
+
when 259 # up
|
236
|
+
next if @history.nil? # move this?
|
237
|
+
gs.history_prev
|
238
|
+
when 258 # down
|
239
|
+
next if @history.nil? # move this?
|
240
|
+
gs.history_next
|
208
241
|
else
|
209
242
|
gs.add(ch)
|
210
243
|
end
|
data/lib/version.rb
CHANGED