-
Notifications
You must be signed in to change notification settings - Fork 348
Added scrolling text to Mac player module and cleaned up functions #356
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
base: master
Are you sure you want to change the base?
Changes from 7 commits
34b3579
8763e9d
fc5efb1
a8deaec
f829cc0
a149f17
dec42b4
e0b5235
8057a9c
a65d4d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,8 +3,7 @@ | |||||||||||||||||||||||||||||||||||||||||
| export LC_ALL=en_US.UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||||||||||||||||||||||||||||||||||||||||||
| source "$current_dir/utils.sh" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| source $current_dir/utils.sh | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| function trackStatus() { | ||||||||||||||||||||||||||||||||||||||||||
| local active_player | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -186,6 +185,25 @@ function remoteControl() { | |||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Scroll the text | ||||||||||||||||||||||||||||||||||||||||||
| function scroll() { | ||||||||||||||||||||||||||||||||||||||||||
| local str=$1 | ||||||||||||||||||||||||||||||||||||||||||
| local width=$2 | ||||||||||||||||||||||||||||||||||||||||||
| local speed=$3 | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| local scrolling_text="" | ||||||||||||||||||||||||||||||||||||||||||
| local i=0 | ||||||||||||||||||||||||||||||||||||||||||
| local len=${#str} | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| for ((i = 0; i <= len; i++)); do | ||||||||||||||||||||||||||||||||||||||||||
| scrolling_text=$(slice_text "$str" "$i" "$width") | ||||||||||||||||||||||||||||||||||||||||||
| printf "\r%s " "$scrolling_text" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| sleep "$speed" | ||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| printf "\r%s " "$scrolling_text" | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+188
to
207
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion
A safer, non-blocking alternative is to compute the start index from the current epoch modulo -function scroll() {
- local str=$1
- local width=$2
- local speed=$3
-
- local len=${#str}
- for ((i = 0; i < len; i++)); do
- printf "\r%s " "$(slice_text "$str" "$i" "$width")"
- sleep "$speed"
- done
-}
+scroll() {
+ local str=$1 width=$2 speed=$3
+ local len=${#str}
+
+ # Calculate frame based on time so the function prints *once* per call.
+ local frame=$(( $(date +%s%N) / $(printf '1%0.s' {1..${#speed}}) % len ))
+ echo "$(slice_text "$str" "$frame" "$width")"
+}This keeps runtime ~ 1 ms, eliminates overlap and yields smooth, continuous scrolling.
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
| main() { | ||||||||||||||||||||||||||||||||||||||||||
| # save buffer to prevent lag | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -202,6 +220,15 @@ main() { | |||||||||||||||||||||||||||||||||||||||||
| REMOTE_ACCESS=$(get_tmux_option "@dracula-mac-player-remote" "false") | ||||||||||||||||||||||||||||||||||||||||||
| REMOTE_APP=$(get_tmux_option "@dracula-mac-player-app" "Spotify") | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Remote Control Buttons Customizations | ||||||||||||||||||||||||||||||||||||||||||
| PLAY_PAUSE_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-play-pause" "P") | ||||||||||||||||||||||||||||||||||||||||||
| BACK_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-back" "R") | ||||||||||||||||||||||||||||||||||||||||||
| NEXT_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-next" "N") | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Scroll | ||||||||||||||||||||||||||||||||||||||||||
| SCROLL=$(get_tmux_option "@dracula-mac-player-scroll" false) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
| SCROLL_SPEED=$(get_tmux_option "@dracula-mac-player-scroll-speed" 0.08) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # os checker | ||||||||||||||||||||||||||||||||||||||||||
| if [[ "$OSTYPE" != "darwin"* ]]; then | ||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -227,12 +254,20 @@ main() { | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if [ ! -f "$cache_file" ] || [ $(($(date +%s) - $(stat -f%c "$cache_file"))) -ge "$RATE" ]; then | ||||||||||||||||||||||||||||||||||||||||||
| local full_track | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| full_track=$(trackStatus "$PAUSE_ICON" "$PLAY_ICON") | ||||||||||||||||||||||||||||||||||||||||||
| sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if [ "$SCROLL" = false ]; then | ||||||||||||||||||||||||||||||||||||||||||
| sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file" | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When SCROLL=true the cache is never updated, causing stale or missing output Inside the refresh window you compute full_track but only write to cache when SCROLL=false. On first run with SCROLL=true, cat "$cache_file" can fail; on subsequent runs the scroller may display stale text. Write the cache in both modes: truncated when SCROLL=false, full text when SCROLL=true. if [ ! -f "$cache_file" ] || [ $(($(date +%s) - $(stat -f%c "$cache_file"))) -ge "$RATE" ]; then
local full_track
full_track=$(trackStatus "$PAUSE_ICON" "$PLAY_ICON")
-
- if [ "$SCROLL" = false ]; then
- sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"
- fi
+ if [ "$SCROLL" = true ]; then
+ printf "%s" "$full_track" > "$cache_file"
+ else
+ sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"
+ fi
fi📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| cat "$cache_file" | ||||||||||||||||||||||||||||||||||||||||||
| # Allow scrolling | ||||||||||||||||||||||||||||||||||||||||||
| local str=$(cat "$cache_file") | ||||||||||||||||||||||||||||||||||||||||||
| if [ "$SCROLL" = true ] && [ "${#str}" -ge $MAX_LENGTH ]; then | ||||||||||||||||||||||||||||||||||||||||||
| scroll "$str" "$MAX_LENGTH" "$SCROLL_SPEED" | ||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||
| echo "$str" | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
LinkUpGames marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| main | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quote the sourced path to avoid breakage on paths containing spaces
Unquoted expansions break if the script is located in a directory with whitespace (e.g. “/Users/al ice/tmux”). Always quote path-like variables when sourcing or executing.
📝 Committable suggestion
🤖 Prompt for AI Agents