lolcat animation breaks in kitty
Luflosi opened this issue · comments
Currently lolcat -a
breaks horribly in kitty because of how the DECSC and DECRC escape sequences are used, see kovidgoyal/kitty#2813.
lolcat currently saves the cursor position only once with DECSC and then restores it many times with DECRC. Since the standard seems to leave some room for interpretation, kitty expects every DECRC to have a corresponding DECSC some time earlier.
I wrote two alternative patches that fix the issue. I'm very sure, that the second patch will not break anything for other terminals. These are the very first lines of Ruby I wrote, so keep that in mind.
--- a/lib/lolcat/lol.rb
+++ b/lib/lolcat/lol.rb
@@ -103,13 +103,14 @@ module Lol
print "\e7"
@real_os = @os
(1..opts[:duration]).each do |i|
- print "\e8"
+ print "\e8\e7"
@os += opts[:spread]
println_plain(str, opts, chomped)
str.gsub!(/\e\[[0-?]*[@JKPX]/, "")
sleep 1.0/opts[:speed]
end
@os = @real_os
+ print "\e8"
end
def self.set_mode(truecolor)
--- a/lib/lolcat/lol.rb
+++ b/lib/lolcat/lol.rb
@@ -100,10 +100,14 @@ module Lol
def self.println_ani(str, opts={}, chomped)
return if str.empty?
- print "\e7"
@real_os = @os
(1..opts[:duration]).each do |i|
- print "\e8"
+ if i > 1
+ print "\e8"
+ end
+ if i < opts[:duration]
+ print "\e7"
+ end
@os += opts[:spread]
println_plain(str, opts, chomped)
str.gsub!(/\e\[[0-?]*[@JKPX]/, "")
The first patch looks nicer but resets the cursor position after the line is finished printing, which may or may not be a problem. It also saves and restores the cursor unnecessarily multiple times.
The second patch fixes this but looks overly complicated. There is probably a nicer way to do this.