djinni 0.1.8 → 0.1.9
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/lib/builtin/help.rb +5 -4
- data/lib/builtin/history.rb +5 -5
- data/lib/builtin/quit.rb +2 -2
- data/lib/djinni.rb +14 -12
- data/lib/djinni_wish.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 054d09c1a59329243cc68fd838539f7886a73099
|
4
|
+
data.tar.gz: 90bed7d10befe6e76a61c495d2837ea6b93eb2c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc21126e3e26610d8988c05ea07f22ccadeaab6f6f1f2567b2ae9b9bf7ff899d04ae7095d10dc8761c49b6ede2f3062c1ec8220cc767dedc7c1687eafb290820
|
7
|
+
data.tar.gz: a98be004548eb6bf5d48915b66d2a49c9df10b47c952d3193298eb1ff7025328cce4ee99675edc8f11d3456314917769717b7d1cd26865c9e31210956e57461e
|
data/lib/builtin/help.rb
CHANGED
@@ -9,13 +9,14 @@ class DjinniHelpWish < DjinniWish
|
|
9
9
|
return "Show helpful information for a wish or wishes"
|
10
10
|
end
|
11
11
|
|
12
|
-
def execute(args,
|
12
|
+
def execute(args, djinni_env = {})
|
13
|
+
wishes = djinni_env["djinni_wishes"].sort
|
13
14
|
if (args.nil? || args.empty?)
|
14
|
-
|
15
|
+
wishes.map do |aliaz, wish|
|
15
16
|
puts "#{aliaz}\t#{wish.description}"
|
16
17
|
end
|
17
18
|
elsif (args.split(" ").length == 1)
|
18
|
-
|
19
|
+
wishes.map do |aliaz, wish|
|
19
20
|
if (aliaz == args)
|
20
21
|
wish.usage
|
21
22
|
return
|
@@ -27,7 +28,7 @@ class DjinniHelpWish < DjinniWish
|
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
|
-
def tab_complete(input,
|
31
|
+
def tab_complete(input, djinni_env = {})
|
31
32
|
return input
|
32
33
|
end
|
33
34
|
|
data/lib/builtin/history.rb
CHANGED
@@ -9,9 +9,9 @@ class DjinniHistoryWish < DjinniWish
|
|
9
9
|
return "Show history or execute commands from history"
|
10
10
|
end
|
11
11
|
|
12
|
-
def execute(args,
|
13
|
-
djinni =
|
14
|
-
history =
|
12
|
+
def execute(args, djinni_env = {})
|
13
|
+
djinni = djinni_env["djinni"]
|
14
|
+
history = djinni_env["djinni_history"]
|
15
15
|
|
16
16
|
case args
|
17
17
|
when nil, ""
|
@@ -34,8 +34,8 @@ class DjinniHistoryWish < DjinniWish
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
def tab_complete(input,
|
38
|
-
history =
|
37
|
+
def tab_complete(input, djinni_env = {})
|
38
|
+
history = djinni_env["djinni_history"]
|
39
39
|
|
40
40
|
included = input.split(" ")
|
41
41
|
completions = (0...history.length).to_a
|
data/lib/builtin/quit.rb
CHANGED
@@ -9,11 +9,11 @@ class DjinniQuitWish < DjinniWish
|
|
9
9
|
return "Quit"
|
10
10
|
end
|
11
11
|
|
12
|
-
def execute(args,
|
12
|
+
def execute(args, djinni_env = {})
|
13
13
|
exit 0
|
14
14
|
end
|
15
15
|
|
16
|
-
def tab_complete(input,
|
16
|
+
def tab_complete(input, djinni_env = {})
|
17
17
|
return input
|
18
18
|
end
|
19
19
|
|
data/lib/djinni.rb
CHANGED
@@ -7,12 +7,12 @@ require "terminfo"
|
|
7
7
|
class Djinni
|
8
8
|
include DjinniError
|
9
9
|
|
10
|
-
def grant_wish(input,
|
10
|
+
def grant_wish(input, djinni_env = {})
|
11
11
|
return "" if (input.nil? || input.empty?)
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
djinni_env["djinni"] = self
|
14
|
+
djinni_env["djinni_history"] = @history
|
15
|
+
djinni_env["djinni_wishes"] = @wishes
|
16
16
|
|
17
17
|
case input[-1]
|
18
18
|
when "\x03" # ^C
|
@@ -30,8 +30,10 @@ class Djinni
|
|
30
30
|
if (input.include?(" "))
|
31
31
|
name, args = input.split(" ", 2)
|
32
32
|
return input if (!@wishes.has_key?(name))
|
33
|
+
|
33
34
|
wish = @wishes[name]
|
34
|
-
|
35
|
+
complete = wish.tab_complete(args, djinni_env)
|
36
|
+
return "#{name} #{complete}"
|
35
37
|
else
|
36
38
|
wishes = @wishes.keys
|
37
39
|
wishes.sort.each do |wish|
|
@@ -50,7 +52,7 @@ class Djinni
|
|
50
52
|
|
51
53
|
@wishes.sort.map do |aliaz, wish|
|
52
54
|
if (aliaz == name)
|
53
|
-
wish.execute(args,
|
55
|
+
wish.execute(args, djinni_env)
|
54
56
|
store_history(input)
|
55
57
|
return ""
|
56
58
|
end
|
@@ -107,10 +109,6 @@ class Djinni
|
|
107
109
|
end
|
108
110
|
)
|
109
111
|
|
110
|
-
load_builtins
|
111
|
-
end
|
112
|
-
|
113
|
-
def load_builtins
|
114
112
|
load_wishes("#{File.dirname(__FILE__)}/builtin")
|
115
113
|
end
|
116
114
|
|
@@ -132,6 +130,7 @@ class Djinni
|
|
132
130
|
@wishes[aliaz] = wish
|
133
131
|
end
|
134
132
|
end
|
133
|
+
private :load_wish
|
135
134
|
|
136
135
|
def load_wishes(dir)
|
137
136
|
return if @loaded_from.include?(dir)
|
@@ -152,11 +151,13 @@ class Djinni
|
|
152
151
|
@loaded_from.push(dir)
|
153
152
|
end
|
154
153
|
|
155
|
-
def prompt(prompt_sym = "$ ")
|
154
|
+
def prompt(djinni_env = {}, prompt_sym = "$ ")
|
156
155
|
@interactive = true
|
157
156
|
|
157
|
+
djinni_env["prompt_sym"] = prompt_sym
|
158
158
|
buffer = ""
|
159
159
|
loop do
|
160
|
+
prompt_sym = djinni_env["prompt_sym"]
|
160
161
|
blank_line = Array.new(@width, " ").join
|
161
162
|
fill_len = @width - prompt_sym.length - buffer.length + 1
|
162
163
|
|
@@ -172,7 +173,7 @@ class Djinni
|
|
172
173
|
print "\r#{prompt_sym}#{buffer}"
|
173
174
|
|
174
175
|
# Process input
|
175
|
-
buffer = grant_wish(buffer + STDIN.getch)
|
176
|
+
buffer = grant_wish(buffer + STDIN.getch, djinni_env)
|
176
177
|
|
177
178
|
if (buffer.nil?)
|
178
179
|
puts "Wish not found!"
|
@@ -193,4 +194,5 @@ class Djinni
|
|
193
194
|
@history.push(input)
|
194
195
|
@hist_index = nil
|
195
196
|
end
|
197
|
+
private :store_history
|
196
198
|
end
|
data/lib/djinni_wish.rb
CHANGED
@@ -14,13 +14,13 @@ class DjinniWish
|
|
14
14
|
)
|
15
15
|
end
|
16
16
|
|
17
|
-
def execute(args,
|
17
|
+
def execute(args, djinni_env = {})
|
18
18
|
raise InterfaceNotImplementedError.new(
|
19
19
|
"execute() not implemented!"
|
20
20
|
)
|
21
21
|
end
|
22
22
|
|
23
|
-
def tab_complete(input,
|
23
|
+
def tab_complete(input, djinni_env = {})
|
24
24
|
raise InterfaceNotImplementedError.new(
|
25
25
|
"tab_complete() not implemented!"
|
26
26
|
)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: djinni
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Whittaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|