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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/output.rb +39 -6
  3. data/lib/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd667701a552225befff826ebf3f1c668bdb1f9d295d7fe0f28c6f2fa022f3c8
4
- data.tar.gz: 4d4c89f86402cbc38ddbe11eca41dca7852c423dbf744c7adaefde184f6d7c74
3
+ metadata.gz: 63fd4f07417878ad5d57fa7e320c0994c2eb66ca041496f3343e5653d3d917d2
4
+ data.tar.gz: f0ab6a636a4cbade143d65601cae90f1eae786f413e86afb415c06cd59b4197f
5
5
  SHA512:
6
- metadata.gz: 327c09610e14bd6bbdc237f29a8dd4b10324638e7bccf32117f7597363fac9f6becd49c9c186bbc8f106c2294c73bd10c2c5a25792a679daf8a178b09fdcf0a3
7
- data.tar.gz: a452fa04fadb0664216c9cd6c41abff4d04d2096646dc05ff0cd23e7f6aaeb05722762f14e83533944628b22244e347347f68db4f76fa0c8d3af2216da4930cc
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
- @len = @str.length
147
- @max = @len - 1
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
- gs = GetString.new(self)
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
@@ -1,6 +1,6 @@
1
1
 
2
2
  module RubyText
3
- VERSION = "0.0.96"
3
+ VERSION = "0.0.97"
4
4
 
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubytext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.96
4
+ version: 0.0.97
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton