console_cmdr 0.2.0 → 0.3.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 +0 -0
- data/lib/console_cmdr.rb +56 -10
- data.tar.gz.sig +0 -0
- metadata +21 -1
- 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: c3308726d84f864d270fba33b15616f80844f7e8
|
4
|
+
data.tar.gz: e5cbfe7d970047080992c9e88afaf858735fa65e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a128d30143c79cf842121983ff7a60fc94e9ee45254565fe38812e2e1fb7ad7f59b060ad66486e27092fb0fd7e44f793e5f6d2dd95b5ea2dd16dd19c9803f5dc
|
7
|
+
data.tar.gz: 6a843eba42806265fedd8c5b71a2e7305ae679302e111ba6e10e6e929f379dd6d178a3ecce41a5418bae3cf620244f14659233c35d98dece4993fcbb9effd434
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/console_cmdr.rb
CHANGED
@@ -4,14 +4,19 @@
|
|
4
4
|
|
5
5
|
require 'cmdr'
|
6
6
|
require 'pxindex'
|
7
|
+
require 'terminfo'
|
7
8
|
require 'io/console'
|
8
9
|
|
9
10
|
|
11
|
+
|
10
12
|
class ConsoleCmdr < Cmdr
|
11
13
|
|
12
14
|
def initialize(pxindex: nil)
|
13
15
|
super()
|
16
|
+
@pxindex_filepath = pxindex
|
14
17
|
@pxi = pxindex ? PxIndex.new(pxindex) : nil
|
18
|
+
|
19
|
+
@keys = []
|
15
20
|
end
|
16
21
|
|
17
22
|
def cli_banner()
|
@@ -19,12 +24,18 @@ class ConsoleCmdr < Cmdr
|
|
19
24
|
print "> "
|
20
25
|
end
|
21
26
|
|
27
|
+
def reload()
|
28
|
+
@pxi = @pxindex_filepath ? PxIndex.new(@pxindex_filepath) : nil
|
29
|
+
end
|
30
|
+
|
22
31
|
def start(&blk)
|
23
32
|
|
24
33
|
cli_banner()
|
25
34
|
|
26
35
|
seq = []
|
27
|
-
|
36
|
+
|
37
|
+
loop do
|
38
|
+
|
28
39
|
c = $stdin.getch
|
29
40
|
|
30
41
|
#puts c.ord
|
@@ -60,6 +71,11 @@ class ConsoleCmdr < Cmdr
|
|
60
71
|
c = :arrow_left
|
61
72
|
on_keypress(c)
|
62
73
|
input c
|
74
|
+
|
75
|
+
elsif c == "\u0003" # CTRL+C
|
76
|
+
puts
|
77
|
+
@linebuffer = ''
|
78
|
+
display_output()
|
63
79
|
else
|
64
80
|
if block_given? then
|
65
81
|
on_keypress(c)
|
@@ -75,7 +91,7 @@ class ConsoleCmdr < Cmdr
|
|
75
91
|
end
|
76
92
|
end
|
77
93
|
|
78
|
-
end
|
94
|
+
end #/ end of loop
|
79
95
|
|
80
96
|
end
|
81
97
|
|
@@ -104,22 +120,52 @@ class ConsoleCmdr < Cmdr
|
|
104
120
|
|
105
121
|
return unless @pxi
|
106
122
|
|
107
|
-
|
123
|
+
|
108
124
|
if key.is_a? String then
|
109
|
-
|
125
|
+
|
126
|
+
@keys = []
|
127
|
+
|
110
128
|
a = @pxi.q?(@linebuffer+key)
|
111
129
|
|
112
130
|
if a then
|
113
|
-
@input_selection
|
114
|
-
|
115
|
-
|
131
|
+
unless @input_selection == a.map(&:title) then
|
132
|
+
@input_selection = a.map(&:title)
|
133
|
+
print ("\b" * @linebuffer.length) + @input_selection.inspect + "\n"
|
134
|
+
end
|
135
|
+
print ("\b" * @linebuffer.length) + @linebuffer + key
|
116
136
|
else
|
117
137
|
@input_selection = nil
|
118
138
|
end
|
119
|
-
|
120
|
-
|
139
|
+
|
140
|
+
elsif key == :arrow_down or key == :arrow_right
|
141
|
+
|
142
|
+
@keys << :arrow_down
|
143
|
+
|
144
|
+
linebuffer = @input_selection[@keys.count(:arrow_down) - 1]
|
145
|
+
return if linebuffer.nil?
|
146
|
+
|
147
|
+
|
148
|
+
oldlinebuffer = @linebuffer
|
149
|
+
print ("\b" * oldlinebuffer.length)
|
150
|
+
|
151
|
+
@linebuffer = linebuffer
|
152
|
+
|
153
|
+
height, width = TermInfo.screen_size
|
154
|
+
|
155
|
+
rblankpadding = ' ' * (width - @linebuffer.length )
|
156
|
+
print @linebuffer
|
157
|
+
print rblankpadding
|
158
|
+
print ("\b" * rblankpadding.length)
|
159
|
+
|
160
|
+
elsif key == :arrow_left
|
161
|
+
|
162
|
+
return if @keys.empty?
|
163
|
+
|
164
|
+
@keys.pop
|
165
|
+
oldlinebuffer = @linebuffer
|
166
|
+
@linebuffer = @input_selection[@keys.count(:arrow_down) - 1]
|
121
167
|
|
122
|
-
print ("\b" *
|
168
|
+
print ("\b" * oldlinebuffer.length) + @linebuffer
|
123
169
|
end
|
124
170
|
end
|
125
171
|
|
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -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: terminfo
|
78
|
+
requirement: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.1'
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.1.1
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - "~>"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0.1'
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 0.1.1
|
76
96
|
description:
|
77
97
|
email: james@r0bertson.co.uk
|
78
98
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|