62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/imsg-grep/utils/strop_utils.rb', line 62
def report_usage(chars = nil)
x = true
r = ->s{ Rainbow(s) }
chars = chars&.chars || (?0..?z).to_a.grep(/[^\W_]/)
chars = chars.sort_by{|c| [c =~ /\d/ || -1, c.downcase, c =~ /[[:upper:]]/ || 1] }
chars = chars.map{|c| [c] << r[c].then{ self[c]&.label ? it.black.bright : it.green.bright }}
longs = chars.map{|c, cc| l = self[c]&.label; [r["-"].black.bright, cc, r[(" --#{l}" if l)].blue].join }
longs = longs.map{ it.sub((x=!x) ? /^/ : / --/, ' \0') }
w = longs.map(&:size).max + 4
pc = [16, chars.length].min
ll = longs.length
longs.fill("", ll...((ll + pc - 1) / pc * pc))
puts chars.map(&:last).join(" ")
puts
puts longs.map{ "%-#{w}s" % it }.each_slice(pc).to_a.transpose.map(&:join).join("\n")
end
|