console_cmdr 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +3 -2
- data.tar.gz.sig +1 -2
- data/lib/console_cmdr.rb +55 -4
- 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: 5d2eaefdcfd50e5023446a819454eb5369910098
|
4
|
+
data.tar.gz: 4de39d32a83d7a75159aaa06338cf3bf222a7751
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df98a024361bdd1f020b4ac73c067afa4515a299d5996abf5a11ae0d914658f8dbea3f2101743f51e8eac2868d78863b6bf1bb8a5435eb4be23fca0031f7ed15
|
7
|
+
data.tar.gz: 34b6b5203a916613fc009107dbd441d1aad3ab97ab975c54f0b55caa4d7ad03216767141fdcb3955f9b18da2bb9d807217f71d19c0b9ff7e5287cad7ac0301d5
|
checksums.yaml.gz.sig
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
-
|
2
|
-
�
|
1
|
+
�Yy�j���T��-ݫg^�L�.�Ƨ-{�Cg!��a���-�qK�3Dn����|�Ϣ�s��w�6G=��56>hBq�������*�b�'E���M�`O+�Q�Y#H�R���,�������2
|
2
|
+
F�?�˫>j�w�?���fʱ锋/R�G��H�n ���3���~nR�Y�e�.W'�,y0Q��{_Q��`h�'>y�
|
3
|
+
Ti;$�.�0�;���]?������bݪjln�+�T6��rN(K�
|
data.tar.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
W���ʩZ�,�IEם�Z�U�Ǔ�s_B��J��L�T�z{�k"�t^%w}�^�IIxX�|�
|
1
|
+
�6^���X�6�с��$�"��ml�HS�����0��bۆ�4B�ӆ�I��E`?c=QHfv��'��x��\��U"�~�7��wȻz�����{�`��˭�/?a�w2H�Rd�A4�"5Թ�s��2���Ǜ�-
|
data/lib/console_cmdr.rb
CHANGED
@@ -3,11 +3,16 @@
|
|
3
3
|
# file: console_cmdr.rb
|
4
4
|
|
5
5
|
require 'cmdr'
|
6
|
+
require 'pxindex'
|
6
7
|
require 'io/console'
|
7
8
|
|
8
9
|
|
9
10
|
class ConsoleCmdr < Cmdr
|
10
11
|
|
12
|
+
def initialize(pxindex: nil)
|
13
|
+
super()
|
14
|
+
@pxi = pxindex ? PxIndex.new(pxindex) : nil
|
15
|
+
end
|
11
16
|
|
12
17
|
def cli_banner()
|
13
18
|
puts "welcome, this code is powered by the cmdr gem\n\n"
|
@@ -23,6 +28,13 @@ class ConsoleCmdr < Cmdr
|
|
23
28
|
c = $stdin.getch
|
24
29
|
|
25
30
|
#puts c.ord
|
31
|
+
|
32
|
+
# [27, 91, 65] = up_arrow
|
33
|
+
# [27, 91, 66] = down_arrow
|
34
|
+
# [27, 91, 67] = right_arrow
|
35
|
+
# [27, 91, 68] = left_arrow
|
36
|
+
# 13 = enter
|
37
|
+
|
26
38
|
if c.ord == 27 then
|
27
39
|
seq << 27
|
28
40
|
#print "\b\b"
|
@@ -31,9 +43,26 @@ class ConsoleCmdr < Cmdr
|
|
31
43
|
elsif c.ord == 65 and seq[1] == 91
|
32
44
|
seq << 65
|
33
45
|
c = :arrow_up
|
46
|
+
on_keypress(c)
|
34
47
|
input c
|
48
|
+
elsif c.ord == 66 and seq[1] == 91
|
49
|
+
seq << 66
|
50
|
+
c = :arrow_down
|
51
|
+
on_keypress(c)
|
52
|
+
input c
|
53
|
+
elsif c.ord == 67 and seq[1] == 91
|
54
|
+
seq << 67
|
55
|
+
c = :arrow_right
|
56
|
+
on_keypress(c)
|
57
|
+
input c
|
58
|
+
elsif c.ord == 68 and seq[1] == 91
|
59
|
+
seq << 68
|
60
|
+
c = :arrow_left
|
61
|
+
on_keypress(c)
|
62
|
+
input c
|
35
63
|
else
|
36
64
|
if block_given? then
|
65
|
+
on_keypress(c)
|
37
66
|
input(c, &blk)
|
38
67
|
else
|
39
68
|
input(c) do |command|
|
@@ -46,21 +75,21 @@ class ConsoleCmdr < Cmdr
|
|
46
75
|
end
|
47
76
|
end
|
48
77
|
|
49
|
-
end until c == "\u0003"
|
78
|
+
end until c == "\u0003" # CTRL+C
|
50
79
|
|
51
80
|
end
|
52
81
|
|
53
82
|
protected
|
54
83
|
|
55
84
|
def reveal(c)
|
56
|
-
|
85
|
+
|
57
86
|
char = case c
|
58
87
|
when "\u007F" # backspace
|
59
88
|
"\b \b"
|
60
89
|
else
|
61
90
|
c unless c.is_a? Symbol
|
62
91
|
end
|
63
|
-
print char
|
92
|
+
print char unless @input_selection and @input_selection.any?
|
64
93
|
end
|
65
94
|
|
66
95
|
def display_output(s='')
|
@@ -70,6 +99,28 @@ class ConsoleCmdr < Cmdr
|
|
70
99
|
def cli_update(s='')
|
71
100
|
print s
|
72
101
|
end
|
102
|
+
|
103
|
+
def on_keypress(key)
|
104
|
+
|
105
|
+
return unless @pxi
|
106
|
+
|
107
|
+
#puts 'key:' + key.inspect
|
108
|
+
if key.is_a? String then
|
109
|
+
#puts '@linebuffer: ' + @linebuffer+key.inspect
|
110
|
+
a = @pxi.q?(@linebuffer+key)
|
111
|
+
|
112
|
+
if a then
|
113
|
+
@input_selection = a.map(&:title)
|
114
|
+
print ("\b" * @linebuffer.length) + @input_selection.last + "\n"
|
115
|
+
print @linebuffer + key
|
116
|
+
else
|
117
|
+
@input_selection = nil
|
118
|
+
end
|
119
|
+
elsif key == :arrow_down
|
120
|
+
@linebuffer = @input_selection.first
|
73
121
|
|
74
|
-
|
122
|
+
print ("\b" * @linebuffer.length) + @linebuffer
|
123
|
+
end
|
124
|
+
end
|
75
125
|
|
126
|
+
end
|
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.2.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-
|
34
|
+
date: 2016-12-01 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: cmdr
|
@@ -53,6 +53,26 @@ dependencies:
|
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: 0.4.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: pxindex
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0.1'
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 0.1.0
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - "~>"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0.1'
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.1.0
|
56
76
|
description:
|
57
77
|
email: james@r0bertson.co.uk
|
58
78
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|