From 95a35399a2ba82538e332444243dbc112beb7645 Mon Sep 17 00:00:00 2001 From: kojix2 <2xijok@gmail.com> Date: Sat, 3 Jul 2021 06:39:21 +0900 Subject: [PATCH] Show a error message when linecolor is specified as a number --- lib/youplot/backends/unicode_plot.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/youplot/backends/unicode_plot.rb b/lib/youplot/backends/unicode_plot.rb index 8a2a14c..7f75c67 100644 --- a/lib/youplot/backends/unicode_plot.rb +++ b/lib/youplot/backends/unicode_plot.rb @@ -6,6 +6,27 @@ require_relative 'processing' require 'unicode_plot' +# If the line color is specified as a number, the program will display an error +# message to the user and exit. Remove this patch when UnicodePlot is improved. + +module UnicodePlot + class << self + alias lineplot_original lineplot + def lineplot(*args, **kw) + if kw[:color].is_a? Numeric + warn <<~EOS + YouPlot: Line colors cannot be specified by numerical values. + + For more information, please see the following issue. + https://github.com/red-data-tools/unicode_plot.rb/issues/34 + EOS + YouPlot.run_as_executable ? exit(1) : raise(Error) + end + lineplot_original(*args, **kw) + end + end +end + module YouPlot # plotting functions. module Backends @@ -182,7 +203,7 @@ module YouPlot series = data.series if series.size == 1 warn <<~EOS - youplot: There is only one series of input data. Please check the delimiter. + YouPlot: There is only one series of input data. Please check the delimiter. Headers: \e[35m#{data.headers.inspect}\e[0m The first item is: \e[35m\"#{series[0][0]}\"\e[0m