rubytext 0.0.95 → 0.0.96
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/README.md +3 -1
- data/lib/output.rb +85 -8
- data/lib/version.rb +1 -1
- data/lib/widgets.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fd667701a552225befff826ebf3f1c668bdb1f9d295d7fe0f28c6f2fa022f3c8
|
|
4
|
+
data.tar.gz: 4d4c89f86402cbc38ddbe11eca41dca7852c423dbf744c7adaefde184f6d7c74
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 327c09610e14bd6bbdc237f29a8dd4b10324638e7bccf32117f7597363fac9f6becd49c9c186bbc8f106c2294c73bd10c2c5a25792a679daf8a178b09fdcf0a3
|
|
7
|
+
data.tar.gz: a452fa04fadb0664216c9cd6c41abff4d04d2096646dc05ff0cd23e7f6aaeb05722762f14e83533944628b22244e347347f68db4f76fa0c8d3af2216da4930cc
|
data/README.md
CHANGED
|
@@ -105,7 +105,7 @@ win.output do
|
|
|
105
105
|
end
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
-
<img src=readme-images/
|
|
108
|
+
<img src=readme-images/window_full.png>
|
|
109
109
|
|
|
110
110
|
You can use `print` and `p` as well as `puts`.
|
|
111
111
|
|
|
@@ -126,6 +126,8 @@ win.output do
|
|
|
126
126
|
end
|
|
127
127
|
```
|
|
128
128
|
|
|
129
|
+
<img src=readme-images/puts_print.png>
|
|
130
|
+
|
|
129
131
|
You can still use `puts` (etc.) with files, but watch for `STDOUT` and `STDERR`.
|
|
130
132
|
|
|
131
133
|
```ruby
|
data/lib/output.rb
CHANGED
|
@@ -138,7 +138,81 @@ class RubyText::Window
|
|
|
138
138
|
@cwin.refresh
|
|
139
139
|
end
|
|
140
140
|
|
|
141
|
+
class GetString
|
|
142
|
+
def initialize(win = STDSCR, str = "", i = 0)
|
|
143
|
+
@win = win
|
|
144
|
+
@r0, @c0 = @win.rc
|
|
145
|
+
@str, @i = str, i
|
|
146
|
+
@len = @str.length
|
|
147
|
+
@max = @len - 1
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def enter
|
|
151
|
+
@win.crlf
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def left_arrow
|
|
155
|
+
if @i > 0
|
|
156
|
+
@i -= 1
|
|
157
|
+
@win.left
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def right_arrow
|
|
162
|
+
if @i < @str.length
|
|
163
|
+
@i += 1
|
|
164
|
+
@win.right
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def backspace
|
|
169
|
+
# remember: may be in middle of string
|
|
170
|
+
return if @i == 0
|
|
171
|
+
@i -= 1
|
|
172
|
+
@str[@i] = ""
|
|
173
|
+
@win.left
|
|
174
|
+
@win.rcprint @r0, @c0, @str + " "
|
|
175
|
+
|
|
176
|
+
# @r, @c = @win.rc
|
|
177
|
+
# @win[@r0, @c0+@str.length+1] = ' '
|
|
178
|
+
# @win.go @r, @c
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def add(ch)
|
|
182
|
+
@str.insert(@i, ch)
|
|
183
|
+
@win.right
|
|
184
|
+
@win.go(@r0, @c0) { @win.print @str }
|
|
185
|
+
@i += 1
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def value
|
|
189
|
+
@str
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
141
193
|
def gets # still needs improvement
|
|
194
|
+
# echo assumed to be OFF, keypad ON
|
|
195
|
+
gs = GetString.new(self)
|
|
196
|
+
loop do
|
|
197
|
+
ch = self.getch
|
|
198
|
+
case ch
|
|
199
|
+
when 10
|
|
200
|
+
gs.enter
|
|
201
|
+
break
|
|
202
|
+
when 8, 127, 63 # backspace, del, ^H (huh?)
|
|
203
|
+
gs.backspace
|
|
204
|
+
when 260 # left-arrow
|
|
205
|
+
gs.left_arrow
|
|
206
|
+
when 261 # right-arrow
|
|
207
|
+
gs.right_arrow
|
|
208
|
+
else
|
|
209
|
+
gs.add(ch)
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
gs.value
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def old_gets # still needs improvement
|
|
142
216
|
# echo assumed to be OFF, keypad ON
|
|
143
217
|
str = ""
|
|
144
218
|
i = 0
|
|
@@ -146,23 +220,26 @@ class RubyText::Window
|
|
|
146
220
|
loop do
|
|
147
221
|
ch = self.getch
|
|
148
222
|
case ch
|
|
149
|
-
when 10
|
|
150
|
-
self.crlf
|
|
151
|
-
break
|
|
223
|
+
when 10; self.crlf; break # Enter
|
|
152
224
|
when 8, 127, 63 # backspace, del, ^H (huh?)
|
|
153
225
|
if i >= 1
|
|
154
226
|
str = str[0..-2]
|
|
155
227
|
i -= 1
|
|
156
228
|
self.left
|
|
157
229
|
self[*self.rc] = ' '
|
|
158
|
-
self.
|
|
230
|
+
r, c = self.rc
|
|
231
|
+
rcprint r, c, str[i+1..-1] + " "
|
|
159
232
|
end
|
|
160
233
|
when 260 # left-arrow
|
|
161
|
-
i
|
|
162
|
-
|
|
234
|
+
if i > 0
|
|
235
|
+
i -= 1
|
|
236
|
+
self.left
|
|
237
|
+
end
|
|
163
238
|
when 261 # right-arrow
|
|
164
|
-
i
|
|
165
|
-
|
|
239
|
+
if i < str.length
|
|
240
|
+
i += 1
|
|
241
|
+
self.right
|
|
242
|
+
end
|
|
166
243
|
else
|
|
167
244
|
str.insert(i, ch)
|
|
168
245
|
self.right
|
data/lib/version.rb
CHANGED
data/lib/widgets.rb
CHANGED
|
@@ -12,4 +12,14 @@ module RubyText
|
|
|
12
12
|
sleep delay
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
|
+
|
|
16
|
+
def self.spinner(win: STDSCR, &block)
|
|
17
|
+
chars = "-\\|/"
|
|
18
|
+
RubyText.hide_cursor
|
|
19
|
+
thread = Thread.new { i=0; loop { i = (i+1) % 4; win.print chars[i]; win.left; sleep 0.1 } }
|
|
20
|
+
block.call
|
|
21
|
+
win.puts
|
|
22
|
+
Thread.kill(thread)
|
|
23
|
+
RubyText.show_cursor
|
|
24
|
+
end
|
|
15
25
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubytext
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.96
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hal Fulton
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-12-
|
|
11
|
+
date: 2018-12-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: curses
|