ix-cli 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ix-hls +11 -7
- data/bin/ix-noansi +9 -0
- data/bin/ix-percentage +90 -21
- data/bin/ix-timestamp2 +4 -6
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f57209fb53af43f7c975fd7fcd07103da106c5b1fd949563e5191222cf97551e
|
4
|
+
data.tar.gz: da7d25d3ded1343aa1fa471444339fac6e0b771d3ed1c22f72897b42447ac73d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3c890c30d399afbfab1eff7bd7efab3fbd40bae76ec1916c1e46e3f71ce33e10966783ec737d6128e7b9b5ca87edb7446b480734c8e4e7a6064cbe047d5a599
|
7
|
+
data.tar.gz: ed18e8551d241ee7af03d78a1186e34f67d7ca21d1bcca445ba95e3b94a2d6f21ea0f602ed4f9d8b2673384f3017b12f2c5562cf0949cac575cddab19baf5ca9
|
data/bin/ix-hls
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
#
|
4
|
+
# options
|
5
|
+
#
|
6
|
+
# line ix-highlight-line highlight a specific line
|
7
|
+
# vertical ix-highlight-vertical highlight a particular column
|
8
|
+
# highlight ix-highlight-match highlight whatever matches a regex
|
9
|
+
#
|
10
|
+
|
5
11
|
|
6
12
|
abort 'No pattern given' if ARGV[0].nil?
|
7
13
|
|
8
14
|
trap('SIGINT') { }
|
9
15
|
|
16
|
+
$stdout.sync = true
|
17
|
+
|
10
18
|
STDIN.each_line do |line|
|
11
|
-
ARGV
|
12
|
-
matcher, color = setting.split(':')
|
13
|
-
line.gsub!(/(#{matcher})/i) { |x| "#{$1}".to_ansi.send(:"#{color}").to_s }
|
14
|
-
end
|
15
|
-
puts line
|
19
|
+
puts line.gsub(/(#{ARGV[0]})/i) { |x| "[0;31;1m#{$1}[0m" }
|
16
20
|
end
|
17
21
|
|
data/bin/ix-noansi
ADDED
data/bin/ix-percentage
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
|
+
require 'isna'
|
5
|
+
|
4
6
|
# Percentage bar.
|
5
7
|
#
|
6
8
|
# items = (1..100).to_a
|
@@ -14,7 +16,7 @@
|
|
14
16
|
class Percentage
|
15
17
|
def initialize(product, divisor, scale = 100)
|
16
18
|
@product = product
|
17
|
-
@scale = scale
|
19
|
+
@scale = scale
|
18
20
|
@pre_percentage = (divisor * @scale / product).to_f
|
19
21
|
@percentage = (@pre_percentage * 100 / @scale)
|
20
22
|
@divisor = divisor
|
@@ -29,25 +31,28 @@ class Percentage
|
|
29
31
|
# 0 ~ 50 green
|
30
32
|
# 50 ~ 80 yellow
|
31
33
|
# 80 ~ 100 red
|
32
|
-
def to_bar(color = true, bar = '|')
|
33
|
-
|
34
|
-
padding = 0
|
34
|
+
def to_bar(color = true, bar = '|', label = '')
|
35
|
+
bars = (bar * @pre_percentage.to_f).rjust(@scale, ' ')
|
35
36
|
if color
|
36
|
-
if to_i
|
37
|
-
|
38
|
-
end
|
39
|
-
if to_i >= 50 and to_i < 80
|
40
|
-
filling = "[0;33;1m" + (bar * @pre_percentage.to_f) + "[0m"
|
37
|
+
if to_i < 33
|
38
|
+
bars = bars.to_ansi.green.to_s
|
41
39
|
end
|
42
|
-
if to_i >=
|
43
|
-
|
40
|
+
if to_i >= 33 and to_i < 66
|
41
|
+
bars = bars.to_ansi.yellow.to_s
|
44
42
|
end
|
45
|
-
if
|
46
|
-
|
43
|
+
if to_i >= 66
|
44
|
+
bars = bars.to_ansi.red.to_s
|
47
45
|
end
|
48
46
|
end
|
49
|
-
bindings =
|
50
|
-
|
47
|
+
bindings = {
|
48
|
+
:open => '[',
|
49
|
+
:close => ']',
|
50
|
+
:bars => bars,
|
51
|
+
:percentage => (to_f.round(2).to_s.rjust(5, ' ') + '%').to_ansi.pink.to_s,
|
52
|
+
:divisor => @divisor.round(2).to_s.rjust(10, ' ').to_ansi.cyan.to_s,
|
53
|
+
:label => label
|
54
|
+
}
|
55
|
+
format("%<open>s%<bars>s%<close>s %<percentage>s %<divisor>s %<label>s", bindings)
|
51
56
|
end
|
52
57
|
end
|
53
58
|
|
@@ -76,13 +81,75 @@ class Array
|
|
76
81
|
|
77
82
|
end
|
78
83
|
|
84
|
+
require 'optparse'
|
85
|
+
require 'json'
|
86
|
+
|
87
|
+
options = {}
|
88
|
+
options[:width] = 40
|
89
|
+
options[:label] = ''
|
90
|
+
options[:char] = '|'
|
91
|
+
options[:color] = 'yes'
|
92
|
+
|
93
|
+
OptionParser.new do |opts|
|
94
|
+
|
95
|
+
opts.banner = "Usage: #{$0} [OPTIONS]"
|
96
|
+
|
97
|
+
opts.on('-c', '--char [STRING]', 'Char to use to print the percentage bar') do |value|
|
98
|
+
options[:char] = value
|
99
|
+
end
|
100
|
+
|
101
|
+
opts.on('-w', '--width [NUMBER]', 'Chars to use to print the bar.') do |value|
|
102
|
+
options[:width] = value.to_f
|
103
|
+
end
|
104
|
+
|
105
|
+
opts.on('-l', '--label [STRING]', 'Label to use when printing out the layout.') do |value|
|
106
|
+
options[:label] = value
|
107
|
+
end
|
108
|
+
|
109
|
+
opts.on('-o', '--color [yes|no]', 'Weather if we should use ansi colors to print colors') do |value|
|
110
|
+
options[:color] = value
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
opts.on('-j', '--json', 'Will parse json keys as var names, and values as numbers') do |value|
|
115
|
+
options[:json] = value
|
116
|
+
end
|
117
|
+
|
118
|
+
end.parse!
|
119
|
+
|
120
|
+
required_options = [:width, :label, :char, :color]
|
121
|
+
required_options.each do |option|
|
122
|
+
unless options[option]
|
123
|
+
$stderr.puts "Can not run #{option.to_s} was not given."
|
124
|
+
exit 1
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
if options[:color] == 'yes'
|
129
|
+
options[:color] = true
|
130
|
+
else
|
131
|
+
options[:color] = false
|
132
|
+
end
|
133
|
+
|
134
|
+
if options[:width] < 1
|
135
|
+
$stderr.puts "Width can not be less than 1."
|
136
|
+
exit 1
|
137
|
+
end
|
79
138
|
|
80
139
|
hash = {}
|
81
140
|
|
82
141
|
STDIN.each_line do |line|
|
83
|
-
|
84
|
-
|
85
|
-
|
142
|
+
if options[:json]
|
143
|
+
line = JSON.parse(line)
|
144
|
+
line.each do |key, value|
|
145
|
+
hash[key] ||= []
|
146
|
+
hash[key] << value.to_f
|
147
|
+
end
|
148
|
+
else
|
149
|
+
chunks = line.split(/\s+/)
|
150
|
+
hash[chunks[0]] ||= []
|
151
|
+
hash[chunks[0]] << chunks[1].to_f
|
152
|
+
end
|
86
153
|
end
|
87
154
|
|
88
155
|
total = 0
|
@@ -91,12 +158,14 @@ hash.keys.each do |key|
|
|
91
158
|
total += array.product
|
92
159
|
end
|
93
160
|
|
94
|
-
hash.keys.
|
161
|
+
hash.keys.sort do |a, b|
|
162
|
+
hash[a].product <=> hash[b].product
|
163
|
+
end.reverse.each do |key|
|
95
164
|
array = hash[key]
|
96
|
-
p = Percentage.new(total, array.product,
|
165
|
+
p = Percentage.new(total, array.product, options[:width])
|
97
166
|
|
98
167
|
template = "%s %s"
|
99
|
-
bindings = [p.to_bar, key]
|
168
|
+
bindings = [p.to_bar(options[:color], options[:char], options[:label]), key.to_ansi.yellow.to_s]
|
100
169
|
puts template % bindings
|
101
170
|
end
|
102
171
|
|
data/bin/ix-timestamp2
CHANGED
@@ -19,16 +19,14 @@ STDIN.each_line do |line|
|
|
19
19
|
end
|
20
20
|
|
21
21
|
object = {
|
22
|
-
:timestamp => timestamp.to_s.rjust(20, ' '),
|
23
22
|
:time => Time.at(timestamp).to_s.rjust(20, ' '),
|
24
|
-
:elapsed => format('%1.
|
25
|
-
:diff => format('%2.
|
23
|
+
:elapsed => format('%1.3f', (timestamp - start)).to_s.rjust(9, ' '),
|
24
|
+
:diff => format('%2.3f', (timestamp - prev)).to_s.rjust(9, ' '),
|
26
25
|
:lineno => (('| ') + (lineno.to_s)).ljust(5, ' '),
|
27
26
|
:message => json['message']
|
28
27
|
}
|
29
28
|
|
30
29
|
if colors
|
31
|
-
object[:timestamp] = object[:timestamp].to_s.to_ansi.yellow.to_s
|
32
30
|
object[:time] = object[:time].to_s.to_ansi.cyan.to_s
|
33
31
|
object[:elapsed] = object[:elapsed].to_s.to_ansi.pink.to_s
|
34
32
|
|
@@ -47,10 +45,10 @@ STDIN.each_line do |line|
|
|
47
45
|
object[:lineno] = object[:lineno].to_s.to_ansi.cyan.to_s
|
48
46
|
end
|
49
47
|
|
50
|
-
puts format("%<
|
48
|
+
puts format("%<time>s %<elapsed>s %<diff>s %<lineno>s %<message>s", object)
|
51
49
|
prev = timestamp
|
52
50
|
rescue => e
|
53
|
-
|
51
|
+
# puts e.message
|
54
52
|
end
|
55
53
|
end
|
56
54
|
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ix-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuyoshi Tlacaelel
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2020-02-05 00:00:00.000000000 Z
|
@@ -24,8 +24,8 @@ dependencies:
|
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.0.4
|
27
|
-
description:
|
28
|
-
email:
|
27
|
+
description:
|
28
|
+
email:
|
29
29
|
executables:
|
30
30
|
- ix
|
31
31
|
- ix-acronym
|
@@ -182,6 +182,7 @@ executables:
|
|
182
182
|
- ix-ncsa-date-to-timestamp
|
183
183
|
- ix-nested-list
|
184
184
|
- ix-nnjj
|
185
|
+
- ix-noansi
|
185
186
|
- ix-noeol
|
186
187
|
- ix-noise
|
187
188
|
- ix-normalize
|
@@ -463,6 +464,7 @@ files:
|
|
463
464
|
- bin/ix-ncsa-date-to-timestamp
|
464
465
|
- bin/ix-nested-list
|
465
466
|
- bin/ix-nnjj
|
467
|
+
- bin/ix-noansi
|
466
468
|
- bin/ix-noeol
|
467
469
|
- bin/ix-noise
|
468
470
|
- bin/ix-normalize
|
@@ -584,10 +586,10 @@ files:
|
|
584
586
|
- bin/ix-wrap
|
585
587
|
- bin/ix-xy
|
586
588
|
- bin/ix-zebra
|
587
|
-
homepage:
|
589
|
+
homepage:
|
588
590
|
licenses: []
|
589
591
|
metadata: {}
|
590
|
-
post_install_message:
|
592
|
+
post_install_message:
|
591
593
|
rdoc_options: []
|
592
594
|
require_paths:
|
593
595
|
- lib
|
@@ -602,8 +604,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
602
604
|
- !ruby/object:Gem::Version
|
603
605
|
version: '0'
|
604
606
|
requirements: []
|
605
|
-
rubygems_version: 3.
|
606
|
-
signing_key:
|
607
|
+
rubygems_version: 3.3.7
|
608
|
+
signing_key:
|
607
609
|
specification_version: 4
|
608
610
|
summary: ix - string manipulation tools
|
609
611
|
test_files: []
|