vll 0.1.12 → 0.1.13

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 +123 -118
  2. metadata +2 -2
data/bin/vl CHANGED
@@ -105,108 +105,51 @@ end
105
105
  #------#
106
106
 
107
107
 
108
- #$max_widths = []
109
- #
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
- #
129
- #
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|
139
- # break if i > $options[:max_n_cols]
140
- # if i == $options[:max_n_cols] then
141
- # print "... #{parsed_line.size - i} more columns"
142
- # break
143
- # end
144
- #
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
- # c = c[0..$options[:chop_length]]
154
- # $max_widths[i] = [$options[:chop_length], $max_widths[i]].min
155
- #
156
- # case $options[:justify]
157
- # when 'l'
158
- # c = c.ljust($max_widths[i] + $options[:padding]) rescue break
159
- # when 'r'
160
- # c = c.rjust($max_widths[i] + $options[:padding]) rescue break
161
- # when 'a'
162
- # begin
163
- # if Float(c) then c = c.rjust($max_widths[i] + $options[:padding]) end
164
- # rescue
165
- # c = c.ljust($max_widths[i] + $options[:padding])
166
- # end
167
- # end
168
- #
169
- # if $options[:alternate_color] then
170
- # c = c.colorize([:yellow, :blue][i % 2])
171
- # end
172
- #
173
- # print c
174
- # end
175
- # puts
176
- #rescue
177
- # STDERR.puts 'vl: Pipe ended while writing.'
178
- # abort
179
- #end
180
- #
181
- #cached_lines.each.with_index do |line, lnum|
182
- # print_line(line, lnum)
183
- #end
184
- #
185
- #ARGF.each_line.with_index do |line, lnum|
186
- # print_line(line, lnum)
187
- #end
188
-
189
-
190
-
108
+ $max_widths = []
191
109
 
192
- #==== new version ===#
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
+ #======================#
193
128
 
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
129
 
202
- def print_row(row)
203
- row.each_with_index do |c, i|
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|
204
139
  break if i > $options[:max_n_cols]
205
140
  if i == $options[:max_n_cols] then
206
- print "... #{row.size - i} more columns"
141
+ print "... #{parsed_line.size - i} more columns"
207
142
  break
208
143
  end
209
144
 
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
+
210
153
  c = c[0..$options[:chop_length]]
211
154
  $max_widths[i] = [$options[:chop_length], $max_widths[i]].min
212
155
 
@@ -230,37 +173,99 @@ def print_row(row)
230
173
  print c
231
174
  end
232
175
  puts
233
- #rescue
234
- # STDERR.puts 'vl: Pipe ended while writing.'
235
- # abort
176
+ rescue
177
+ STDERR.puts 'vl: Pipe ended while writing.'
178
+ abort
236
179
  end
237
180
 
238
- CSV.new(ARGF, $csv_options).each.with_index do |row, i|
239
- row = row.map.with_index do |c, i|
240
- # damn you, 'csv' package!
241
- c = '' if c == nil
242
- c = c.inspect[1..-2]
243
- if $max_widths.fetch(i, -1) < c.length then $max_widths[i] = c.length end
244
- c
245
- end
246
-
247
- if i < $options[:probe_lines] then
248
- $cached_lines.push(row)
249
- else
250
- if $cached_lines.length > 0 then
251
- $cached_lines.each{|row|print_row(row)}
252
- $cached_lines = []
253
- end
254
- print_row(row)
255
- end
181
+ cached_lines.each.with_index do |line, lnum|
182
+ print_line(line, lnum)
256
183
  end
257
184
 
258
- if $cached_lines.length > 0 then
259
- $cached_lines.each{|row|print_row(row)}
260
- $cached_lines = []
185
+ ARGF.each_line.with_index do |line, lnum|
186
+ print_line(line, lnum)
261
187
  end
262
188
 
263
189
 
190
+
191
+
192
+ #==== new version ===#
193
+
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
267
+
268
+
264
269
  rescue Interrupt
265
270
 
266
271
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: vll
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.12
5
+ version: 0.1.13
6
6
  platform: ruby
7
7
  authors:
8
8
  - xzhu
@@ -51,7 +51,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 2.2.0
55
55
  required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements: