Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lolcat animation breaks in kitty #116

Open
Luflosi opened this issue Jun 29, 2020 · 0 comments
Open

lolcat animation breaks in kitty #116

Luflosi opened this issue Jun 29, 2020 · 0 comments

Comments

@Luflosi
Copy link

Luflosi commented Jun 29, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant