diff --git a/polybar-scripts/player-mpris-tail/README.md b/polybar-scripts/player-mpris-tail/README.md index c6726091..2499c3ab 100644 --- a/polybar-scripts/player-mpris-tail/README.md +++ b/polybar-scripts/player-mpris-tail/README.md @@ -52,6 +52,8 @@ Argument | Description | Default -b, --blacklist | Blacklist / Ignore the given player -w, --whitelist | Whitelist / Permit the given player -f, --format | Use the given `format` string | `{icon} {artist} - {title}` +-s, --scroll | set when to start scrolling, 0 means no scrolling | 0 +--scroll-speed | delay in ms until the next character is shown. | 250 --truncate-text | Use the given string as the end of truncated text | `…` --icon-playing | Use the given text as the playing icon | `⏵` --icon-paused | Use the given text as the paused icon | `⏸` @@ -110,6 +112,16 @@ tail = true Example: `⏵ Artist - Title` +### Basic output that starts to scroll if the output is longer than 30 characters + +```ini +[module/player-mpris-tail] +type = custom/script +exec = ~/polybar-scripts/player-mpris-tail.py -f '{icon} {artist} - {title}' --scroll=30 --scroll-speed=300 +tail = true +``` + +Example: `tist - Title --- A` ### Basic output and mouse controls diff --git a/polybar-scripts/player-mpris-tail/player-mpris-tail.py b/polybar-scripts/player-mpris-tail/player-mpris-tail.py old mode 100755 new mode 100644 index 6d2cb2b1..a25c6463 --- a/polybar-scripts/player-mpris-tail/player-mpris-tail.py +++ b/polybar-scripts/player-mpris-tail/player-mpris-tail.py @@ -474,14 +474,45 @@ def __missing__(self, key): Seems to assure print() actually prints when no terminal is connected """ +SCROLL_CHARACTER_LIMIT = 30 +currentScrollCharacter = 0 +timeoutReference = "" +SCROLL_SPEED = 250 _last_status = '' def _printFlush(status, **kwargs): global _last_status + global SCROLL_CHARACTER_LIMIT + global timeoutReference if status != _last_status: - print(status, **kwargs) - sys.stdout.flush() + if timeoutReference != "": + GLib.source_remove(timeoutReference) + timeoutReference = "" + if SCROLL_CHARACTER_LIMIT != 0 and len(status)>SCROLL_CHARACTER_LIMIT: + _printScrolling(status +" ---", **kwargs) + else: + print(status, **kwargs) + sys.stdout.flush() + _last_status = status +def _printScrolling(string, **kwargs): + global SCROLL_CHARACTER_LIMIT + global currentScrollCharacter + global SCROLL_SPEED + global timeoutReference + printString = string[currentScrollCharacter:currentScrollCharacter+SCROLL_CHARACTER_LIMIT] + + if SCROLL_CHARACTER_LIMIT + currentScrollCharacter > len(string): + + rolloverAmmount = SCROLL_CHARACTER_LIMIT + currentScrollCharacter - len(string) + printString += string[0: rolloverAmmount] + print(printString,**kwargs) + sys.stdout.flush() + if(currentScrollCharacter