term_utils 0.3.2 → 0.5.0
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/CHANGELOG.md +16 -2
- data/COPYING +3 -3
- data/README.md +51 -16
- data/Rakefile +6 -0
- data/doc/TermUtils/AP/Article.html +57 -55
- data/doc/TermUtils/AP/ArticleResult.html +584 -0
- data/doc/TermUtils/AP/Flag.html +295 -78
- data/doc/TermUtils/AP/Parameter.html +891 -103
- data/doc/TermUtils/AP/ParameterResult.html +980 -0
- data/doc/TermUtils/{FF/Cursor/Context.html → AP/ParameterWalkerHooks.html} +60 -60
- data/doc/TermUtils/AP/ParseError.html +651 -19
- data/doc/TermUtils/AP/Parser.html +181 -121
- data/doc/TermUtils/AP/Result.html +201 -528
- data/doc/TermUtils/AP/Syntax.html +103 -393
- data/doc/TermUtils/AP/SyntaxError.html +9 -91
- data/doc/TermUtils/AP/Walker.html +686 -0
- data/doc/TermUtils/AP.html +49 -160
- data/doc/TermUtils/FF/Config.html +203 -35
- data/doc/TermUtils/FF/Context.html +585 -0
- data/doc/TermUtils/FF/Entry.html +626 -0
- data/doc/TermUtils/FF/Finder.html +850 -0
- data/doc/TermUtils/FF/{Cursor.html → FinderEntry.html} +473 -211
- data/doc/TermUtils/FF/FinderQuery.html +946 -0
- data/doc/TermUtils/FF/Query.html +402 -70
- data/doc/TermUtils/FF.html +135 -11
- data/doc/TermUtils/PropertyTreeNode.html +304 -190
- data/doc/TermUtils/Tab/Column.html +98 -96
- data/doc/TermUtils/Tab/Header.html +30 -30
- data/doc/TermUtils/Tab/Holder.html +81 -81
- data/doc/TermUtils/Tab/Printer.html +43 -43
- data/doc/TermUtils/Tab/Table.html +124 -128
- data/doc/TermUtils/Tab/TableError.html +7 -89
- data/doc/TermUtils/Tab.html +93 -86
- data/doc/TermUtils.html +10 -10
- data/doc/_index.html +62 -42
- data/doc/class_list.html +3 -3
- data/doc/css/style.css +3 -2
- data/doc/file.README.html +63 -26
- data/doc/file_list.html +2 -2
- data/doc/frames.html +2 -2
- data/doc/index.html +63 -26
- data/doc/js/app.js +14 -3
- data/doc/method_list.html +708 -236
- data/doc/top-level-namespace.html +7 -7
- data/lib/term_utils/ap/article.rb +15 -9
- data/lib/term_utils/ap/flag.rb +37 -20
- data/lib/term_utils/ap/parameter.rb +88 -19
- data/lib/term_utils/ap/parser.rb +143 -116
- data/lib/term_utils/ap/result.rb +208 -161
- data/lib/term_utils/ap/syntax.rb +53 -69
- data/lib/term_utils/ap.rb +79 -24
- data/lib/term_utils/ff/config.rb +22 -10
- data/lib/term_utils/{ap/no_such_value_error.rb → ff/entry.rb} +26 -8
- data/lib/term_utils/ff/finder.rb +255 -0
- data/lib/term_utils/ff/query.rb +94 -17
- data/lib/term_utils/ff.rb +12 -2
- data/lib/term_utils/property_tree_node.rb +47 -19
- data/lib/term_utils/tab.rb +106 -61
- data/lib/term_utils.rb +8 -1
- data/term_utils.gemspec +4 -4
- metadata +18 -17
- data/doc/TermUtils/AP/Element.html +0 -1025
- data/doc/TermUtils/AP/Level.html +0 -638
- data/doc/TermUtils/AP/NoSuchValueError.html +0 -217
- data/lib/term_utils/ap/element.rb +0 -78
- data/lib/term_utils/ap/level.rb +0 -57
- data/lib/term_utils/ap/parse_error.rb +0 -27
- data/lib/term_utils/ap/syntax_error.rb +0 -27
- data/lib/term_utils/ff/cursor.rb +0 -153
data/lib/term_utils/tab.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (C) 2023 Thomas Baron
|
2
4
|
#
|
3
5
|
# This file is part of term_utils.
|
4
6
|
#
|
@@ -13,60 +15,65 @@
|
|
13
15
|
#
|
14
16
|
# You should have received a copy of the GNU General Public License
|
15
17
|
# along with term_utils. If not, see <https://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
require 'stringio'
|
20
|
+
|
16
21
|
module TermUtils
|
17
22
|
# The tab module provides a way to print formatted tables.
|
18
23
|
module Tab
|
19
24
|
# Represents a table error.
|
20
25
|
class TableError < StandardError
|
21
|
-
def initialize(msg)
|
22
|
-
super
|
23
|
-
end
|
24
26
|
end
|
27
|
+
|
25
28
|
# Creates initial column properties.
|
26
29
|
# @return [Hash] `:offset`, `:column_separator_width`.
|
27
30
|
def self.init_table_props
|
28
|
-
{:
|
31
|
+
{ offset: 0, column_separator_width: 2 }
|
29
32
|
end
|
33
|
+
|
30
34
|
# Creates initial column properties.
|
31
35
|
# @return [Hash] `:width`, `:align`, `:fixed`, `:ellipsis`, `:format`.
|
32
36
|
def self.init_column_props
|
33
|
-
{:
|
37
|
+
{ width: 8, align: :left, fixed: false, ellipsis: '?', format: nil }
|
34
38
|
end
|
39
|
+
|
35
40
|
# Assigns table properties.
|
36
41
|
# @param target [Hash]
|
37
42
|
# @param source [Hash] `:offset`, `:column_separator_width`.
|
38
43
|
# @return [Hash]
|
39
44
|
def self.assign_table_props(target, source)
|
40
|
-
if (source.
|
45
|
+
if (source.key? :offset) && (source[:offset].is_a? Integer) && (source[:offset] >= 0)
|
41
46
|
target[:offset] = source[:offset]
|
42
47
|
end
|
43
|
-
if (source.
|
48
|
+
if (source.key? :column_separator_width) && (source[:column_separator_width].is_a? Integer) && source[:column_separator_width].positive?
|
44
49
|
target[:column_separator_width] = source[:column_separator_width]
|
45
50
|
end
|
46
51
|
target
|
47
52
|
end
|
53
|
+
|
48
54
|
# Assigns column properties.
|
49
55
|
# @param target [Hash]
|
50
56
|
# @param source [Hash] `:width`, `:align`, `:fixed`, `:ellipsis`, `:format`.
|
51
57
|
# @return [Hash]
|
52
58
|
def self.assign_column_props(target, source)
|
53
|
-
if (source.
|
59
|
+
if (source.key? :width) && (source[:width].is_a? Integer) && source[:width].positive?
|
54
60
|
target[:width] = source[:width]
|
55
61
|
end
|
56
|
-
if (source.
|
62
|
+
if (source.key? :align) && %i[left right].index(source[:align])
|
57
63
|
target[:align] = source[:align]
|
58
64
|
end
|
59
|
-
if (source.
|
65
|
+
if (source.key? :fixed) && (!!source[:fixed] == source[:fixed])
|
60
66
|
target[:fixed] = source[:fixed]
|
61
67
|
end
|
62
|
-
if (source.
|
68
|
+
if (source.key? :ellipsis) && (source[:ellipsis].is_a? String)
|
63
69
|
target[:ellipsis] = source[:ellipsis]
|
64
70
|
end
|
65
|
-
if (source.
|
71
|
+
if (source.key? :format) && (source[:ellipsis].nil? || (source[:ellipsis].is_a? Proc) || (source[:ellipsis].is_a? String))
|
66
72
|
target[:format] = source[:format]
|
67
73
|
end
|
68
74
|
target
|
69
75
|
end
|
76
|
+
|
70
77
|
# Aligns and cuts a given string.
|
71
78
|
# @param src [String]
|
72
79
|
# @param align [Symbol] `:left`, `:right`.
|
@@ -75,32 +82,31 @@ module TermUtils
|
|
75
82
|
# @param ellipsis [String] The ellipsis when not fixed.
|
76
83
|
# @return [String]
|
77
84
|
def self.align_cut(src, align, fixed, width, ellipsis)
|
78
|
-
res = src
|
79
85
|
if align == :left
|
80
86
|
# Align left
|
81
87
|
if fixed && (src.length > width)
|
82
88
|
if ellipsis.length >= width
|
83
|
-
|
89
|
+
ellipsis[0..(width - 1)]
|
84
90
|
else
|
85
|
-
|
91
|
+
format '%<value>s%<ellipsis>s', value: src[0..(width - (ellipsis.length + 1))], ellipsis: ellipsis
|
86
92
|
end
|
87
93
|
else
|
88
|
-
|
94
|
+
src.ljust(width)
|
89
95
|
end
|
90
96
|
elsif align == :right
|
91
97
|
# Align right
|
92
98
|
if fixed && (src.length > width)
|
93
99
|
if ellipsis.length >= width
|
94
|
-
|
100
|
+
ellipsis[0..(width - 1)]
|
95
101
|
else
|
96
|
-
|
102
|
+
format '%<ellipsis>s%<value>s', ellipsis: ellipsis, value: src[(src.length - width + ellipsis.length)..(src.length - 1)]
|
97
103
|
end
|
98
104
|
else
|
99
|
-
|
105
|
+
src.rjust(width)
|
100
106
|
end
|
101
107
|
end
|
102
|
-
res
|
103
108
|
end
|
109
|
+
|
104
110
|
# Represents a table.
|
105
111
|
class Table
|
106
112
|
# @return [Symbol]
|
@@ -113,6 +119,7 @@ module TermUtils
|
|
113
119
|
attr_accessor :column_defaults
|
114
120
|
# @return [Array<Tab::Column>]
|
115
121
|
attr_accessor :columns
|
122
|
+
|
116
123
|
# @param opts [Hash]
|
117
124
|
# @option opts [Symbol] :id
|
118
125
|
# @option opts [Integer] :offset
|
@@ -122,18 +129,16 @@ module TermUtils
|
|
122
129
|
@id = opts.fetch(:id, nil)
|
123
130
|
@offset = opts.fetch(:offset)
|
124
131
|
@column_separator_width = opts.fetch(:column_separator_width)
|
125
|
-
|
126
|
-
@column_defaults = opts[:column_defaults].dup
|
127
|
-
else
|
128
|
-
@column_defaults = TermUtils::Tab.default_column_props
|
129
|
-
end
|
132
|
+
@column_defaults = opts.key?(:column_defaults) ? opts[:column_defaults].dup : TermUtils::Tab.default_column_props
|
130
133
|
@columns = []
|
131
134
|
end
|
135
|
+
|
132
136
|
# Returns the properties of this one.
|
133
137
|
# @return [Hash]
|
134
138
|
def props
|
135
|
-
{:
|
139
|
+
{ offset: @offset, column_separator_width: @column_separator_width }
|
136
140
|
end
|
141
|
+
|
137
142
|
# Sets column default properties.
|
138
143
|
# @param opts [Hash]
|
139
144
|
# @option opts [Integer] :width
|
@@ -144,6 +149,7 @@ module TermUtils
|
|
144
149
|
def set_column_defaults(opts = {})
|
145
150
|
TermUtils::Tab.assign_column_props(@column_defaults, opts)
|
146
151
|
end
|
152
|
+
|
147
153
|
# Defines a column.
|
148
154
|
# @param id [Symbol]
|
149
155
|
# @param opts [Hash]
|
@@ -156,24 +162,26 @@ module TermUtils
|
|
156
162
|
def define_column(id, opts = {}, &block)
|
157
163
|
col = @columns.find { |c| c.id == id }
|
158
164
|
if col
|
159
|
-
block
|
165
|
+
block&.call(col)
|
160
166
|
col.validate
|
161
167
|
else
|
162
168
|
opts[:id] = id
|
163
169
|
opts[:index] = @columns.length
|
164
170
|
col = Column.new(@column_defaults.merge(opts))
|
165
|
-
block
|
171
|
+
block&.call(col)
|
166
172
|
col.validate
|
167
173
|
@columns << col
|
168
174
|
end
|
169
175
|
col
|
170
176
|
end
|
177
|
+
|
171
178
|
# Finds a column.
|
172
179
|
# @param id [Symbol]
|
173
180
|
# @return [Tab::Column, nil]
|
174
181
|
def find_column(id)
|
175
182
|
@columns.find { |c| c.id == id }
|
176
183
|
end
|
184
|
+
|
177
185
|
# Creates a new table printer.
|
178
186
|
# @param io [#puts]
|
179
187
|
# @param opts [Hash]
|
@@ -182,9 +190,10 @@ module TermUtils
|
|
182
190
|
# @return [Tab::Printer]
|
183
191
|
def printer(io, opts = {}, &block)
|
184
192
|
ptr = Printer.new(self, io, props.merge(opts))
|
185
|
-
block
|
193
|
+
block&.call(ptr)
|
186
194
|
ptr
|
187
195
|
end
|
196
|
+
|
188
197
|
# Prints a header row.
|
189
198
|
# @param io [#puts]
|
190
199
|
# @param values [Array<Object>, Hash<Symbol, Object>]
|
@@ -203,17 +212,19 @@ module TermUtils
|
|
203
212
|
vals << values[col.id]
|
204
213
|
end
|
205
214
|
end
|
206
|
-
raise TermUtils::Tab::TableError,
|
215
|
+
raise TermUtils::Tab::TableError, 'wrong values (not array)' unless vals.is_a? Array
|
216
|
+
|
207
217
|
offset = opts.fetch(:offset)
|
208
218
|
column_separator_width = opts.fetch(:column_separator_width)
|
209
219
|
sb = StringIO.new
|
210
|
-
sb <<
|
220
|
+
sb << (' ' * offset) if offset.positive?
|
211
221
|
@columns.each do |col|
|
212
|
-
sb <<
|
222
|
+
sb << (' ' * column_separator_width) if col.index.positive?
|
213
223
|
sb << col.render_header(vals[col.index])
|
214
224
|
end
|
215
225
|
io.puts sb.string
|
216
226
|
end
|
227
|
+
|
217
228
|
# Prints a data row.
|
218
229
|
# @param io [#puts]
|
219
230
|
# @param values [Array<Object>, Hash<Symbol, Object>]
|
@@ -230,17 +241,19 @@ module TermUtils
|
|
230
241
|
vals << values[col.id]
|
231
242
|
end
|
232
243
|
end
|
233
|
-
raise TermUtils::Tab::TableError,
|
244
|
+
raise TermUtils::Tab::TableError, 'wrong values (not array)' unless vals.is_a? Array
|
245
|
+
|
234
246
|
offset = opts.fetch(:offset)
|
235
247
|
column_separator_width = opts.fetch(:column_separator_width)
|
236
248
|
sb = StringIO.new
|
237
|
-
sb <<
|
249
|
+
sb << (' ' * offset) if offset.positive?
|
238
250
|
@columns.each do |col|
|
239
|
-
sb <<
|
251
|
+
sb << (' ' * column_separator_width) if col.index.positive?
|
240
252
|
sb << col.render_data(vals[col.index])
|
241
253
|
end
|
242
254
|
io.puts sb.string
|
243
255
|
end
|
256
|
+
|
244
257
|
# Prints a separator row.
|
245
258
|
# @param io [#puts]
|
246
259
|
# @param opts [Hash]
|
@@ -251,13 +264,14 @@ module TermUtils
|
|
251
264
|
offset = opts.fetch(:offset)
|
252
265
|
column_separator_width = opts.fetch(:column_separator_width)
|
253
266
|
sb = StringIO.new
|
254
|
-
sb <<
|
267
|
+
sb << (' ' * offset) if offset.positive?
|
255
268
|
@columns.each do |col|
|
256
|
-
sb <<
|
257
|
-
sb <<
|
269
|
+
sb << (' ' * column_separator_width) if col.index.positive?
|
270
|
+
sb << ('-' * col.width)
|
258
271
|
end
|
259
272
|
io.puts sb.string
|
260
273
|
end
|
274
|
+
|
261
275
|
# Returns column titles.
|
262
276
|
# @return [Hash<Symbol, String>]
|
263
277
|
def titles
|
@@ -268,6 +282,7 @@ module TermUtils
|
|
268
282
|
h
|
269
283
|
end
|
270
284
|
end
|
285
|
+
|
271
286
|
# Represents a table column.
|
272
287
|
class Column
|
273
288
|
# @return [Symbol]
|
@@ -286,6 +301,7 @@ module TermUtils
|
|
286
301
|
attr_accessor :format
|
287
302
|
# @return [TermUtils::Tab::Header]
|
288
303
|
attr_accessor :header
|
304
|
+
|
289
305
|
# @param opts [Hash]
|
290
306
|
# @option opts [Symbol] :id
|
291
307
|
# @option opts [Integer] :index
|
@@ -300,31 +316,35 @@ module TermUtils
|
|
300
316
|
@width = opts.fetch(:width, 8)
|
301
317
|
@align = opts.fetch(:align, :left)
|
302
318
|
@fixed = opts.fetch(:fixed, false)
|
303
|
-
@ellipsis = opts.fetch(:ellipsis,
|
319
|
+
@ellipsis = opts.fetch(:ellipsis, '?')
|
304
320
|
@format = opts.fetch(:format, nil)
|
305
|
-
@header = TermUtils::Tab::Header.new(:
|
321
|
+
@header = TermUtils::Tab::Header.new(title: @id.to_s, align: @align)
|
306
322
|
end
|
323
|
+
|
307
324
|
# Validates the column represented by this one.
|
308
325
|
# @return [nil]
|
309
326
|
# @raise [TermUtils::Tab::TableError]
|
310
327
|
def validate
|
311
|
-
raise TermUtils::Tab::TableError,
|
312
|
-
raise TermUtils::Tab::TableError,
|
313
|
-
raise TermUtils::Tab::TableError,
|
314
|
-
raise TermUtils::Tab::TableError,
|
315
|
-
raise TermUtils::Tab::TableError,
|
316
|
-
raise TermUtils::Tab::TableError,
|
317
|
-
raise TermUtils::Tab::TableError,
|
318
|
-
raise TermUtils::Tab::TableError,
|
328
|
+
raise TermUtils::Tab::TableError, 'missing column id (nil)' if @id.nil?
|
329
|
+
raise TermUtils::Tab::TableError, 'missing column index (nil)' if @index.nil?
|
330
|
+
raise TermUtils::Tab::TableError, 'wrong column index (not integer)' unless @index.is_a? Integer
|
331
|
+
raise TermUtils::Tab::TableError, 'wrong column index (not >= 0)' if @index.negative?
|
332
|
+
raise TermUtils::Tab::TableError, 'missing column width (nil)' if @width.nil?
|
333
|
+
raise TermUtils::Tab::TableError, 'wrong column width (not integer)' unless @width.is_a? Integer
|
334
|
+
raise TermUtils::Tab::TableError, 'wrong column width (not > 0)' if @width <= 0
|
335
|
+
raise TermUtils::Tab::TableError, 'wrong column align (not :left or :right)' unless %i[left right].index(@align)
|
336
|
+
|
319
337
|
@header.validate
|
320
338
|
end
|
339
|
+
|
321
340
|
# Renders a given header.
|
322
341
|
# @param val [Object]
|
323
342
|
# return [String]
|
324
343
|
def render_header(val)
|
325
|
-
src =
|
344
|
+
src = val.is_a?(String) ? val : val.to_s
|
326
345
|
TermUtils::Tab.align_cut(src, @header.align, @fixed, @width, @ellipsis)
|
327
346
|
end
|
347
|
+
|
328
348
|
# Renders a given value.
|
329
349
|
# @param val [Object]
|
330
350
|
# return [String]
|
@@ -337,16 +357,18 @@ module TermUtils
|
|
337
357
|
src = @format % val
|
338
358
|
end
|
339
359
|
end
|
340
|
-
src =
|
360
|
+
src = src.to_s unless src.is_a?(String)
|
341
361
|
TermUtils::Tab.align_cut(src, @align, @fixed, @width, @ellipsis)
|
342
362
|
end
|
343
363
|
end
|
364
|
+
|
344
365
|
# Represents a column header.
|
345
366
|
class Header
|
346
367
|
# @return [String]
|
347
368
|
attr_accessor :title
|
348
369
|
# @return [Symbol] `:left`, `:right`.
|
349
370
|
attr_accessor :align
|
371
|
+
|
350
372
|
# Constructs a new Header.
|
351
373
|
# @param opts [Hash]
|
352
374
|
# @option opts [String] :title
|
@@ -355,14 +377,16 @@ module TermUtils
|
|
355
377
|
@title = opts.fetch(:title)
|
356
378
|
@align = opts.fetch(:align, :left)
|
357
379
|
end
|
380
|
+
|
358
381
|
# Validates the column represented by this one.
|
359
382
|
# @return [nil]
|
360
383
|
# @raise [TermUtils::Tab::TableError]
|
361
384
|
def validate
|
362
|
-
raise TermUtils::Tab::TableError,
|
363
|
-
raise TermUtils::Tab::TableError,
|
385
|
+
raise TermUtils::Tab::TableError, 'missing header title (nil)' if @title.nil?
|
386
|
+
raise TermUtils::Tab::TableError, 'wrong header align (not :left or :right)' unless %i[left right].index(@align)
|
364
387
|
end
|
365
388
|
end
|
389
|
+
|
366
390
|
# Represents a table printer.
|
367
391
|
class Printer
|
368
392
|
# @return [Tab::Table]
|
@@ -371,6 +395,7 @@ module TermUtils
|
|
371
395
|
attr_accessor :io
|
372
396
|
# @return [Hash]
|
373
397
|
attr_accessor :options
|
398
|
+
|
374
399
|
# @param table [Tab::Table]
|
375
400
|
# @param io [IO]
|
376
401
|
# @param options [Hash]
|
@@ -379,10 +404,12 @@ module TermUtils
|
|
379
404
|
@io = io
|
380
405
|
@options = options
|
381
406
|
end
|
407
|
+
|
382
408
|
# Prints an empty line.
|
383
409
|
def line
|
384
|
-
@io.puts
|
410
|
+
@io.puts
|
385
411
|
end
|
412
|
+
|
386
413
|
# Prints a header row.
|
387
414
|
# @param values [Array<Object>, Hash<Symbol, Object>]
|
388
415
|
# @param opts [Hash]
|
@@ -392,6 +419,7 @@ module TermUtils
|
|
392
419
|
def header(values = nil, opts = nil)
|
393
420
|
@table.print_header(@io, values, opts ? @options.merge(opts) : @options)
|
394
421
|
end
|
422
|
+
|
395
423
|
# Prints a data row.
|
396
424
|
# @param values [Array<Object>, Hash<Symbol, Object>]
|
397
425
|
# @param opts [Hash]
|
@@ -401,6 +429,7 @@ module TermUtils
|
|
401
429
|
def data(values, opts = nil)
|
402
430
|
@table.print_data(@io, values, opts ? @options.merge(opts) : @options)
|
403
431
|
end
|
432
|
+
|
404
433
|
# Prints a separator.
|
405
434
|
# @param opts [Hash]
|
406
435
|
# @option opts [Integer] :offset
|
@@ -410,7 +439,8 @@ module TermUtils
|
|
410
439
|
@table.print_separator(@io, opts ? @options.merge(opts) : @options)
|
411
440
|
end
|
412
441
|
end
|
413
|
-
|
442
|
+
|
443
|
+
# Represents a Holder of Table(s).
|
414
444
|
class Holder
|
415
445
|
# @return [Hash] `:offset`, `:column_separator_width`.
|
416
446
|
attr_accessor :table_defaults
|
@@ -418,11 +448,14 @@ module TermUtils
|
|
418
448
|
attr_accessor :column_defaults
|
419
449
|
# @return [Hash<Symbol, Tab::Table>]
|
420
450
|
attr_accessor :tables
|
421
|
-
|
451
|
+
|
452
|
+
# Creates a new Holder.
|
453
|
+
def initialize
|
422
454
|
@table_defaults = TermUtils::Tab.init_table_props
|
423
455
|
@column_defaults = TermUtils::Tab.init_column_props
|
424
456
|
@tables = {}
|
425
457
|
end
|
458
|
+
|
426
459
|
# Sets table default properties.
|
427
460
|
# @param opts [Hash]
|
428
461
|
# @option opts [Integer] :offset
|
@@ -430,6 +463,7 @@ module TermUtils
|
|
430
463
|
def set_table_defaults(opts = {})
|
431
464
|
TermUtils::Tab.assign_table_props(@table_defaults, opts)
|
432
465
|
end
|
466
|
+
|
433
467
|
# Sets column default properties.
|
434
468
|
# @param opts [Hash]
|
435
469
|
# @option opts [Integer] :width
|
@@ -440,6 +474,7 @@ module TermUtils
|
|
440
474
|
def set_column_defaults(opts = {})
|
441
475
|
TermUtils::Tab.assign_column_props(@column_defaults, opts)
|
442
476
|
end
|
477
|
+
|
443
478
|
# Creates a new table, using default properties, without registering it.
|
444
479
|
# @param opts [Hash]
|
445
480
|
# @return [Tab::Table]
|
@@ -448,33 +483,36 @@ module TermUtils
|
|
448
483
|
opts[:column_separator_width] = @table_defaults.fetch(:column_separator_width)
|
449
484
|
opts[:column_defaults] = @column_defaults.dup
|
450
485
|
new_tab = Table.new(opts)
|
451
|
-
block
|
486
|
+
block&.call(new_tab)
|
452
487
|
new_tab
|
453
488
|
end
|
489
|
+
|
454
490
|
# Defines a table, using default properties.
|
455
491
|
# @param id [Symbol]
|
456
492
|
# @param opts [Hash]
|
457
493
|
# @return [Tab::Table]
|
458
494
|
def define_table(id, opts = {}, &block)
|
459
|
-
if @tables.
|
460
|
-
block
|
495
|
+
if @tables.key? id
|
496
|
+
block&.call(@tables[id])
|
461
497
|
else
|
462
498
|
opts[:id] = id
|
463
499
|
opts[:offset] = @table_defaults.fetch(:offset)
|
464
500
|
opts[:column_separator_width] = @table_defaults.fetch(:column_separator_width)
|
465
501
|
opts[:column_defaults] = @column_defaults.dup
|
466
502
|
new_tab = Table.new(opts)
|
467
|
-
block
|
503
|
+
block&.call(new_tab)
|
468
504
|
@tables[id] = new_tab
|
469
505
|
end
|
470
506
|
@tables[id]
|
471
507
|
end
|
508
|
+
|
472
509
|
# Finds a table.
|
473
510
|
# @param id [Symbol]
|
474
511
|
# @return [Tab::Table, nil]
|
475
512
|
def find_table(id)
|
476
513
|
@tables[id]
|
477
514
|
end
|
515
|
+
|
478
516
|
# Creates a new table printer.
|
479
517
|
# @param id [Symbol]
|
480
518
|
# @param io [IO]
|
@@ -486,7 +524,9 @@ module TermUtils
|
|
486
524
|
find_table(id).printer(io, opts, &block)
|
487
525
|
end
|
488
526
|
end
|
489
|
-
|
527
|
+
|
528
|
+
@@default_holder = Holder.new # rubocop:disable Style/ClassVars
|
529
|
+
|
490
530
|
# Sets table default properties.
|
491
531
|
# @param opts [Hash]
|
492
532
|
# @option opts [Integer] :offset
|
@@ -494,6 +534,7 @@ module TermUtils
|
|
494
534
|
def self.set_table_defaults(opts = {})
|
495
535
|
@@default_holder.set_table_defaults(opts)
|
496
536
|
end
|
537
|
+
|
497
538
|
# Sets column default properties.
|
498
539
|
# @param opts [Hash]
|
499
540
|
# @option opts [Integer] :width
|
@@ -504,12 +545,14 @@ module TermUtils
|
|
504
545
|
def self.set_column_defaults(opts = {})
|
505
546
|
@@default_holder.set_column_defaults(opts)
|
506
547
|
end
|
548
|
+
|
507
549
|
# Creates a new Table, using default properties, without registering it.
|
508
550
|
# @param opts [Hash]
|
509
551
|
# @return [Tab::Table]
|
510
552
|
def self.create_table(opts = {}, &block)
|
511
553
|
@@default_holder.create_table(opts, &block)
|
512
554
|
end
|
555
|
+
|
513
556
|
# Defines a new Table, using default properties, and registers it.
|
514
557
|
# @param id [Symbol]
|
515
558
|
# @param opts [Hash]
|
@@ -517,12 +560,14 @@ module TermUtils
|
|
517
560
|
def self.define_table(id, opts = {}, &block)
|
518
561
|
@@default_holder.define_table(id, opts, &block)
|
519
562
|
end
|
563
|
+
|
520
564
|
# Finds a registered table.
|
521
565
|
# @param id [Symbol]
|
522
566
|
# @return [Tab::Table, nil]
|
523
567
|
def self.find_table(id)
|
524
568
|
@@default_holder.find_table(id)
|
525
569
|
end
|
570
|
+
|
526
571
|
# Creates a new Printer for a registered Table.
|
527
572
|
# @param id [Symbol]
|
528
573
|
# @param io [IO]
|
data/lib/term_utils.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (C) 2023 Thomas Baron
|
2
4
|
#
|
3
5
|
# This file is part of term_utils.
|
4
6
|
#
|
@@ -13,6 +15,11 @@
|
|
13
15
|
#
|
14
16
|
# You should have received a copy of the GNU General Public License
|
15
17
|
# along with term_utils. If not, see <https://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
# Utilities for terminal application.
|
20
|
+
module TermUtils
|
21
|
+
end
|
22
|
+
|
16
23
|
require 'term_utils/ap'
|
17
24
|
require 'term_utils/ff'
|
18
25
|
require 'term_utils/tab'
|
data/term_utils.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "term_utils"
|
3
|
-
s.version = "0.
|
4
|
-
s.date = "
|
5
|
-
s.summary = "
|
3
|
+
s.version = "0.5.0"
|
4
|
+
s.date = "2023-08-09"
|
5
|
+
s.summary = "Utilities for terminal application."
|
6
6
|
s.description = <<-EOS
|
7
|
-
|
7
|
+
Utilities for terminal application like argument parsing, table formatting and file finding.
|
8
8
|
EOS
|
9
9
|
s.authors = ["Thomas Baron"]
|
10
10
|
s.email = "tvbaron at gmail dot com"
|
metadata
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: term_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Baron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: '
|
13
|
+
description: 'Utilities for terminal application like argument parsing, table formatting
|
14
|
+
and file finding.
|
14
15
|
|
15
|
-
'
|
16
|
+
'
|
16
17
|
email: tvbaron at gmail dot com
|
17
18
|
executables: []
|
18
19
|
extensions: []
|
@@ -26,20 +27,24 @@ files:
|
|
26
27
|
- doc/TermUtils.html
|
27
28
|
- doc/TermUtils/AP.html
|
28
29
|
- doc/TermUtils/AP/Article.html
|
29
|
-
- doc/TermUtils/AP/
|
30
|
+
- doc/TermUtils/AP/ArticleResult.html
|
30
31
|
- doc/TermUtils/AP/Flag.html
|
31
|
-
- doc/TermUtils/AP/Level.html
|
32
|
-
- doc/TermUtils/AP/NoSuchValueError.html
|
33
32
|
- doc/TermUtils/AP/Parameter.html
|
33
|
+
- doc/TermUtils/AP/ParameterResult.html
|
34
|
+
- doc/TermUtils/AP/ParameterWalkerHooks.html
|
34
35
|
- doc/TermUtils/AP/ParseError.html
|
35
36
|
- doc/TermUtils/AP/Parser.html
|
36
37
|
- doc/TermUtils/AP/Result.html
|
37
38
|
- doc/TermUtils/AP/Syntax.html
|
38
39
|
- doc/TermUtils/AP/SyntaxError.html
|
40
|
+
- doc/TermUtils/AP/Walker.html
|
39
41
|
- doc/TermUtils/FF.html
|
40
42
|
- doc/TermUtils/FF/Config.html
|
41
|
-
- doc/TermUtils/FF/
|
42
|
-
- doc/TermUtils/FF/
|
43
|
+
- doc/TermUtils/FF/Context.html
|
44
|
+
- doc/TermUtils/FF/Entry.html
|
45
|
+
- doc/TermUtils/FF/Finder.html
|
46
|
+
- doc/TermUtils/FF/FinderEntry.html
|
47
|
+
- doc/TermUtils/FF/FinderQuery.html
|
43
48
|
- doc/TermUtils/FF/Query.html
|
44
49
|
- doc/TermUtils/PropertyTreeNode.html
|
45
50
|
- doc/TermUtils/Tab.html
|
@@ -66,19 +71,15 @@ files:
|
|
66
71
|
- lib/term_utils.rb
|
67
72
|
- lib/term_utils/ap.rb
|
68
73
|
- lib/term_utils/ap/article.rb
|
69
|
-
- lib/term_utils/ap/element.rb
|
70
74
|
- lib/term_utils/ap/flag.rb
|
71
|
-
- lib/term_utils/ap/level.rb
|
72
|
-
- lib/term_utils/ap/no_such_value_error.rb
|
73
75
|
- lib/term_utils/ap/parameter.rb
|
74
|
-
- lib/term_utils/ap/parse_error.rb
|
75
76
|
- lib/term_utils/ap/parser.rb
|
76
77
|
- lib/term_utils/ap/result.rb
|
77
78
|
- lib/term_utils/ap/syntax.rb
|
78
|
-
- lib/term_utils/ap/syntax_error.rb
|
79
79
|
- lib/term_utils/ff.rb
|
80
80
|
- lib/term_utils/ff/config.rb
|
81
|
-
- lib/term_utils/ff/
|
81
|
+
- lib/term_utils/ff/entry.rb
|
82
|
+
- lib/term_utils/ff/finder.rb
|
82
83
|
- lib/term_utils/ff/query.rb
|
83
84
|
- lib/term_utils/property_tree_node.rb
|
84
85
|
- lib/term_utils/tab.rb
|
@@ -103,8 +104,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
104
|
- !ruby/object:Gem::Version
|
104
105
|
version: '0'
|
105
106
|
requirements: []
|
106
|
-
rubygems_version: 3.
|
107
|
+
rubygems_version: 3.4.18
|
107
108
|
signing_key:
|
108
109
|
specification_version: 4
|
109
|
-
summary:
|
110
|
+
summary: Utilities for terminal application.
|
110
111
|
test_files: []
|