mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-07 15:41:12 +08:00
Improved progressive mode
This commit is contained in:
parent
f0861bcac4
commit
60fb611160
@ -31,16 +31,18 @@ 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)
|
||||||
|
elsif options[:progressive]
|
||||||
|
stop = false
|
||||||
|
Signal.trap(:INT) { stop = true }
|
||||||
|
while (input = Kernel.gets)
|
||||||
|
main_progressive(input)
|
||||||
|
break if stop
|
||||||
|
end
|
||||||
|
options[:output].print "\e[0J"
|
||||||
else
|
else
|
||||||
if options[:progressive]
|
# Sometimes the input file does not end with a newline code.
|
||||||
while (input = Kernel.gets)
|
while (input = Kernel.gets(nil))
|
||||||
main_progress(input)
|
main(input)
|
||||||
end
|
|
||||||
else
|
|
||||||
# Sometimes the input file does not end with a newline code.
|
|
||||||
while (input = Kernel.gets(nil))
|
|
||||||
main(input)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -58,12 +60,13 @@ module YouPlot
|
|||||||
output_plot(plot)
|
output_plot(plot)
|
||||||
end
|
end
|
||||||
|
|
||||||
def main_progress(input)
|
def main_progressive(input)
|
||||||
output_data(input)
|
output_data(input)
|
||||||
|
|
||||||
@raw_data ||= String.new
|
@raw_data ||= String.new
|
||||||
@raw_data << input
|
@raw_data << input
|
||||||
|
|
||||||
|
# FIXME
|
||||||
@data = read_dsv(@raw_data)
|
@data = read_dsv(@raw_data)
|
||||||
|
|
||||||
plot = create_plot
|
plot = create_plot
|
||||||
@ -129,9 +132,10 @@ module YouPlot
|
|||||||
case options[:output]
|
case options[:output]
|
||||||
when IO
|
when IO
|
||||||
# RefactorMe
|
# RefactorMe
|
||||||
@output_stringio = StringIO.new(String.new)
|
out = StringIO.new(String.new)
|
||||||
def @output_stringio.tty?; true; end
|
def out.tty?
|
||||||
out = @output_stringio.clone
|
true
|
||||||
|
end
|
||||||
plot.render(out)
|
plot.render(out)
|
||||||
lines = out.string.lines
|
lines = out.string.lines
|
||||||
lines.each do |line|
|
lines.each do |line|
|
||||||
@ -139,11 +143,12 @@ module YouPlot
|
|||||||
options[:output].print "\e[0K"
|
options[:output].print "\e[0K"
|
||||||
options[:output].puts
|
options[:output].puts
|
||||||
end
|
end
|
||||||
|
options[:output].print "\e[0J"
|
||||||
options[:output].flush
|
options[:output].flush
|
||||||
n = out.string.lines.size
|
n = out.string.lines.size
|
||||||
options[:output].print "\e[#{n}F"
|
options[:output].print "\e[#{n}F"
|
||||||
else
|
else
|
||||||
raise "In progressive mode, output to a file is not possible."
|
raise 'In progressive mode, output to a file is not possible.'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user