vll 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/vl +141 -120
  2. metadata +3 -3
data/bin/vl CHANGED
@@ -5,6 +5,7 @@ begin
5
5
  require 'optparse'
6
6
  require 'colorize'
7
7
  require 'csv'
8
+ require 'pp'
8
9
 
9
10
  $options = {
10
11
  :padding => 1,
@@ -16,6 +17,7 @@ $options = {
16
17
  :alternate_color => false,
17
18
  :chop_length => 1024,
18
19
  :max_n_cols => 200,
20
+ :return_char => ["\n", "\r", "\r\n"],
19
21
  }
20
22
 
21
23
 
@@ -105,51 +107,109 @@ end
105
107
  #------#
106
108
 
107
109
 
108
- $max_widths = []
110
+ #$max_widths = []
111
+ #
112
+ ##==== line caching ====#
113
+ #cached_lines = []
114
+ #ARGF.each_line.with_index.reduce 0 do |pnum, (line, lnum)|
115
+ # cached_lines.push(line)
116
+ # next pnum if lnum < $options[:skip] or line =~ $options[:comment]
117
+ # parsed_line = CSV.parse_line(line, {:col_sep=>$options[:separator], :quote_char=>$options[:quote]})
118
+ # # damn you, 'csv' package!
119
+ # parsed_line = [] if parsed_line == nil
120
+ # parsed_line.each_with_index do |c, i|
121
+ # # damn you, 'csv' package!
122
+ # c = '' if c == nil
123
+ # c = c.inspect[1..-2]
124
+ # # -1 because it's possible that c is empty and i is out of range
125
+ # if $max_widths.fetch(i, -1) < c.length then $max_widths[i] = c.length end
126
+ # end
127
+ # (pnum += 1) < $options[:probe_lines] ? pnum : break
128
+ #end
129
+ ##======================#
130
+ #
131
+ #
132
+ #def print_line(line, lnum)
133
+ # if lnum < $options[:skip] or line =~ $options[:comment] then
134
+ # print line
135
+ # return
136
+ # end
137
+ # parsed_line = CSV.parse_line(line, {:col_sep=>$options[:separator], :quote_char=>$options[:quote]})
138
+ # # damn you, 'csv' package!
139
+ # parsed_line = [] if parsed_line == nil
140
+ # parsed_line.each_with_index do |c, i|
141
+ # break if i > $options[:max_n_cols]
142
+ # if i == $options[:max_n_cols] then
143
+ # print "... #{parsed_line.size - i} more columns"
144
+ # break
145
+ # end
146
+ #
147
+ # # damn you, 'csv' package!
148
+ # c = '' if c == nil
149
+ # c = c.inspect[1..-2]
150
+ #
151
+ # if $max_widths.fetch(i, -1) < c.length then
152
+ # $max_widths[i] = c.length
153
+ # end
154
+ #
155
+ # c = c[0..$options[:chop_length]]
156
+ # $max_widths[i] = [$options[:chop_length], $max_widths[i]].min
157
+ #
158
+ # case $options[:justify]
159
+ # when 'l'
160
+ # c = c.ljust($max_widths[i] + $options[:padding]) rescue break
161
+ # when 'r'
162
+ # c = c.rjust($max_widths[i] + $options[:padding]) rescue break
163
+ # when 'a'
164
+ # begin
165
+ # if Float(c) then c = c.rjust($max_widths[i] + $options[:padding]) end
166
+ # rescue
167
+ # c = c.ljust($max_widths[i] + $options[:padding])
168
+ # end
169
+ # end
170
+ #
171
+ # if $options[:alternate_color] then
172
+ # c = c.colorize([:yellow, :blue][i % 2])
173
+ # end
174
+ #
175
+ # print c
176
+ # end
177
+ # puts
178
+ #rescue
179
+ # STDERR.puts 'vl: Pipe ended while writing.'
180
+ # abort
181
+ #end
182
+ #
183
+ #cached_lines.each.with_index do |line, lnum|
184
+ # print_line(line, lnum)
185
+ #end
186
+ #
187
+ #ARGF.each_line.with_index do |line, lnum|
188
+ # print_line(line, lnum)
189
+ #end
109
190
 
110
- #==== line caching ====#
111
- cached_lines = []
112
- ARGF.each_line.with_index.reduce 0 do |pnum, (line, lnum)|
113
- cached_lines.push(line)
114
- next pnum if lnum < $options[:skip] or line =~ $options[:comment]
115
- parsed_line = CSV.parse_line(line, {:col_sep=>$options[:separator], :quote_char=>$options[:quote]})
116
- # damn you, 'csv' package!
117
- parsed_line = [] if parsed_line == nil
118
- parsed_line.each_with_index do |c, i|
119
- # damn you, 'csv' package!
120
- c = '' if c == nil
121
- c = c.inspect[1..-2]
122
- # -1 because it's possible that c is empty and i is out of range
123
- if $max_widths.fetch(i, -1) < c.length then $max_widths[i] = c.length end
124
- end
125
- (pnum += 1) < $options[:probe_lines] ? pnum : break
126
- end
127
- #======================#
128
191
 
129
192
 
130
- def print_line(line, lnum)
131
- if lnum < $options[:skip] or line =~ $options[:comment] then
132
- print line
133
- return
134
- end
135
- parsed_line = CSV.parse_line(line, {:col_sep=>$options[:separator], :quote_char=>$options[:quote]})
136
- # damn you, 'csv' package!
137
- parsed_line = [] if parsed_line == nil
138
- parsed_line.each_with_index do |c, i|
193
+
194
+ #==== new version ===#
195
+
196
+ $cached_lines = []
197
+ $max_widths = []
198
+ $csv_options = {
199
+ :col_sep => $options[:separator],
200
+ :quote_char => $options[:quote],
201
+ :row_sep => $options[:return_char],
202
+ #:skip_lines => $options[:comment]
203
+ }
204
+
205
+ def print_row(row)
206
+ row.each_with_index do |c, i|
139
207
  break if i > $options[:max_n_cols]
140
208
  if i == $options[:max_n_cols] then
141
- print "... #{parsed_line.size - i} more columns"
209
+ print "... #{row.size - i} more columns"
142
210
  break
143
211
  end
144
212
 
145
- # damn you, 'csv' package!
146
- c = '' if c == nil
147
- c = c.inspect[1..-2]
148
-
149
- if $max_widths.fetch(i, -1) < c.length then
150
- $max_widths[i] = c.length
151
- end
152
-
153
213
  c = c[0..$options[:chop_length]]
154
214
  $max_widths[i] = [$options[:chop_length], $max_widths[i]].min
155
215
 
@@ -173,97 +233,58 @@ def print_line(line, lnum)
173
233
  print c
174
234
  end
175
235
  puts
176
- rescue
177
- STDERR.puts 'vl: Pipe ended while writing.'
178
- abort
236
+ #rescue Exception => e
237
+ # #STDERR.puts 'vl: Pipe ended while writing.'
238
+ # pp e
239
+ # throw e
179
240
  end
180
241
 
181
- cached_lines.each.with_index do |line, lnum|
182
- print_line(line, lnum)
183
- end
242
+ (1..1.0/0).each do |i|
243
+ if ARGF.eof? then
244
+ break
245
+ end
184
246
 
185
- ARGF.each_line.with_index do |line, lnum|
186
- print_line(line, lnum)
187
- end
247
+ line = ARGF.readline
188
248
 
249
+ if i < $options[:skip] or line =~ $options[:comment] then
250
+ print line
251
+ next
252
+ end
189
253
 
254
+ begin
255
+ row = CSV.parse_line(line, $csv_options)
256
+ rescue CSV::MalformedCSVError => e
257
+ line = line + ARGF.readline
258
+ if line.length < 10000 then
259
+ retry
260
+ else
261
+ throw e
262
+ end
263
+ end
190
264
 
265
+ row = row.map.with_index do |c, i|
266
+ # damn you, 'csv' package!
267
+ c = '' if c == nil
268
+ c = c.inspect[1..-2]
269
+ if $max_widths.fetch(i, -1) < c.length then $max_widths[i] = c.length end
270
+ c
271
+ end
191
272
 
192
- #==== new version ===#
273
+ if i < $options[:probe_lines] then
274
+ $cached_lines.push(row)
275
+ else
276
+ if $cached_lines.length > 0 then
277
+ $cached_lines.each{|row|print_row(row)}
278
+ $cached_lines = []
279
+ end
280
+ print_row(row)
281
+ end
282
+ end
193
283
 
194
- #$cached_lines = []
195
- #$max_widths = []
196
- #$csv_options = {
197
- # :col_sep => $options[:separator],
198
- # :quote_char => $options[:quote],
199
- # :skip_lines => $options[:comment]
200
- #}
201
- #
202
- #def print_row(row)
203
- # row.each_with_index do |c, i|
204
- # break if i > $options[:max_n_cols]
205
- # if i == $options[:max_n_cols] then
206
- # print "... #{row.size - i} more columns"
207
- # break
208
- # end
209
- #
210
- # c = c[0..$options[:chop_length]]
211
- # $max_widths[i] = [$options[:chop_length], $max_widths[i]].min
212
- #
213
- # case $options[:justify]
214
- # when 'l'
215
- # c = c.ljust($max_widths[i] + $options[:padding]) rescue break
216
- # when 'r'
217
- # c = c.rjust($max_widths[i] + $options[:padding]) rescue break
218
- # when 'a'
219
- # begin
220
- # if Float(c) then c = c.rjust($max_widths[i] + $options[:padding]) end
221
- # rescue
222
- # c = c.ljust($max_widths[i] + $options[:padding])
223
- # end
224
- # end
225
- #
226
- # if $options[:alternate_color] then
227
- # c = c.colorize([:yellow, :blue][i % 2])
228
- # end
229
- #
230
- # print c
231
- # end
232
- # puts
233
- ##rescue
234
- ## STDERR.puts 'vl: Pipe ended while writing.'
235
- ## abort
236
- #end
237
- #
238
- #CSV.new(ARGF, $csv_options).each.with_index do |row, i|
239
- # if i < $options[:skip] then
240
- # puts 'break!'
241
- # break
242
- # end
243
- #
244
- # row = row.map.with_index do |c, i|
245
- # # damn you, 'csv' package!
246
- # c = '' if c == nil
247
- # c = c.inspect[1..-2]
248
- # if $max_widths.fetch(i, -1) < c.length then $max_widths[i] = c.length end
249
- # c
250
- # end
251
- #
252
- # if i < $options[:probe_lines] then
253
- # $cached_lines.push(row)
254
- # else
255
- # if $cached_lines.length > 0 then
256
- # $cached_lines.each{|row|print_row(row)}
257
- # $cached_lines = []
258
- # end
259
- # print_row(row)
260
- # end
261
- #end
262
- #
263
- #if $cached_lines.length > 0 then
264
- # $cached_lines.each{|row|print_row(row)}
265
- # $cached_lines = []
266
- #end
284
+ if $cached_lines.length > 0 then
285
+ $cached_lines.each{|row|print_row(row)}
286
+ $cached_lines = []
287
+ end
267
288
 
268
289
 
269
290
  rescue Interrupt
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: vll
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.13
5
+ version: 0.1.14
6
6
  platform: ruby
7
7
  authors:
8
8
  - xzhu
@@ -39,7 +39,7 @@ extra_rdoc_files: []
39
39
  files:
40
40
  - bin/vl
41
41
  - bin/vll
42
- homepage:
42
+ homepage: https://github.com/w9/vll
43
43
  licenses:
44
44
  - MIT
45
45
  post_install_message:
@@ -51,7 +51,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
- version: 2.2.0
54
+ version: '0'
55
55
  required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements: