From 2181e4a0f7c4cf63945795b1e8d0b1e03fff71fe Mon Sep 17 00:00:00 2001 From: kojix2 <2xijok@gmail.com> Date: Fri, 6 Nov 2020 10:21:36 +0900 Subject: [PATCH] Fix color command option --- lib/uplot/command.rb | 2 +- lib/uplot/command/parser.rb | 24 +++++++++++++----------- lib/uplot/plot.rb | 10 ++++++---- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/uplot/command.rb b/lib/uplot/command.rb index 4106aa9..309e7da 100644 --- a/lib/uplot/command.rb +++ b/lib/uplot/command.rb @@ -31,7 +31,7 @@ module Uplot @debug = parser.debug if command == :colors - Plot.colors + Plot.colors(parser.color_names) exit end diff --git a/lib/uplot/command/parser.rb b/lib/uplot/command/parser.rb index 0217684..0317db8 100644 --- a/lib/uplot/command/parser.rb +++ b/lib/uplot/command/parser.rb @@ -7,19 +7,21 @@ module Uplot class Command class Parser attr_reader :command, :params, - :delimiter, :transpose, :headers, :pass, :output, :fmt, :debug + :delimiter, :transpose, :headers, :pass, :output, :fmt, + :color_names, :debug def initialize - @command = nil - @params = Params.new + @command = nil + @params = Params.new - @delimiter = "\t" - @transpose = false - @headers = nil - @pass = false - @output = $stderr - @fmt = 'xyy' - @debug = false + @delimiter = "\t" + @transpose = false + @headers = nil + @pass = false + @output = $stderr + @fmt = 'xyy' + @debug = false + @color_names = false end def create_default_parser @@ -202,7 +204,7 @@ module Uplot end when :colors - parser.on_head('-n', '--names', TrueClass) do |v| + parser.on_head('-n', '--names', 'show color names only', TrueClass) do |v| @color_names = v end diff --git a/lib/uplot/plot.rb b/lib/uplot/plot.rb index db901d1..839917d 100644 --- a/lib/uplot/plot.rb +++ b/lib/uplot/plot.rb @@ -50,7 +50,7 @@ module Uplot end def get_method2(method1) - (method1.to_s + '!').to_sym + "#{method1}!".to_sym end def plot_xyy(data, method1, params) @@ -121,12 +121,14 @@ module Uplot UnicodePlot.boxplot(headers, series, **params.to_hc) end - def colors + def colors(color_names = false) UnicodePlot::StyledPrinter::TEXT_COLORS.each do |k, v| print v print k - print "\t" - print ' ●' + unless color_names + print "\t" + print ' ●' + end print "\033[0m" print "\t" end