-
Notifications
You must be signed in to change notification settings - Fork 338
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 all commits
34b3579
8763e9d
fc5efb1
a8deaec
f829cc0
a149f17
dec42b4
e0b5235
8057a9c
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) | ||||||||||||||||||||||||
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. don't forget this too |
||||||||||||||||||||||||
SCROLL_SPEED=$(get_tmux_option "@dracula-mac-player-scroll-speed" 0.08) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
# os checker | ||||||||||||||||||||||||
if [[ "$OSTYPE" != "darwin"* ]]; then | ||||||||||||||||||||||||
exit 1 | ||||||||||||||||||||||||
|
@@ -227,12 +254,22 @@ 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" = "true" ] && [ "${#str}" -ge $MAX_LENGTH ]; then | ||||||||||||||||||||||||
echo "$full_track" > "$cache_file" | ||||||||||||||||||||||||
else | ||||||||||||||||||||||||
sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file" | ||||||||||||||||||||||||
fi | ||||||||||||||||||||||||
Comment on lines
+258
to
+263
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. Bug: using ${#str} before str is defined; cache logic doesn’t update for SCROLL=true str is only populated later (Line 267). This condition always evaluates with an empty str, leading to stale/missing cache entries when SCROLL=true. Also prefer printf over echo for exact writes and quote MAX_LENGTH in numeric tests. - if [ "$SCROLL" = "true" ] && [ "${#str}" -ge $MAX_LENGTH ]; then
- echo "$full_track" > "$cache_file"
- else
- sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"
- fi
+ if [ "$SCROLL" = "true" ] && [ "${#full_track}" -ge "$MAX_LENGTH" ]; then
+ printf "%s" "$full_track" > "$cache_file"
+ else
+ sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"
+ fi 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||
fi | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
cat "$cache_file" | ||||||||||||||||||||||||
# Allow scrolling | ||||||||||||||||||||||||
local str=$(cat "$cache_file") | ||||||||||||||||||||||||
if [ "$SCROLL" = "true" ]; then | ||||||||||||||||||||||||
scroll "$str" "$MAX_LENGTH" "$SCROLL_SPEED" | ||||||||||||||||||||||||
else | ||||||||||||||||||||||||
echo "$str" | ||||||||||||||||||||||||
fi | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
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