Skip to content

Commit

Permalink
Fix support for legacy terminals (Urxvt)
Browse files Browse the repository at this point in the history
Thanks to u/katie-is-gay for tracking this down:
https://www.reddit.com/r/archlinux/comments/cnvlsa/lolcat_colors_glitched_only_at_urxvt/ewelhfn

And to @incomingstick for reporting it:
busyloop#99

Also thanks to @XVilka for maintaining an absurdly
comprehensive guide on Truecolor terminal support:
https://gist.github.com/XVilka/8346728

TLDR: We no longer rely on 24bit auto-detection by the Paint gem.
Lolcat now performs its own detection and otherwise defaults 256 colors.

The auto-detection is only a qualified guess.
Use the -t flag to ensure highest rainbow fidelity.

Fixes busyloop#97
  • Loading branch information
m-o-e committed Aug 12, 2019
1 parent 971c704 commit 7d96dca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lib/lolcat/lol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ module Lol
ANSI_ESCAPE = /((?:\e(?:[ -\/]+.|[\]PX^_][^\a\e]*|\[[0-?]*.|.))*)(.?)/m
INCOMPLETE_ESCAPE = /\e(?:[ -\/]*|[\]PX^_][^\a\e]*|\[[0-?]*)$/

@paint_detected_mode = Paint.detect_mode
@os = 0
@paint_init = false

def self.rainbow(freq, i)
red = Math.sin(freq*i + 0) * 127 + 128
Expand Down 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])
set_mode(opts[:truecolor]) 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 @@ -113,7 +113,10 @@ def self.println_ani(str, opts={}, chomped)
end

def self.set_mode(truecolor)
@paint_mode_detected ||= Paint.mode
# @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']
@paint_init = true
end
end
2 changes: 1 addition & 1 deletion lib/lolcat/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Lolcat
VERSION = "99.9.99"
VERSION = "100.0.0"
end
2 changes: 1 addition & 1 deletion lolcat.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.summary = %q{Okay, no unicorns. But rainbows!!}

s.add_development_dependency "rake"
s.add_dependency "paint", "~> 2.0.0"
s.add_dependency "paint", "~> 2.1.0"
s.add_dependency "optimist", "~> 3.0.0"
s.add_dependency "manpages", "~> 0.6.1"

Expand Down

0 comments on commit 7d96dca

Please sign in to comment.