intar 2.12 → 2.14
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/README +3 -3
- data/lib/intar/prompt.rb +20 -20
- data/lib/intar/version.rb +1 -1
- data/lib/intar.rb +44 -27
- 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: dfabe8ba50f5502971175b8ec48582e1c24d68b75cf164ed10b7b1545b8ed1ec
|
4
|
+
data.tar.gz: 376905c4c3f81b252662f6df9803ad8bd9038475c8ccc5c9adc6f79239f5c3c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cf36852e6c4387d6eb85ac8b9dafaced557033bc7be3004eae58ea22529155d08cd7e213d9cfb5a3f630e8ac84b04113e35d39a5f811388c1dcc339b56fc9b0
|
7
|
+
data.tar.gz: 156c61b56e014f810f45da42a7500a9ce6b5f937b090eb3d2f6e591c786441b0f51ffb0c5c353ba56e7ece4d9205546f6a9fad48d3bda726b6b6970f2e5ac102
|
data/README
CHANGED
@@ -23,9 +23,9 @@ after this in Irb and in Intar:
|
|
23
23
|
|
24
24
|
=== Subcommands
|
25
25
|
|
26
|
-
obj.method
|
27
|
-
obj.each
|
28
|
-
obj.method
|
26
|
+
obj.method ! enter a sub-Intar
|
27
|
+
obj.each ! enter multiple sub-Intars
|
28
|
+
obj.method !x enter a sub-Intar with variable x
|
29
29
|
|
30
30
|
\q exit from the innermost sub-Intar
|
31
31
|
\q! exit from the innermost sub-Intar loop
|
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
|
@@ -154,10 +168,10 @@ class Intar
|
|
154
168
|
private
|
155
169
|
|
156
170
|
def eval_line l
|
157
|
-
ls = l.sub %r/\s
|
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.14'
|
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-19 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
|
'
|