mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-07 23:51:12 +08:00
Add experimental progressive mode
This commit is contained in:
parent
1669024325
commit
f0861bcac4
@ -31,6 +31,11 @@ module YouPlot
|
|||||||
if %i[colors color colours colour].include? @command
|
if %i[colors color colours colour].include? @command
|
||||||
plot = create_plot
|
plot = create_plot
|
||||||
output_plot(plot)
|
output_plot(plot)
|
||||||
|
else
|
||||||
|
if options[:progressive]
|
||||||
|
while (input = Kernel.gets)
|
||||||
|
main_progress(input)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
# Sometimes the input file does not end with a newline code.
|
# Sometimes the input file does not end with a newline code.
|
||||||
while (input = Kernel.gets(nil))
|
while (input = Kernel.gets(nil))
|
||||||
@ -38,6 +43,7 @@ module YouPlot
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
@ -52,6 +58,18 @@ module YouPlot
|
|||||||
output_plot(plot)
|
output_plot(plot)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def main_progress(input)
|
||||||
|
output_data(input)
|
||||||
|
|
||||||
|
@raw_data ||= String.new
|
||||||
|
@raw_data << input
|
||||||
|
|
||||||
|
@data = read_dsv(@raw_data)
|
||||||
|
|
||||||
|
plot = create_plot
|
||||||
|
output_plot_progressive(plot)
|
||||||
|
end
|
||||||
|
|
||||||
def read_dsv(input)
|
def read_dsv(input)
|
||||||
input = input.dup.force_encoding(options[:encoding]).encode('utf-8') if options[:encoding]
|
input = input.dup.force_encoding(options[:encoding]).encode('utf-8') if options[:encoding]
|
||||||
DSV.parse(input, options[:delimiter], options[:headers], options[:transpose])
|
DSV.parse(input, options[:delimiter], options[:headers], options[:transpose])
|
||||||
@ -106,5 +124,27 @@ module YouPlot
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def output_plot_progressive(plot)
|
||||||
|
case options[:output]
|
||||||
|
when IO
|
||||||
|
# RefactorMe
|
||||||
|
@output_stringio = StringIO.new(String.new)
|
||||||
|
def @output_stringio.tty?; true; end
|
||||||
|
out = @output_stringio.clone
|
||||||
|
plot.render(out)
|
||||||
|
lines = out.string.lines
|
||||||
|
lines.each do |line|
|
||||||
|
options[:output].print line.chomp
|
||||||
|
options[:output].print "\e[0K"
|
||||||
|
options[:output].puts
|
||||||
|
end
|
||||||
|
options[:output].flush
|
||||||
|
n = out.string.lines.size
|
||||||
|
options[:output].print "\e[#{n}F"
|
||||||
|
else
|
||||||
|
raise "In progressive mode, output to a file is not possible."
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,6 +7,7 @@ module YouPlot
|
|||||||
:transpose,
|
:transpose,
|
||||||
:headers,
|
:headers,
|
||||||
:pass,
|
:pass,
|
||||||
|
:progressive,
|
||||||
:output,
|
:output,
|
||||||
:fmt,
|
:fmt,
|
||||||
:encoding,
|
:encoding,
|
||||||
|
@ -82,7 +82,7 @@ module YouPlot
|
|||||||
opt.on('--[no-]labels', TrueClass, 'hide the labels') do |v|
|
opt.on('--[no-]labels', TrueClass, 'hide the labels') do |v|
|
||||||
params.labels = v
|
params.labels = v
|
||||||
end
|
end
|
||||||
opt.on('--progress', TrueClass, 'progressive') do |v|
|
opt.on('--progress', TrueClass, 'progressive mode [experimental]') do |v|
|
||||||
@options[:progressive] = v
|
@options[:progressive] = v
|
||||||
end
|
end
|
||||||
opt.on('--encoding VAL', String, 'Specify the input encoding') do |v|
|
opt.on('--encoding VAL', String, 'Specify the input encoding') do |v|
|
||||||
|
Loading…
Reference in New Issue
Block a user