Fix color command

This commit is contained in:
kojix2
2020-12-17 12:37:27 +09:00
parent cc076d5cfe
commit edd081562e
4 changed files with 40 additions and 18 deletions

View File

@@ -152,17 +152,23 @@ module YouPlot
end
def colors(color_names = false)
# FIXME
s = String.new
UnicodePlot::StyledPrinter::TEXT_COLORS.each do |k, v|
print v
print k
s << v
s << k.to_s
unless color_names
print "\t"
print ' ●'
s << "\t"
s << ' ●'
end
print "\033[0m"
print "\t"
s << "\033[0m"
s << "\t"
end
puts
s << "\n"
def s.render(obj)
obj.print(self)
end
s
end
def check_series_size(data, fmt)

View File

@@ -28,14 +28,14 @@ module YouPlot
@options ||= parser.options
@params ||= parser.params
if command == :colors
@backend.colors(parser.color_names)
exit
end
# Sometimes the input file does not end with a newline code.
while (input = Kernel.gets(nil))
main(input)
if %i[colors color colours colour].include? @command
plot = create_plot
output_plot(plot)
else
# Sometimes the input file does not end with a newline code.
while (input = Kernel.gets(nil))
main(input)
end
end
end
@@ -75,6 +75,8 @@ module YouPlot
@backend.density(data, params, options[:fmt])
when :box, :boxplot
@backend.boxplot(data, params)
when :colors, :color, :colours, :colour
@backend.colors(options[:color_names])
else
raise "unrecognized plot_type: #{command}"
end

View File

@@ -123,7 +123,7 @@ module YouPlot
scatter s draw a scatter plot
density d draw a density plot
boxplot box draw a horizontal boxplot
colors show the list of available colors
colors color show the list of available colors
count c draw a baplot based on the number of
occurrences (slow)
@@ -252,7 +252,7 @@ module YouPlot
params.xlim = v.take(2)
end
when :colors
when :colors, :color, :colours, :colour
parser.on_head('-n', '--names', 'show color names only', TrueClass) do |v|
@options[:color_names] = v
end