Skip to content

Updated playerctl script to allow scrolling text #273

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

Merged
merged 5 commits into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions scripts/playerctl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,59 @@
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8

current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source $current_dir/utils.sh

main()
{
function slice_loop() {
local str="$1"
local start="$2"
local how_many="$3"
local len=${#str}

local result=""

for ((i = 0; i < how_many; i++)); do
local index=$(((start + i) % len))
local char="${str:index:1}"
result="$result$char"
done

echo "$result"
}

main() {
# storing the refresh rate in the variable RATE, default is 5
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)

if ! command -v playerctl &> /dev/null
then
if ! command -v playerctl &>/dev/null; then
exit 1
fi

FORMAT=$(get_tmux_option "@dracula-playerctl-format" "Now playing: {{ artist }} - {{ album }} - {{ title }}")
playerctl_playback=$(playerctl metadata --format "${FORMAT}")
echo ${playerctl_playback}
playerctl_playback="${playerctl_playback} "

# Adjust width of string
terminal_width=25

# Initial start point for scrolling
start=0
len=${#playerctl_playback}

scrolling_text=""

for ((start = 0; start <= len; start++)); do
scrolling_text=$(slice_loop "$playerctl_playback" "$start" "$terminal_width")
echo -ne "\r"
echo "$scrolling_text "
echo -ne "\r"

sleep 0.08
done

echo -ne "\r"
echo "$scrolling_text "
echo -ne "\r"
}

# run the main driver
Expand Down