mcthomas / Apple-Music-CLI-Player

A simple command-line Apple Music controller script which includes a "Now Playing" widget function, a playback function, and a list-out function for your Mac's Music.app library, written in sh.
MIT License
107 stars 10 forks source link

Fix for flickering output in np widget #6

Open varon opened 1 year ago

varon commented 1 year ago

By issuing the 'clear' command, depending on the terminal implementation, the screen can flicker if the terminal takes some time to draw the next characters.

The correct fix is not to clear the screen, but instead to manipulate the cursor to place it at the top, then simply re-draw. This avoids any flickering in the output.

This fix should address that for the terminal player.

Thanks again for making such a great, simple tool. It was easy to make this change.

varon commented 1 year ago

Looks like this runs into some edge cases where song names change. Marking this as a draft for now.

mcthomas commented 1 year ago

Currently, similar to the concept of double buffering, I have clear called immediately before drawing (as part of the buffer to be drawn, and also in the case of text mode just before outputting the playback information).

So I think you'd want that escape sequence in the $art buffer, in place of clear. Currently in this diff it is just called for the case of the -t text mode flag. I don't know what effect this will have, but please feel free to update the pr if you see the issue resolve in terminal emulators with that change, I'd be thrilled to merge it in. But I haven't messed with that escape sequence myself.