From ccf232a7423e4ac05bce57c0845fb87eb996cf00 Mon Sep 17 00:00:00 2001 From: kojix2 <2xijok@gmail.com> Date: Wed, 25 Nov 2020 15:51:06 +0900 Subject: [PATCH] Pass standard input to standard output first --- lib/youplot/command.rb | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/youplot/command.rb b/lib/youplot/command.rb index a25aeba..ff2383d 100644 --- a/lib/youplot/command.rb +++ b/lib/youplot/command.rb @@ -40,14 +40,28 @@ module YouPlot # Sometimes the input file does not end with a newline code. while (input = Kernel.gets(nil)) - input.freeze + + # Pass the input to subsequent pipelines + case pass + when IO + pass.print(input) + else + if pass + File.open(pass, 'w') do |f| + f.print(input) + end + end + end + @data = if @encoding input2 = input.dup.force_encoding(@encoding).encode('utf-8') Preprocessing.input(input2, delimiter, headers, transpose) else Preprocessing.input(input, delimiter, headers, transpose) end + pp @data if @debug + plot = case command when :bar, :barplot @backend.barplot(data, params) @@ -78,16 +92,6 @@ module YouPlot end end - case pass - when IO - pass.print(input) - else - if pass - File.open(pass, 'w') do |f| - f.print(input) - end - end - end end end end