Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/lolcat/cat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
12 changes: 10 additions & 2 deletions lib/lolcat/lol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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