console_cmdr 0.3.0 → 0.4.0
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
- checksums.yaml.gz.sig +0 -0
- data/lib/console_cmdr.rb +188 -31
- data.tar.gz.sig +0 -0
- metadata +22 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed5bbea62199c0d50966eeac59187f5ef1bb0ddc
|
4
|
+
data.tar.gz: c8e123361250caec9d0e45373557195a83aa95f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e57e3ee2f0c27e261e14d1358bcdfd3ef899d6e12889df2f437bd202318cf7cf4b214ffc1418378aaed6959d65dd472e6ea4fcc65bbb9aed75007870cdc52817
|
7
|
+
data.tar.gz: 2d492f6244b21e09951bd99e27f4e653b4170cbfd77abc51e80b366367a28cb7f56176bc7a6fd4c6f5595f9d0868bda922f2e04de10cce64cf7a4a1795e5b297
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/console_cmdr.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
|
5
5
|
require 'cmdr'
|
6
6
|
require 'pxindex'
|
7
|
+
require 'colored'
|
7
8
|
require 'terminfo'
|
8
9
|
require 'io/console'
|
9
10
|
|
@@ -17,7 +18,17 @@ class ConsoleCmdr < Cmdr
|
|
17
18
|
@pxi = pxindex ? PxIndex.new(pxindex) : nil
|
18
19
|
|
19
20
|
@keys = []
|
21
|
+
@item_selected = ''
|
22
|
+
@input_selection = []
|
23
|
+
@running = true
|
20
24
|
end
|
25
|
+
|
26
|
+
def clear()
|
27
|
+
@linebuffer = ''
|
28
|
+
print "\e[H\e[2J"
|
29
|
+
''
|
30
|
+
#cli_banner()
|
31
|
+
end
|
21
32
|
|
22
33
|
def cli_banner()
|
23
34
|
puts "welcome, this code is powered by the cmdr gem\n\n"
|
@@ -26,6 +37,7 @@ class ConsoleCmdr < Cmdr
|
|
26
37
|
|
27
38
|
def reload()
|
28
39
|
@pxi = @pxindex_filepath ? PxIndex.new(@pxindex_filepath) : nil
|
40
|
+
'reloaded'
|
29
41
|
end
|
30
42
|
|
31
43
|
def start(&blk)
|
@@ -34,17 +46,19 @@ class ConsoleCmdr < Cmdr
|
|
34
46
|
|
35
47
|
seq = []
|
36
48
|
|
37
|
-
|
49
|
+
while @running do
|
38
50
|
|
39
51
|
c = $stdin.getch
|
40
|
-
|
52
|
+
#puts 'c:' + c.inspect
|
41
53
|
#puts c.ord
|
42
54
|
|
43
55
|
# [27, 91, 65] = up_arrow
|
44
56
|
# [27, 91, 66] = down_arrow
|
45
57
|
# [27, 91, 67] = right_arrow
|
46
58
|
# [27, 91, 68] = left_arrow
|
59
|
+
# [27, 91, 49, 53] = ctrl+right_arrow
|
47
60
|
# 13 = enter
|
61
|
+
#puts 'seq: ' + seq.inspect
|
48
62
|
|
49
63
|
if c.ord == 27 then
|
50
64
|
seq << 27
|
@@ -55,34 +69,62 @@ class ConsoleCmdr < Cmdr
|
|
55
69
|
seq << 65
|
56
70
|
c = :arrow_up
|
57
71
|
on_keypress(c)
|
58
|
-
input c
|
72
|
+
#input c
|
59
73
|
elsif c.ord == 66 and seq[1] == 91
|
60
74
|
seq << 66
|
61
75
|
c = :arrow_down
|
76
|
+
seq = []
|
77
|
+
on_keypress(c)
|
78
|
+
input c
|
79
|
+
|
80
|
+
elsif c.ord == 68 and seq[1] == 91
|
81
|
+
seq << 68
|
82
|
+
c = :arrow_left
|
83
|
+
seq = []
|
84
|
+
on_keypress(c)
|
85
|
+
input c
|
86
|
+
elsif c.ord == 49 and seq[1] == 91
|
87
|
+
seq << 49
|
88
|
+
#puts 'ctrl + right arrow'
|
89
|
+
elsif c.ord == 59 and seq[2] == 49
|
90
|
+
seq << 59
|
91
|
+
elsif c.ord == 53 and seq[3] == 59
|
92
|
+
seq << 53
|
93
|
+
elsif c.ord == 67 and seq[4] == 53
|
94
|
+
seq << 67
|
95
|
+
seq = []
|
96
|
+
c = :ctrl_arrow_right
|
62
97
|
on_keypress(c)
|
63
98
|
input c
|
64
99
|
elsif c.ord == 67 and seq[1] == 91
|
65
100
|
seq << 67
|
66
101
|
c = :arrow_right
|
102
|
+
#puts 'right arrow'
|
103
|
+
seq = []
|
67
104
|
on_keypress(c)
|
68
105
|
input c
|
69
|
-
elsif c.ord ==
|
70
|
-
seq <<
|
71
|
-
|
106
|
+
elsif c.ord == 79 and seq.first == 27
|
107
|
+
seq << 79
|
108
|
+
|
109
|
+
elsif c.ord == 72 and seq[1] == 79
|
110
|
+
c = :home_key
|
111
|
+
seq = []
|
72
112
|
on_keypress(c)
|
73
|
-
input c
|
74
|
-
|
75
113
|
elsif c == "\u0003" # CTRL+C
|
76
114
|
puts
|
77
115
|
@linebuffer = ''
|
78
116
|
display_output()
|
79
117
|
else
|
80
118
|
if block_given? then
|
81
|
-
on_keypress(c)
|
82
|
-
|
119
|
+
char = on_keypress(c)
|
120
|
+
|
121
|
+
unless (@linebuffer[0] == ':' and char == ':')
|
122
|
+
input(char, &blk) if char
|
123
|
+
end
|
124
|
+
|
83
125
|
else
|
84
126
|
input(c) do |command|
|
85
|
-
|
127
|
+
|
86
128
|
case command
|
87
129
|
when 'time'
|
88
130
|
Time.now.to_s
|
@@ -95,6 +137,14 @@ class ConsoleCmdr < Cmdr
|
|
95
137
|
|
96
138
|
end
|
97
139
|
|
140
|
+
def stop()
|
141
|
+
|
142
|
+
@running = false
|
143
|
+
'bye'
|
144
|
+
end
|
145
|
+
|
146
|
+
alias quit stop
|
147
|
+
|
98
148
|
protected
|
99
149
|
|
100
150
|
def reveal(c)
|
@@ -105,6 +155,7 @@ class ConsoleCmdr < Cmdr
|
|
105
155
|
else
|
106
156
|
c unless c.is_a? Symbol
|
107
157
|
end
|
158
|
+
#puts 'inside reveal'
|
108
159
|
print char unless @input_selection and @input_selection.any?
|
109
160
|
end
|
110
161
|
|
@@ -118,55 +169,161 @@ class ConsoleCmdr < Cmdr
|
|
118
169
|
|
119
170
|
def on_keypress(key)
|
120
171
|
|
121
|
-
return
|
172
|
+
return key if @linebuffer[0] == ':'
|
173
|
+
return key unless @pxi
|
122
174
|
|
123
|
-
|
124
175
|
if key.is_a? String then
|
125
176
|
|
126
177
|
@keys = []
|
127
178
|
|
179
|
+
if key.to_i.to_s == key and @input_selection and @input_selection.any?
|
180
|
+
r = select_item(key.to_i-1)
|
181
|
+
key = ''
|
182
|
+
return r
|
183
|
+
end
|
184
|
+
|
185
|
+
parent = @pxi.parent.title if @pxi.parent
|
186
|
+
|
128
187
|
a = @pxi.q?(@linebuffer+key)
|
129
188
|
|
130
189
|
if a then
|
131
190
|
unless @input_selection == a.map(&:title) then
|
132
191
|
@input_selection = a.map(&:title)
|
133
|
-
|
192
|
+
@selection = a.map.with_index do |x,i|
|
193
|
+
|
194
|
+
branch = x.records.any? ? :branch : nil
|
195
|
+
|
196
|
+
title = x.title
|
197
|
+
# is the target a web page?
|
198
|
+
title = title.green if x.target[0] == 'w'
|
199
|
+
title << '>' if branch
|
200
|
+
|
201
|
+
["%d.%s" % [i+1, title], branch, x.desc.yellow]
|
202
|
+
|
203
|
+
end
|
204
|
+
print ("\b" * @linebuffer.length) + @selection.map \
|
205
|
+
{|x| x.values_at(0,2).join ' '}.join(" | ") + "\n"
|
206
|
+
|
134
207
|
end
|
135
|
-
print ("\b" * @linebuffer.length)
|
208
|
+
print ("\b" * @linebuffer.length)
|
209
|
+
|
210
|
+
if (@linebuffer[/\s/] or a.length == 1) and key == ' ' then
|
211
|
+
|
212
|
+
@linebuffer.sub!(/\w+$/, @item_selected)
|
213
|
+
|
214
|
+
end
|
215
|
+
print @linebuffer + key
|
136
216
|
else
|
137
217
|
@input_selection = nil
|
138
218
|
end
|
139
219
|
|
140
|
-
elsif key == :arrow_down or key == :arrow_right
|
141
|
-
|
142
|
-
@
|
220
|
+
elsif key == :arrow_down or key == :arrow_right
|
221
|
+
|
222
|
+
return if @input_selection.nil?
|
143
223
|
|
144
|
-
|
145
|
-
return if linebuffer.nil?
|
224
|
+
@keys << :arrow_down
|
146
225
|
|
226
|
+
i = @keys.count(:arrow_down) - 1
|
227
|
+
|
228
|
+
if i == @selection.length then
|
229
|
+
@keys.pop
|
230
|
+
return nil
|
231
|
+
end
|
232
|
+
|
233
|
+
select_item(i)
|
234
|
+
|
235
|
+
elsif key == :arrow_left
|
147
236
|
|
237
|
+
return nil if @keys.empty?
|
238
|
+
|
239
|
+
@keys.pop
|
148
240
|
oldlinebuffer = @linebuffer
|
241
|
+
@linebuffer = @input_selection[@keys.count(:arrow_down) - 1]
|
242
|
+
|
243
|
+
height, width = TermInfo.screen_size
|
244
|
+
|
149
245
|
print ("\b" * oldlinebuffer.length)
|
246
|
+
rblankpadding = ' ' * (width)
|
247
|
+
print rblankpadding
|
248
|
+
print ("\b" * rblankpadding.length)
|
150
249
|
|
151
|
-
@linebuffer
|
250
|
+
print @linebuffer
|
251
|
+
|
252
|
+
elsif key == :home_key
|
152
253
|
|
153
254
|
height, width = TermInfo.screen_size
|
154
255
|
|
155
|
-
|
156
|
-
|
256
|
+
print ("\b" * @linebuffer.to_s.length)
|
257
|
+
@linebuffer = ''
|
258
|
+
rblankpadding = ' ' * (width)
|
157
259
|
print rblankpadding
|
158
|
-
print ("\b" * rblankpadding.length)
|
260
|
+
print ("\b" * rblankpadding.length)
|
159
261
|
|
160
|
-
elsif key == :
|
262
|
+
elsif key == :ctrl_arrow_right
|
161
263
|
|
162
|
-
return if
|
264
|
+
return if @input_selection.nil?
|
163
265
|
|
164
|
-
@keys
|
165
|
-
oldlinebuffer = @linebuffer
|
166
|
-
@linebuffer = @input_selection[@keys.count(:arrow_down) - 1]
|
266
|
+
@keys << :arrow_down
|
167
267
|
|
168
|
-
|
268
|
+
i = @keys.count(:arrow_down) - 1
|
269
|
+
|
270
|
+
if i == @selection.length then
|
271
|
+
@keys.pop
|
272
|
+
return nil
|
273
|
+
end
|
274
|
+
|
275
|
+
select_item(i, append_command: true)
|
169
276
|
end
|
277
|
+
|
278
|
+
return key
|
279
|
+
end
|
280
|
+
|
281
|
+
private
|
282
|
+
|
283
|
+
def select_item(i, append_command: false)
|
284
|
+
|
285
|
+
|
286
|
+
execute_command = false
|
287
|
+
|
288
|
+
linebuffer = @input_selection[i]
|
289
|
+
@item_selected = @input_selection[i]
|
290
|
+
return if linebuffer.nil?
|
291
|
+
|
292
|
+
|
293
|
+
oldlinebuffer = @linebuffer
|
294
|
+
print ("\b" * oldlinebuffer.length)
|
295
|
+
|
296
|
+
|
297
|
+
if @selection[i][1] == :branch or append_command then
|
298
|
+
|
299
|
+
if @linebuffer[-1] != ' ' then
|
300
|
+
a = @linebuffer.split(/ /)
|
301
|
+
a.pop
|
302
|
+
@linebuffer = a.join ' '
|
303
|
+
end
|
304
|
+
|
305
|
+
linebuffer.prepend @linebuffer
|
306
|
+
execute_command = false
|
307
|
+
else
|
308
|
+
execute_command = true
|
309
|
+
end
|
310
|
+
|
311
|
+
if @selection[i][1] == :branch then
|
312
|
+
words = @linebuffer.split(/ /)
|
313
|
+
@linebuffer = (words[0..-2] + [linebuffer]).join(' ')
|
314
|
+
else
|
315
|
+
@linebuffer = linebuffer
|
316
|
+
end
|
317
|
+
|
318
|
+
height, width = TermInfo.screen_size
|
319
|
+
|
320
|
+
rblankpadding = ' ' * (width - @linebuffer.length )
|
321
|
+
print @linebuffer
|
322
|
+
print rblankpadding
|
323
|
+
print ("\b" * rblankpadding.length)
|
324
|
+
|
325
|
+
execute_command ? "\r" : nil
|
326
|
+
|
170
327
|
end
|
171
328
|
|
172
|
-
end
|
329
|
+
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: console_cmdr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
JRl6lG+PlMKYzPBmY9bJ9nnHUzlNaUigwV8HWjUzq9NmckAilhs430t3xe8+fsIc
|
32
32
|
uSZB48oWIrOfew==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2016-12-
|
34
|
+
date: 2016-12-02 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: cmdr
|
@@ -73,6 +73,26 @@ dependencies:
|
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 0.1.0
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: colored
|
78
|
+
requirement: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.2'
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '1.2'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - "~>"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '1.2'
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '1.2'
|
76
96
|
- !ruby/object:Gem::Dependency
|
77
97
|
name: terminfo
|
78
98
|
requirement: !ruby/object:Gem::Requirement
|
metadata.gz.sig
CHANGED
Binary file
|