diff --git a/lib/lolcat/cat.rb b/lib/lolcat/cat.rb index dedfbe9..09c3a6f 100644 --- a/lib/lolcat/cat.rb +++ b/lib/lolcat/cat.rb @@ -50,6 +50,7 @@ def self.cat! opt :speed, "Animation speed", :short => 's', :default => 20.0 opt :invert, "Invert fg and bg", :short => 'i', :default => false opt :truecolor, "24-bit (truecolor)", :short => 't', :default => false + opt :rgbcolor, "Use 256 colors (disable truecolor)", :short => 'r', :default => false opt :force, "Force color even when stdout is not a tty", :short => 'f', :default => false opt :version, "Print version and exit", :short => 'v' opt :help, "Show this message", :short => 'h' diff --git a/lib/lolcat/lol.rb b/lib/lolcat/lol.rb index a487b01..110d21e 100644 --- a/lib/lolcat/lol.rb +++ b/lib/lolcat/lol.rb @@ -78,7 +78,7 @@ def self.println(str, defaults={}, opts={}) def self.println_plain(str, defaults={}, opts={}, chomped) opts.merge!(defaults) - set_mode(opts[:truecolor]) unless @paint_init + set_mode(opts[:truecolor], opts[:rgbcolor]) unless @paint_init filtered = str.scan(ANSI_ESCAPE) filtered.each_with_index do |c, i| color = rainbow(opts[:freq], @os+i/opts[:spread]) @@ -112,11 +112,19 @@ def self.println_ani(str, opts={}, chomped) @os = @real_os end - def self.set_mode(truecolor) + def self.set_mode(truecolor, rgbcolor) # @paint_mode_detected = Paint.mode @paint_mode_detected = %w[truecolor 24bit].include?(ENV['COLORTERM']) ? 0xffffff : 256 Paint.mode = truecolor ? 0xffffff : @paint_mode_detected STDERR.puts "DEBUG: Paint.mode = #{Paint.mode} (detected: #{@paint_mode_detected})" if ENV['LOLCAT_DEBUG'] + if rgbcolor then + unless Paint.mode == 256 then + Paint.mode = 256 + STDERR.puts "DEBUG: rgbcolor Paint.mode set to 256" if ENV['LOLCAT_DEBUG'] + else + STDERR.puts "DEBUG: rgbcolor Paint.mode already 256" if ENV['LOLCAT_DEBUG'] + end + end @paint_init = true end end