vll 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/vl +66 -59
- data/bin/vll +3 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e835b8515174f40da85daa6a5fd92b94f0fc525
|
4
|
+
data.tar.gz: 2510a88faf49a449fc58fd70b5e6b970d5c7adbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4ec9e6c335414131aad90f76edcc1d72d36a8fa99a90d5cf301e0f2a2c8cfcd9c14862a60f073b292e6e6366cf311d4b7eede81b3850c39019ce2ee955a1c4b
|
7
|
+
data.tar.gz: c15455c89ccf657803aae83979ece54d176910e2741e277b99fd3bec6773e96f85613d538c71f5f9d0d79e424114d68acb9e4fe6782989594558868934db3f38
|
data/bin/vl
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
begin
|
3
3
|
|
4
4
|
require 'optparse'
|
5
|
-
require '
|
5
|
+
require 'csv'
|
6
6
|
|
7
|
-
options = {
|
8
|
-
:separator =>
|
7
|
+
$options = {
|
8
|
+
:separator => "",
|
9
9
|
:padding => 1,
|
10
10
|
:skip => 0,
|
11
11
|
:comment => /^#/,
|
@@ -13,42 +13,46 @@ options = {
|
|
13
13
|
:justify => 'l'
|
14
14
|
}
|
15
15
|
|
16
|
+
|
16
17
|
opts = OptionParser.new do |opts|
|
17
18
|
opts.program_name = "(V)iew (L)arge table"
|
18
|
-
|
19
|
-
opts.banner =
|
19
|
+
|
20
|
+
opts.banner = "(V)iew (L)arge table: lightning fast table formatter"
|
21
|
+
opts.separator ''
|
22
|
+
opts.separator ' output to stdout:'
|
23
|
+
opts.separator ' vl FILENAME [options]'
|
24
|
+
opts.separator ' pipe to less:'
|
20
25
|
opts.separator ' vll FILENAME [options]'
|
21
26
|
opts.separator ''
|
22
27
|
opts.separator 'Options:'
|
23
|
-
opts.separator '-' * 80
|
24
28
|
|
25
29
|
opts.on('-s', '--separator [REGEX]',
|
26
|
-
'
|
27
|
-
' default:
|
30
|
+
'char or string to match the separator',
|
31
|
+
' default: "," (if csv, "\t")') do |s|
|
28
32
|
begin
|
29
33
|
options[:separator] = Regexp.new(s)
|
30
34
|
rescue
|
31
35
|
puts 'Warning: Problems encountered when processing the regex.'
|
32
|
-
puts "Warning: Default value \"#{options[:separator].source}\" is used."
|
36
|
+
puts "Warning: Default value \"#{$options[:separator].source}\" is used."
|
33
37
|
end
|
34
38
|
end
|
35
39
|
|
36
40
|
opts.on('-p', '--padding [NUM_OF_SPACES]',
|
37
41
|
'number of spaces that separate the columns',
|
38
42
|
' default: 1') do |p|
|
39
|
-
options[:padding] = p.to_i
|
43
|
+
$options[:padding] = p.to_i
|
40
44
|
end
|
41
45
|
|
42
46
|
opts.on('-k', '--skip [NUM_OF_LINES]',
|
43
47
|
'number of top lines to skip',
|
44
48
|
' default: 0') do |k|
|
45
|
-
options[:skip] = k.to_i
|
49
|
+
$options[:skip] = k.to_i
|
46
50
|
end
|
47
51
|
|
48
52
|
opts.on('-p', '--probe-lines [NUM_OF_LINES]',
|
49
53
|
'number of top lines used for fast estimation',
|
50
54
|
' default: 100') do |p|
|
51
|
-
options[:probe_lines] = p.to_i
|
55
|
+
$options[:probe_lines] = p.to_i
|
52
56
|
end
|
53
57
|
|
54
58
|
opts.on('-j', '--justify [CODE]',
|
@@ -57,10 +61,10 @@ opts = OptionParser.new do |opts|
|
|
57
61
|
' options: l = left, r = right, a = auto',
|
58
62
|
' default: l') do |j|
|
59
63
|
if ['l', 'r', 'a'].include?(j[0])
|
60
|
-
options[:justify] = j[0]
|
64
|
+
$options[:justify] = j[0]
|
61
65
|
else
|
62
66
|
puts 'Warning: Unrecognized justify option.'
|
63
|
-
puts "Warning: Default value \"#{options[:justify]}\" is used"
|
67
|
+
puts "Warning: Default value \"#{$options[:justify]}\" is used"
|
64
68
|
end
|
65
69
|
end
|
66
70
|
|
@@ -68,80 +72,83 @@ opts = OptionParser.new do |opts|
|
|
68
72
|
'regex to match lines to ignore',
|
69
73
|
' default: ^#') do |c|
|
70
74
|
begin
|
71
|
-
options[:comment] = Regexp.new(c)
|
75
|
+
$options[:comment] = Regexp.new(c)
|
72
76
|
rescue
|
73
77
|
puts 'Warning: Problems encountered when processing the regex.'
|
74
|
-
puts "Warning: Default value \"#{options[:comment].source}\" is used."
|
78
|
+
puts "Warning: Default value \"#{$options[:comment].source}\" is used."
|
75
79
|
end
|
76
80
|
end
|
77
81
|
end
|
78
82
|
|
79
83
|
opts.parse!
|
80
84
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
else
|
86
|
-
|
85
|
+
#default separator
|
86
|
+
if $options[:separator] == ''
|
87
|
+
if ARGF.filename =~ /.*\.csv/
|
88
|
+
$options[:separator] = ','
|
89
|
+
else
|
90
|
+
$options[:separator] = "\t"
|
91
|
+
end
|
87
92
|
end
|
88
93
|
|
89
|
-
if !File.exists? file_name
|
90
|
-
abort "Error: file \"#{file_name}\" not found."
|
91
|
-
end
|
92
94
|
|
93
|
-
max_widths = []
|
94
95
|
|
95
|
-
|
96
|
+
#------#
|
97
|
+
# Main #
|
98
|
+
#------#
|
99
|
+
|
100
|
+
|
101
|
+
$max_widths = []
|
102
|
+
|
96
103
|
|
97
|
-
|
98
|
-
|
99
|
-
|
104
|
+
#==== line caching ====#
|
105
|
+
cached_lines = []
|
106
|
+
ARGF.each_line.with_index.reduce 0 do |pnum, (line, lnum)|
|
107
|
+
cached_lines.push(line)
|
108
|
+
next pnum if lnum < $options[:skip] or line =~ $options[:comment]
|
109
|
+
CSV.parse_line(line, {:col_sep=>$options[:separator]}).each_with_index do |c, i|
|
100
110
|
# -1 because it's possible that c is empty and i is out of range
|
101
|
-
if max_widths.fetch(i, -1) < c.length then max_widths[i] = c.length end
|
111
|
+
if $max_widths.fetch(i, -1) < c.length then $max_widths[i] = c.length end
|
102
112
|
end
|
103
|
-
(pnum += 1) < options[:probe_lines] ? pnum : break
|
113
|
+
(pnum += 1) < $options[:probe_lines] ? pnum : break
|
104
114
|
end
|
115
|
+
#======================#
|
105
116
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
# line = file.next rescue break
|
110
|
-
# lnum += 1
|
111
|
-
# end while lnum < options[:skip] or line =~ options[:comment]
|
112
|
-
# line.chomp.split(options[:separator]).each_with_index do |c, i|
|
113
|
-
# # -1 because it's possible that c is empty and i is out of range
|
114
|
-
# if max_widths.fetch(i, -1) < c.length then max_widths[i] = c.length end
|
115
|
-
# end
|
116
|
-
#end
|
117
|
-
|
118
|
-
file.rewind
|
119
|
-
|
120
|
-
file.each_line.with_index do |line, lnum|
|
121
|
-
if lnum < options[:skip] or line =~ options[:comment] then
|
117
|
+
|
118
|
+
def print_line(line, lnum)
|
119
|
+
if lnum < $options[:skip] or line =~ $options[:comment] then
|
122
120
|
print line
|
123
|
-
|
121
|
+
return
|
124
122
|
end
|
125
|
-
|
126
|
-
if max_widths.fetch(i, -1) < c.length then max_widths[i] = c.length end
|
127
|
-
case options[:justify]
|
123
|
+
CSV.parse_line(line, {:col_sep=>$options[:separator]}).each_with_index do |c, i|
|
124
|
+
if $max_widths.fetch(i, -1) < c.length then $max_widths[i] = c.length end
|
125
|
+
case $options[:justify]
|
128
126
|
when 'l'
|
129
|
-
print c.ljust(max_widths[i] + options[:padding]) rescue break
|
127
|
+
print c.ljust($max_widths[i] + $options[:padding]) rescue break
|
130
128
|
when 'r'
|
131
|
-
print c.rjust(max_widths[i] + options[:padding]) rescue break
|
129
|
+
print c.rjust($max_widths[i] + $options[:padding]) rescue break
|
132
130
|
when 'a'
|
133
131
|
begin
|
134
|
-
if Float(c) then print c.rjust(max_widths[i] + options[:padding]) end
|
132
|
+
if Float(c) then print c.rjust($max_widths[i] + $options[:padding]) end
|
135
133
|
rescue
|
136
|
-
print c.ljust(max_widths[i] + options[:padding])
|
134
|
+
print c.ljust($max_widths[i] + $options[:padding])
|
137
135
|
end
|
138
136
|
end
|
139
137
|
end
|
140
|
-
print "\n" rescue
|
138
|
+
print "\n" rescue return
|
139
|
+
end
|
140
|
+
|
141
|
+
cached_lines.each.with_index do |line, lnum|
|
142
|
+
print_line(line, lnum)
|
143
|
+
end
|
144
|
+
|
145
|
+
ARGF.each_line.with_index do |line, lnum|
|
146
|
+
print_line(line, lnum)
|
141
147
|
end
|
142
148
|
|
149
|
+
|
150
|
+
|
151
|
+
|
143
152
|
rescue Interrupt
|
144
|
-
# avoid awkward system prompt
|
145
|
-
print "\n"
|
146
153
|
|
147
154
|
end
|
data/bin/vll
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vll
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xzhu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Nicely format columns of a large CSV/TSV file according to their content
|
14
14
|
width, using first few lines as estimation thus extremely fast. Customizable.
|
@@ -42,9 +42,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
42
|
version: '0'
|
43
43
|
requirements: []
|
44
44
|
rubyforge_project:
|
45
|
-
rubygems_version: 2.4.
|
45
|
+
rubygems_version: 2.4.5
|
46
46
|
signing_key:
|
47
47
|
specification_version: 4
|
48
48
|
summary: "(V)iew (L)arge table. Format large table in a split of a second"
|
49
49
|
test_files: []
|
50
|
-
has_rdoc:
|