From 5320b551c153330fdcfc2e6ec272833f48d83d5b Mon Sep 17 00:00:00 2001 From: Marcos Cevallos Date: Mon, 15 Jul 2024 15:53:30 -0400 Subject: [PATCH 1/5] Updated player ctl script for scrolling --- scripts/playerctl.sh | 64 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/scripts/playerctl.sh b/scripts/playerctl.sh index a813a5ea..4a9fe262 100755 --- a/scripts/playerctl.sh +++ b/scripts/playerctl.sh @@ -2,23 +2,71 @@ # 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" +} + +function update_playerctl_playback() { + FORMAT=$(get_tmux_option "@dracula-playerctl-format" "Now playing: {{ artist }} - {{ album }} - {{ title }}") + + playerctl_playback=$(playerctl metadata --format "${FORMAT}") + msg="${playerctl_playback}" + + len=${#msg} +} + +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} + update_playerctl_playback + window_size=25 # Number of characters to display at once + begin=0 + + while true; do + slice=$(slice_loop "$msg" $begin $window_size) + echo -ne " \r" + echo -n "$slice" + echo -ne "\r" + sleep 0.1 + + ((begin++)) + + # Check if playerctl_playback has changed + updated_msg=$(playerctl metadata --format "${FORMAT}") + updated_msg="$updated_msg " + + if [ "$updated_msg" != "$playerctl_playback" ]; then + playerctl_playback="$updated_msg" + + msg="$playerctl_playback" + + len=${#msg} + begin=0 + sleep 1 + fi + done } # run the main driver From 16929611b1d239de2e1602b3c360ce23d34f2602 Mon Sep 17 00:00:00 2001 From: Marcos Cevallos Date: Mon, 15 Jul 2024 17:46:02 -0400 Subject: [PATCH 2/5] Updated player ctl --- scripts/playerctl.sh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/playerctl.sh b/scripts/playerctl.sh index 4a9fe262..9ba8c304 100755 --- a/scripts/playerctl.sh +++ b/scripts/playerctl.sh @@ -44,7 +44,20 @@ main() { begin=0 while true; do - slice=$(slice_loop "$msg" $begin $window_size) + # Check if playerctl metadata command is available + if ! command -v playerctl metadata &>/dev/null; then + echo "" + exit 1 + fi + + # Slice the message to display + if [ "$len" -le "$window_size" ]; then + # If msg length is smaller than window_size, display the entire msg + slice="$msg" + else + slice=$(slice_loop "$msg" $begin $window_size) + fi + echo -ne " \r" echo -n "$slice" echo -ne "\r" @@ -58,15 +71,13 @@ main() { if [ "$updated_msg" != "$playerctl_playback" ]; then playerctl_playback="$updated_msg" - msg="$playerctl_playback" - len=${#msg} - begin=0 sleep 1 fi done + } # run the main driver From d796fa2b1e73678250429b75aef1065cd7d21a62 Mon Sep 17 00:00:00 2001 From: Marcos Cevallos Date: Mon, 15 Jul 2024 18:50:07 -0400 Subject: [PATCH 3/5] Updated the player to be shorter and better --- scripts/playerctl.sh | 67 ++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 43 deletions(-) diff --git a/scripts/playerctl.sh b/scripts/playerctl.sh index 9ba8c304..227ba87b 100755 --- a/scripts/playerctl.sh +++ b/scripts/playerctl.sh @@ -22,15 +22,6 @@ function slice_loop() { echo "$result" } -function update_playerctl_playback() { - FORMAT=$(get_tmux_option "@dracula-playerctl-format" "Now playing: {{ artist }} - {{ album }} - {{ title }}") - - playerctl_playback=$(playerctl metadata --format "${FORMAT}") - msg="${playerctl_playback}" - - len=${#msg} -} - main() { # storing the refresh rate in the variable RATE, default is 5 RATE=$(get_tmux_option "@dracula-refresh-rate" 5) @@ -39,45 +30,35 @@ main() { exit 1 fi - update_playerctl_playback - window_size=25 # Number of characters to display at once - begin=0 - - while true; do - # Check if playerctl metadata command is available - if ! command -v playerctl metadata &>/dev/null; then - echo "" - exit 1 - fi - - # Slice the message to display - if [ "$len" -le "$window_size" ]; then - # If msg length is smaller than window_size, display the entire msg - slice="$msg" - else - slice=$(slice_loop "$msg" $begin $window_size) - fi - - echo -ne " \r" - echo -n "$slice" + FORMAT=$(get_tmux_option "@dracula-playerctl-format" "Now playing: {{ artist }} - {{ album }} - {{ title }}") + playerctl_playback=$(playerctl metadata --format "${FORMAT}") + playerctl_playback="${playerctl_playback} " + + # Determine the length of the terminal window (not implemented here) + # Adjust 'terminal_width' based on your actual terminal width + terminal_width=25 + + # Initial start point for scrolling + start=0 + len=${#playerctl_playback} + + scrolling_text="" + + for ((i = 0; i <= len; i++)); do + # Slice the string starting from 'start' index and display 'terminal_width' characters + scrolling_text=$(slice_loop "$playerctl_playback" "$start" "$terminal_width") + echo -ne "\r" + echo "$scrolling_text" echo -ne "\r" - sleep 0.1 - ((begin++)) + # Check if the beginning of the original string reappears at the start of the visible area - # Check if playerctl_playback has changed - updated_msg=$(playerctl metadata --format "${FORMAT}") - updated_msg="$updated_msg " + # Update the start index for the next iteration + ((start++)) - if [ "$updated_msg" != "$playerctl_playback" ]; then - playerctl_playback="$updated_msg" - msg="$playerctl_playback" - len=${#msg} - begin=0 - sleep 1 - fi + # Sleep for RATE seconds before updating the display (adjust RATE as needed) + sleep 0.08 done - } # run the main driver From 6d7809eb289764ed541186901818b6988e465346 Mon Sep 17 00:00:00 2001 From: Marcos Cevallos Date: Mon, 15 Jul 2024 18:59:56 -0400 Subject: [PATCH 4/5] Updated the playerctl.sh --- scripts/playerctl.sh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/scripts/playerctl.sh b/scripts/playerctl.sh index 227ba87b..f9c7e180 100755 --- a/scripts/playerctl.sh +++ b/scripts/playerctl.sh @@ -35,7 +35,7 @@ main() { playerctl_playback="${playerctl_playback} " # Determine the length of the terminal window (not implemented here) - # Adjust 'terminal_width' based on your actual terminal width + # Adjust width of string terminal_width=25 # Initial start point for scrolling @@ -44,21 +44,20 @@ main() { scrolling_text="" - for ((i = 0; i <= len; i++)); do + for ((start = 0; start <= len; start++)); do # Slice the string starting from 'start' index and display 'terminal_width' characters scrolling_text=$(slice_loop "$playerctl_playback" "$start" "$terminal_width") echo -ne "\r" - echo "$scrolling_text" + echo "$scrolling_text " echo -ne "\r" - # Check if the beginning of the original string reappears at the start of the visible area - - # Update the start index for the next iteration - ((start++)) - # Sleep for RATE seconds before updating the display (adjust RATE as needed) sleep 0.08 done + + echo -ne "\r" + echo "$scrolling_text " + echo -ne "\r" } # run the main driver From dae8e6a019d48a9e1a51ef96562413c045f71b5f Mon Sep 17 00:00:00 2001 From: Marcos Cevallos Date: Mon, 15 Jul 2024 19:05:23 -0400 Subject: [PATCH 5/5] Removed useless comments --- scripts/playerctl.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/playerctl.sh b/scripts/playerctl.sh index f9c7e180..70e94729 100755 --- a/scripts/playerctl.sh +++ b/scripts/playerctl.sh @@ -34,7 +34,6 @@ main() { playerctl_playback=$(playerctl metadata --format "${FORMAT}") playerctl_playback="${playerctl_playback} " - # Determine the length of the terminal window (not implemented here) # Adjust width of string terminal_width=25 @@ -45,13 +44,11 @@ main() { scrolling_text="" for ((start = 0; start <= len; start++)); do - # Slice the string starting from 'start' index and display 'terminal_width' characters scrolling_text=$(slice_loop "$playerctl_playback" "$start" "$terminal_width") echo -ne "\r" echo "$scrolling_text " echo -ne "\r" - # Sleep for RATE seconds before updating the display (adjust RATE as needed) sleep 0.08 done