intar 2.12 → 2.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/intar/prompt.rb +20 -20
- data/lib/intar/version.rb +1 -1
- data/lib/intar.rb +43 -26
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e86e4f946139fe4ff918beed2626ea4a9c61b147921469248bbcc5666b2d4aae
|
4
|
+
data.tar.gz: 8ea712436624aadf51c8110aac49524782d7052e0ab1cc6261fda9e8b25f8b9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6528b54a1b584b091d894ca95c61ab15e6e276cf49d6b6fbd8f737608a96852908b87e03c31c250609fac12fdccb7ddefe1d41ebe55b4fa39fc02eefd27d7457
|
7
|
+
data.tar.gz: 69e33fe0bf79a6b1bd8e34d1958c21b4720fa6e7a4912c423cacef1c49f4d9a176a3c7d51cc8a52ad76d5d9d7580e0d5d5e13755bbf07b48c3bc97e43b4291d5
|
data/lib/intar/prompt.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
|
5
5
|
require "supplement"
|
6
|
-
require "
|
6
|
+
require "reline"
|
7
7
|
|
8
8
|
|
9
9
|
class Intar
|
@@ -12,23 +12,23 @@ class Intar
|
|
12
12
|
|
13
13
|
def initialize histfile: nil, limit: nil
|
14
14
|
@limit = limit.nonzero?
|
15
|
-
|
15
|
+
Reline::HISTORY.clear
|
16
16
|
@new = 0
|
17
17
|
end
|
18
18
|
|
19
19
|
def push text
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
Reline.pre_input_hook = proc {
|
21
|
+
Reline.insert_text text
|
22
|
+
Reline.redisplay
|
23
23
|
}
|
24
24
|
nil
|
25
25
|
end
|
26
26
|
|
27
27
|
def ask prompt
|
28
28
|
begin
|
29
|
-
|
29
|
+
Reline.readline prompt
|
30
30
|
ensure
|
31
|
-
|
31
|
+
Reline.pre_input_hook = nil
|
32
32
|
end
|
33
33
|
rescue Interrupt
|
34
34
|
puts
|
@@ -39,21 +39,21 @@ class Intar
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def last
|
42
|
-
|
42
|
+
Reline::HISTORY[-1] unless Reline::HISTORY.empty?
|
43
43
|
end
|
44
44
|
|
45
45
|
def scan_history
|
46
|
-
i =
|
46
|
+
i = Reline::HISTORY.length
|
47
47
|
while i > 0 do
|
48
48
|
i -= 1
|
49
|
-
yield
|
49
|
+
yield Reline::HISTORY[i]
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
def push_history item
|
54
54
|
item.empty? and return
|
55
55
|
last != item or return
|
56
|
-
|
56
|
+
Reline::HISTORY.push item
|
57
57
|
@new += 1
|
58
58
|
end
|
59
59
|
|
@@ -61,14 +61,14 @@ class Intar
|
|
61
61
|
with_filepath filepath do |p|
|
62
62
|
read_file_if p do |f|
|
63
63
|
h = []
|
64
|
-
@new.times { h.push
|
65
|
-
|
64
|
+
@new.times { h.push Reline::HISTORY.pop }
|
65
|
+
Reline::HISTORY.clear
|
66
66
|
f.each_line { |l|
|
67
67
|
l.chomp!
|
68
68
|
l.sub! "\r", "\n"
|
69
|
-
|
69
|
+
Reline::HISTORY.push l
|
70
70
|
}
|
71
|
-
|
71
|
+
Reline::HISTORY.push h.pop while h.any?
|
72
72
|
end
|
73
73
|
nil
|
74
74
|
end
|
@@ -86,9 +86,9 @@ class Intar
|
|
86
86
|
end
|
87
87
|
File.open p, "w" do |f|
|
88
88
|
old.each { |l| f.puts l }
|
89
|
-
i =
|
90
|
-
while i <
|
91
|
-
l =
|
89
|
+
i = Reline::HISTORY.length - @new
|
90
|
+
while i < Reline::HISTORY.length do
|
91
|
+
l = Reline::HISTORY[ i].sub "\n", "\r"
|
92
92
|
f.puts l
|
93
93
|
i += 1
|
94
94
|
end
|
@@ -99,8 +99,8 @@ class Intar
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def limit_history max
|
102
|
-
n =
|
103
|
-
n.times {
|
102
|
+
n = Reline::HISTORY.length - max
|
103
|
+
n.times { Reline::HISTORY.shift }
|
104
104
|
@new > max and @new = max
|
105
105
|
nil
|
106
106
|
end
|
data/lib/intar/version.rb
CHANGED
data/lib/intar.rb
CHANGED
@@ -40,9 +40,7 @@ everywhere inside your Ruby program.
|
|
40
40
|
|
41
41
|
|
42
42
|
class Object
|
43
|
-
def
|
44
|
-
binding
|
45
|
-
end
|
43
|
+
def empty_binding ; binding ; end
|
46
44
|
end
|
47
45
|
|
48
46
|
|
@@ -50,15 +48,21 @@ class Intar
|
|
50
48
|
|
51
49
|
class <<self
|
52
50
|
|
53
|
-
def open obj =
|
51
|
+
def open obj = main, **params
|
54
52
|
i = new obj, **params
|
55
53
|
yield i
|
56
54
|
end
|
57
55
|
|
58
|
-
def run obj =
|
56
|
+
def run obj = main, **params
|
59
57
|
open obj, **params do |i| i.run end
|
60
58
|
end
|
61
59
|
|
60
|
+
private
|
61
|
+
|
62
|
+
def main
|
63
|
+
TOPLEVEL_BINDING.eval "self"
|
64
|
+
end
|
65
|
+
|
62
66
|
end
|
63
67
|
|
64
68
|
|
@@ -74,25 +78,33 @@ class Intar
|
|
74
78
|
histmax: 500,
|
75
79
|
}
|
76
80
|
|
77
|
-
@@current = nil
|
78
81
|
|
79
|
-
|
82
|
+
private
|
83
|
+
|
84
|
+
@@prev = nil
|
85
|
+
|
86
|
+
SET_BINDING = "proc { |_| _.instance_eval { binding } }"
|
87
|
+
|
80
88
|
def initialize obj = nil, **params
|
81
|
-
@obj = obj
|
82
|
-
|
83
|
-
|
84
|
-
@
|
85
|
-
@
|
86
|
-
@
|
89
|
+
@obj = obj
|
90
|
+
@n = 1
|
91
|
+
if @@prev then
|
92
|
+
@params = @@prev.params
|
93
|
+
@prompt = @@prev.prompt
|
94
|
+
@depth = @@prev.depth + 1
|
95
|
+
sb = @@prev.execute SET_BINDING
|
87
96
|
else
|
88
97
|
@params = DEFAULTS.dup.update params
|
89
98
|
@prompt = Prompt.new
|
90
|
-
@depth
|
91
|
-
|
99
|
+
@depth = 0
|
100
|
+
sb = empty_binding.eval SET_BINDING
|
92
101
|
end
|
93
|
-
@
|
102
|
+
@binding = sb.call @obj
|
94
103
|
end
|
95
104
|
|
105
|
+
public
|
106
|
+
|
107
|
+
attr_reader :params, :prompt, :depth, :n, :obj
|
96
108
|
|
97
109
|
class Clear < Exception ; end
|
98
110
|
class Quit < Exception ; end
|
@@ -103,7 +115,7 @@ class Intar
|
|
103
115
|
def run
|
104
116
|
handle_history do
|
105
117
|
set_current do
|
106
|
-
|
118
|
+
execute OLD_INIT
|
107
119
|
loop do
|
108
120
|
l = readline
|
109
121
|
l or break
|
@@ -135,15 +147,17 @@ class Intar
|
|
135
147
|
r = $!
|
136
148
|
show_exception
|
137
149
|
end
|
138
|
-
|
150
|
+
(execute OLD_SET).call r, @n
|
139
151
|
@n += 1
|
140
152
|
end
|
153
|
+
ensure
|
154
|
+
execute OLD_INIT
|
141
155
|
end
|
142
156
|
end
|
143
157
|
end
|
144
158
|
|
145
159
|
def execute code
|
146
|
-
eval code, @
|
160
|
+
@binding.eval code, @file||"#{self.class}/execute"
|
147
161
|
end
|
148
162
|
|
149
163
|
def set_var name, val
|
@@ -157,7 +171,7 @@ class Intar
|
|
157
171
|
ls = l.sub %r/\s+&(\w+)?\s*\z/ do
|
158
172
|
<<~EOT
|
159
173
|
\ do |obj|
|
160
|
-
Intar.open #{
|
174
|
+
Intar.open #{$1 ? "self" : "obj"} do |i|
|
161
175
|
#{"# " unless $1}i.set_var "#$1", obj
|
162
176
|
i.run
|
163
177
|
end
|
@@ -166,7 +180,7 @@ class Intar
|
|
166
180
|
end
|
167
181
|
EOT
|
168
182
|
end
|
169
|
-
@redir.redirect_output do
|
183
|
+
@redir.redirect_output do execute ls end
|
170
184
|
end
|
171
185
|
|
172
186
|
def handle_history
|
@@ -183,10 +197,10 @@ class Intar
|
|
183
197
|
end
|
184
198
|
|
185
199
|
def set_current
|
186
|
-
old, @@
|
200
|
+
old, @@prev = @@prev, self
|
187
201
|
yield
|
188
202
|
ensure
|
189
|
-
@@
|
203
|
+
@@prev = old
|
190
204
|
end
|
191
205
|
|
192
206
|
def find_redirect line
|
@@ -196,8 +210,11 @@ class Intar
|
|
196
210
|
end
|
197
211
|
|
198
212
|
|
199
|
-
|
213
|
+
OLD_INIT = <<~EOT
|
200
214
|
_, __, ___ = nil, nil, nil
|
215
|
+
EOT
|
216
|
+
|
217
|
+
OLD_SET = <<~EOT
|
201
218
|
proc { |r,n|
|
202
219
|
Array === __ or __ = []
|
203
220
|
Hash === ___ or ___ = {}
|
@@ -331,7 +348,7 @@ class Intar
|
|
331
348
|
def eval_param l
|
332
349
|
eot = "EOT0001"
|
333
350
|
eot.succ! while l[ eot]
|
334
|
-
l =
|
351
|
+
l = execute "<<#{eot}\n#{l}\n#{eot}"
|
335
352
|
l.strip!
|
336
353
|
l.notempty?
|
337
354
|
end
|
@@ -549,7 +566,7 @@ class Intar
|
|
549
566
|
x or raise Failed, "No input file given."
|
550
567
|
l = File.read x
|
551
568
|
@redir.redirect_output do
|
552
|
-
eval l,
|
569
|
+
@binding.eval l, x
|
553
570
|
end
|
554
571
|
end
|
555
572
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: intar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '2.
|
4
|
+
version: '2.13'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bertram Scharpf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appl
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: reline
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.3'
|
41
55
|
description: 'This is a lean replacement for Irb.
|
42
56
|
|
43
57
|
'
|