fxri 0.3.2 → 0.3.3
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.
- data/fxri +260 -258
- data/fxri.gemspec +16 -16
- data/fxri.kpf +66 -0
- data/lib/Empty_Text_Field_Handler.rb +57 -57
- data/lib/FoxDisplayer.rb +146 -146
- data/lib/FoxTextFormatter.rb +270 -260
- data/lib/Globals.rb +3 -2
- data/lib/Icon_Loader.rb +30 -30
- data/lib/Packet_Item.rb +167 -167
- data/lib/Packet_List.rb +187 -187
- data/lib/Recursive_Open_Struct.rb +205 -205
- data/lib/RiManager.rb +133 -133
- data/lib/Search_Engine.rb +159 -159
- data/lib/fxirb.rb +321 -332
- metadata +51 -42
data/lib/FoxTextFormatter.rb
CHANGED
@@ -1,265 +1,275 @@
|
|
1
1
|
# This class is mostly copy & paste from ri_formatter.rb.
|
2
2
|
# except that it always returns a string and does not print anything.
|
3
3
|
class FoxTextFormatter
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
=begin
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
4
|
+
# define all possible styles
|
5
|
+
STYLE_NORMAL = :STYLE_NORMAL
|
6
|
+
STYLE_BOLD = :STYLE_BOLD
|
7
|
+
STYLE_CLASS = :STYLE_CLASS
|
8
|
+
STYLE_H1 = :STYLE_H1
|
9
|
+
STYLE_H2 = :STYLE_H2
|
10
|
+
STYLE_H3 = :STYLE_H3
|
11
|
+
STYLE_TELETYPE = :STYLE_TELETYPE
|
12
|
+
STYLE_CODE = :STYLE_CODE
|
13
|
+
STYLE_EMPHASIS = :STYLE_EMPHASIS
|
14
|
+
|
15
|
+
attr_reader :indent
|
16
|
+
attr_accessor :width
|
17
|
+
|
18
|
+
# whenever text should be printed/added/shown, proc is called with the text as the argument.
|
19
|
+
def initialize(width, indent, &proc)
|
20
|
+
@width = width
|
21
|
+
@indent = indent
|
22
|
+
@proc = proc
|
23
|
+
end
|
24
|
+
|
25
|
+
######################################################################
|
26
|
+
|
27
|
+
def draw_line(label=nil)
|
28
|
+
len = @width
|
29
|
+
len -= (label.size+1) if label
|
30
|
+
len = [0, len].max
|
31
|
+
@proc.call("-"*len)
|
32
|
+
if label
|
33
|
+
@proc.call(" ")
|
34
|
+
@proc.call(label, STYLE_CLASS)
|
35
|
+
end
|
36
|
+
@proc.call("\n")
|
37
|
+
end
|
38
|
+
|
39
|
+
def display_params(method)
|
40
|
+
params = method.params
|
41
|
+
|
42
|
+
if params[0] == ?(
|
43
|
+
if method.is_singleton
|
44
|
+
params = method.full_name + params
|
45
|
+
else
|
46
|
+
params = method.name + params
|
47
|
+
end
|
48
|
+
end
|
49
|
+
params.split(/\n/).each do |param|
|
50
|
+
@proc.call(param+"\n", STYLE_BOLD)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def wrap(txt, prefix=@indent, linelen=@width)
|
55
|
+
return if !txt || txt.empty?
|
56
|
+
@proc.call(prefix, STYLE_EMPHASIS)
|
57
|
+
conv_markup(txt, prefix, linelen)
|
58
|
+
=begin
|
59
|
+
textLen = linelen - prefix.length
|
60
|
+
patt = Regexp.new("^(.{0,#{textLen}})[ \n]")
|
61
|
+
next_prefix = prefix.tr("^ ", " ")
|
62
|
+
|
63
|
+
res = []
|
64
|
+
|
65
|
+
while work.length > textLen
|
66
|
+
if work =~ patt
|
67
|
+
res << $1
|
68
|
+
work.slice!(0, $&.length)
|
69
|
+
else
|
70
|
+
res << work.slice!(0, textLen)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
res << work if work.length.nonzero?
|
74
|
+
@proc.call(prefix + res.join("\n" + next_prefix) + "\n")
|
75
75
|
=end
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
76
|
+
end
|
77
|
+
|
78
|
+
######################################################################
|
79
|
+
|
80
|
+
def blankline
|
81
|
+
@proc.call("\n")
|
82
|
+
end
|
83
|
+
|
84
|
+
######################################################################
|
85
|
+
|
86
|
+
# called when we want to ensure a nbew 'wrap' starts on a newline
|
87
|
+
# Only needed for HtmlFormatter, because the rest do their
|
88
|
+
# own line breaking
|
89
|
+
|
90
|
+
def break_to_newline
|
91
|
+
end
|
92
|
+
|
93
|
+
######################################################################
|
94
|
+
|
95
|
+
def bold_print(txt)
|
96
|
+
@proc.call(txt, STYLE_BOLD)
|
97
|
+
end
|
98
|
+
|
99
|
+
######################################################################
|
100
|
+
|
101
|
+
def raw_print_line(txt)
|
102
|
+
@proc.call(txt)
|
103
|
+
end
|
104
|
+
|
105
|
+
######################################################################
|
106
|
+
|
107
|
+
# convert HTML entities back to ASCII
|
108
|
+
def conv_html(txt)
|
109
|
+
case txt
|
110
|
+
when Array
|
111
|
+
txt.join.
|
112
|
+
gsub(/>/, '>').
|
113
|
+
gsub(/</, '<').
|
114
|
+
gsub(/"/, '"').
|
115
|
+
gsub(/&/, '&')
|
116
|
+
else # it's a String
|
117
|
+
txt.
|
118
|
+
gsub(/>/, '>').
|
119
|
+
gsub(/</, '<').
|
120
|
+
gsub(/"/, '"').
|
121
|
+
gsub(/&/, '&')
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# convert markup into display form
|
126
|
+
def conv_markup(txt, prefix, linelen)
|
127
|
+
|
128
|
+
# this code assumes that tags are not used inside tags
|
129
|
+
pos = 0
|
130
|
+
old_pos = 0
|
131
|
+
style = STYLE_NORMAL
|
132
|
+
current_indent = prefix.size
|
133
|
+
while pos = txt.index(%r{(<tt>|<code>|<b>|<em>|</tt>|</code>|</b>|</em>)}, old_pos)
|
134
|
+
new_part = txt[old_pos...pos]
|
135
|
+
@proc.call(new_part, style)
|
136
|
+
|
137
|
+
# get tag name
|
138
|
+
old_pos = txt.index(">", pos) + 1
|
139
|
+
style = case txt[(pos+1)...(old_pos-1)]
|
140
|
+
when "tt"
|
141
|
+
STYLE_TELETYPE
|
142
|
+
when "code"
|
143
|
+
STYLE_CODE
|
144
|
+
when "b"
|
145
|
+
STYLE_BOLD
|
146
|
+
when "em"
|
147
|
+
STYLE_EMPHASIS
|
148
|
+
else
|
149
|
+
# closing or unknown tags
|
150
|
+
STYLE_NORMAL
|
151
|
+
end
|
152
|
+
end
|
153
|
+
@proc.call(txt[old_pos...txt.size], style)
|
154
|
+
@proc.call("\n")
|
155
|
+
end
|
156
|
+
|
157
|
+
######################################################################
|
158
|
+
|
159
|
+
def display_list(list)
|
160
|
+
case list.type
|
161
|
+
when SM::ListBase::BULLET
|
162
|
+
prefixer = proc { |ignored| @indent + "* " }
|
163
|
+
|
164
|
+
when SM::ListBase::NUMBER,
|
165
|
+
SM::ListBase::UPPERALPHA,
|
166
|
+
SM::ListBase::LOWERALPHA
|
167
|
+
|
168
|
+
start = case list.type
|
169
|
+
when SM::ListBase::NUMBER then 1
|
170
|
+
when SM::ListBase::UPPERALPHA then 'A'
|
171
|
+
when SM::ListBase::LOWERALPHA then 'a'
|
172
|
+
end
|
173
|
+
prefixer = proc do |ignored|
|
174
|
+
res = @indent + "#{start}.".ljust(4)
|
175
|
+
start = start.succ
|
176
|
+
res
|
177
|
+
end
|
178
|
+
|
179
|
+
when SM::ListBase::LABELED
|
180
|
+
prefixer = proc do |li|
|
181
|
+
li.label
|
182
|
+
end
|
183
|
+
|
184
|
+
when SM::ListBase::NOTE
|
185
|
+
longest = 0
|
186
|
+
list.contents.each do |item|
|
187
|
+
if item.kind_of?(SM::Flow::LI) && item.label.length > longest
|
188
|
+
longest = item.label.length
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
prefixer = proc do |li|
|
193
|
+
@indent + li.label.ljust(longest+1)
|
194
|
+
end
|
195
|
+
|
196
|
+
else
|
197
|
+
fail "unknown list type"
|
198
|
+
end
|
199
|
+
|
200
|
+
list.contents.each do |item|
|
201
|
+
if item.kind_of? SM::Flow::LI
|
202
|
+
prefix = prefixer.call(item)
|
203
|
+
display_flow_item(item, prefix)
|
204
|
+
else
|
205
|
+
display_flow_item(item)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
######################################################################
|
211
|
+
|
212
|
+
def display_flow_item(item, prefix=@indent)
|
213
|
+
|
214
|
+
case item
|
215
|
+
when SM::Flow::P, SM::Flow::LI
|
216
|
+
wrap(conv_html(item.body), prefix)
|
217
|
+
blankline
|
218
|
+
|
219
|
+
when SM::Flow::LIST
|
220
|
+
display_list(item)
|
221
|
+
|
222
|
+
when SM::Flow::VERB
|
223
|
+
display_verbatim_flow_item(item, @indent)
|
224
|
+
|
225
|
+
when SM::Flow::H
|
226
|
+
display_heading(conv_html(item.text), item.level, @indent)
|
227
|
+
|
228
|
+
when SM::Flow::RULE
|
229
|
+
draw_line
|
230
|
+
|
231
|
+
when String
|
232
|
+
wrap(conv_html(item), prefix)
|
233
|
+
|
234
|
+
else
|
235
|
+
fail "Unknown flow element: #{item.class}"
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
######################################################################
|
240
|
+
|
241
|
+
def display_verbatim_flow_item(item, prefix=@indent)
|
242
|
+
item.body.split(/\n/).each do |line|
|
243
|
+
@proc.call(@indent)
|
244
|
+
@proc.call(conv_html(line))
|
245
|
+
@proc.call("\n")
|
246
|
+
end
|
247
|
+
blankline
|
248
|
+
end
|
249
|
+
|
250
|
+
######################################################################
|
251
|
+
|
252
|
+
def display_heading(text, level, indent)
|
253
|
+
case level
|
254
|
+
when 1
|
255
|
+
@proc.call(text, STYLE_H1)
|
256
|
+
@proc.call("\n")
|
257
|
+
|
258
|
+
when 2
|
259
|
+
@proc.call(text, STYLE_H2)
|
260
|
+
@proc.call("\n")
|
261
|
+
|
262
|
+
else
|
263
|
+
@proc.call(indent)
|
264
|
+
@proc.call(text, STYLE_H3)
|
265
|
+
@proc.call("\n")
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
|
270
|
+
def display_flow(flow)
|
271
|
+
flow.each do |f|
|
272
|
+
display_flow_item(f)
|
273
|
+
end
|
274
|
+
end
|
265
275
|
end
|