-
Notifications
You must be signed in to change notification settings - Fork 337
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?
Conversation
Made sure that both modules have scrollable text as an option as exposed several other parameters that the user can use to customize
📝 WalkthroughWalkthroughAdds horizontal scrolling support and remote-control option wiring: new scroll implementations in Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant tmuxWidget as Widget Script (mac-player/playerctl)
participant Utils as utils.sh
User->>tmuxWidget: Widget invoked (periodic/tmux trigger)
tmuxWidget->>tmuxWidget: Read tmux options (scroll, width/speed, remote mappings)
alt Scrolling enabled
tmuxWidget->>Utils: slice_text / scroll iterations
Utils-->>tmuxWidget: frame substrings
tmuxWidget->>User: Output animated frames (carriage-return updates)
else Scrolling disabled
tmuxWidget->>User: Output cached/truncated text
end
opt Remote access enabled
User->>tmuxWidget: Remote button press
tmuxWidget->>tmuxWidget: Handle mapped remote action (play/pause/next/back)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
Reverted some formatting changes to previous code
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.
Actionable comments posted: 3
♻️ Duplicate comments (2)
docs/CONFIG.md (1)
691-697
: Same wording issue as abovePlease apply the same wording fix for the playerctl section.
scripts/mac-player.sh (1)
193-203
: Same “newline per frame” issue as in playerctlUse
printf "\r%s " …
instead ofecho
, otherwise the widget spams new lines.
🧹 Nitpick comments (3)
docs/CONFIG.md (1)
580-586
: Grammar / clarity tweak“Lower speeds means faster scroll” → “Lower values mean faster scrolling”.
scripts/playerctl.sh (1)
5-7
: Quote path when sourcing utilitiesIf the path contains spaces the current unquoted
source
fails.-source $current_dir/utils.sh +source "$current_dir/utils.sh"scripts/mac-player.sh (1)
6-6
: Quote utils path for robustness-source $current_dir/utils.sh +source "$current_dir/utils.sh"
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
docs/CONFIG.md
(2 hunks)scripts/mac-player.sh
(4 hunks)scripts/playerctl.sh
(3 hunks)scripts/utils.sh
(1 hunks)
🪛 Shellcheck (0.10.0)
scripts/mac-player.sh
[warning] 255-255: Declare and assign separately to avoid masking return values.
(SC2155)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
scripts/mac-player.sh
[warning] 255-255: Declare and assign separately to avoid masking return values.
(SC2155)
Added a couple fixes suggested by code rabbit
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.
Actionable comments posted: 2
🧹 Nitpick comments (2)
scripts/mac-player.sh (2)
227-230
: Validate@dracula-mac-player-scroll-speed
to prevent invalidsleep
arguments
sleep
accepts only non-negative numbers. If a user sets the option to a negative or non-numeric value the script will exit withsleep: invalid time interval
. Consider clamping or defaulting:case $SCROLL_SPEED in ''|*[!0-9.]*|-* ) SCROLL_SPEED=0.08 ;; esac
251-256
: Avoid SC2155 & fork-less read for cache content
Assigning and declaring in one line hides the exit status and thecat
fork is unnecessary.- local str=$(cat "$cache_file") + local str + IFS= read -r str <"$cache_file"Reduces process count and keeps shellcheck quiet.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
scripts/mac-player.sh
(4 hunks)scripts/playerctl.sh
(3 hunks)scripts/utils.sh
(1 hunks)
🪛 Shellcheck (0.10.0)
scripts/mac-player.sh
[warning] 251-251: Declare and assign separately to avoid masking return values.
(SC2155)
🚧 Files skipped from review as they are similar to previous changes (2)
- scripts/utils.sh
- scripts/playerctl.sh
🧰 Additional context used
🪛 Shellcheck (0.10.0)
scripts/mac-player.sh
[warning] 251-251: Declare and assign separately to avoid masking return values.
(SC2155)
@@ -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 |
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.
-source $current_dir/utils.sh
+source "$current_dir/utils.sh"
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
source $current_dir/utils.sh | |
source "$current_dir/utils.sh" |
🤖 Prompt for AI Agents
In scripts/mac-player.sh at line 6, the sourced path variable $current_dir is
not quoted, which can cause the script to break if the directory path contains
spaces. Fix this by enclosing $current_dir/utils.sh in double quotes when using
source, like source "$current_dir/utils.sh", to ensure the path is correctly
interpreted even with spaces.
# 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" | ||
} | ||
|
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.
🛠️ Refactor suggestion
scroll()
blocks for len*speed
seconds and resets every run – consider a time-based slice instead
The current loop:
- Sleeps
len
times, so a 60-char title at0.08s
stalls the script for almost 5 s – longer than the default refresh rate and likely to spawn overlapping processes. - Restarts from index 0 on every invocation, causing a “jump” rather than seamless scroll.
- Uses
<= len
; wheni == len
the slice starts at the terminating NUL, returning an empty string.
A safer, non-blocking alternative is to compute the start index from the current epoch modulo len
, output one slice, and let tmux refresh drive the animation:
-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.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In scripts/mac-player.sh around lines 187 to 206, the scroll() function blocks
execution for len*speed seconds and restarts the scroll from index 0 each time,
causing jumps and potential overlapping processes. To fix this, refactor
scroll() to compute the start index based on the current epoch time modulo the
string length, output only one slice per call, and remove the loop and sleep
calls. This change will make scrolling non-blocking, smooth, and continuous,
relying on external refresh timing to drive the animation.
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.
Actionable comments posted: 0
♻️ Duplicate comments (2)
scripts/mac-player.sh (2)
6-6
: Quote$current_dir
when sourcing – unresolved from previous review
The path is still unquoted, so the script breaks if its directory contains spaces.-source $current_dir/utils.sh +source "$current_dir/utils.sh"
187-205
:scroll()
blocks for len × speed seconds and restarts every call – re-implement as a non-blocking, time-based slice
Running a full loop withsleep
inside a status-line script stalls tmux, spawns overlapping processes and consumes CPU. It also “jumps” back to index 0 on every refresh.Replace the loop with a single, time-derived frame calculation:
-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" -} +scroll() { + local str=$1 width=$2 speed=$3 + local len=${#str} + + # Frame index based on current time → smooth & stateless + # Using nanoseconds divided by speed-in-µs to get a rolling counter. + local frame=$(( ( $(date +%s%N) / $(printf '%d' "$(awk 'BEGIN{printf "%d",'"$speed"'*1000000}')") ) % len )) + + printf "%s" "$(slice_text "$str" "$frame" "$width")" +}Benefits: O(1 ms) runtime, no sleeps, no overlap, continuous scroll.
🧹 Nitpick comments (2)
scripts/mac-player.sh (2)
244-247
: Quote$cache_file
to survive paths with spaces- sliceTrack "$(cat $cache_file)" "$MAX_LENGTH" >"$cache_file" + sliceTrack "$(cat "$cache_file")" "$MAX_LENGTH" >"$cache_file"
250-252
: Separate declaration & command substitution to silence SC2155- local str=$(cat "$cache_file") + local str + str=$(cat "$cache_file")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
scripts/mac-player.sh
(4 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
scripts/mac-player.sh
[warning] 251-251: Declare and assign separately to avoid masking return values.
(SC2155)
🔇 Additional comments (1)
scripts/mac-player.sh (1)
253-256
: Calling the blockingscroll()
here will freeze the status line until it completes
Even with a short title the loop lastslen × speed
seconds (e.g. 3 s for 40 chars × 0.08 s), exceeding normal refresh intervals. Once the refactor above is applied, this concern disappears.
i didn't think about the fact that merging @iberniex plugin improvements would mess with yours. i'm sorry for the merge conflicts. |
Let me try it out :) After he resolves the conflicts |
All good! I'll fix the conflicts later today |
@Theoreticallyhugo @iberniex I fixed the conflicts. Let me know if I'm missing something! |
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.
Actionable comments posted: 1
♻️ Duplicate comments (2)
scripts/mac-player.sh (2)
6-6
: Quote sourced path to handle spaces safelyUnquoted path expansions will break when the script lives in a directory containing spaces.
Apply:
-source $current_dir/utils.sh +source "$current_dir/utils.sh"
188-206
: Scrolling function blocks, restarts every call, and can spawn overlapping processesThe loop sleeps len*speed seconds and reprints multiple frames per invocation. In tmux status scripts, this blocks longer than the refresh interval, leading to overlapping processes and choppy “jump to start” behavior each refresh.
Refactor to print a single frame per call, advance a persisted index, and rely on tmux refresh to animate. This keeps runtime ~ms and scales well. The step heuristics below use RATE and the configured speed to control how many chars to advance each refresh (no floating sleeps needed, compatible with macOS date).
-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" -} +function scroll() { + local str="$1" + local width="$2" + local speed="$3" + + local len=${#str} + # Persist scroll index across invocations to avoid restart "jumps" + local idx_file="/tmp/tmux_mac_player_scroll_idx" + local i=0 + if [[ -f "$idx_file" ]]; then + i=$(cat "$idx_file" 2>/dev/null || echo 0) + fi + # Advance by a step derived from refresh RATE and desired speed. + # At default RATE=5s and speed=0.08, step ~2 chars per refresh. + local rate="${RATE:-5}" + local step + step=$(awk -v r="$rate" -v s="$speed" 'BEGIN{ st=int(1/(r*s)); if (st<1) st=1; print st }') + i=$(( (i + step) % (len>0?len:1) )) + + printf "%s" "$(slice_text "$str" "$i" "$width")" + echo "$i" > "$idx_file" +}Note: If you’ve added a shared scroll helper in utils.sh for playerctl, consider reusing it here to avoid duplication.
🧹 Nitpick comments (2)
scripts/mac-player.sh (2)
223-227
: Redundant re-fetching of remote button optionsYou retrieve these options here and again inside the REMOTE_ACCESS block (Lines 239-243). Single-source them once before the conditional to avoid drift and unnecessary tmux calls.
If you keep the prefetch here, remove the duplicate reads inside the conditional.
264-270
: Fix SC2155 and harden numeric comparisonAvoid declare-and-assign to preserve exit codes (ShellCheck SC2155). Also quote MAX_LENGTH in the numeric test.
- local str=$(cat "$cache_file") - if [ "$SCROLL" = true ] && [ "${#str}" -ge $MAX_LENGTH ]; then + local str + str=$(cat "$cache_file") + if [ "$SCROLL" = true ] && [ "${#str}" -ge "$MAX_LENGTH" ]; then scroll "$str" "$MAX_LENGTH" "$SCROLL_SPEED" else echo "$str" fi
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
docs/CONFIG.md
(2 hunks)scripts/mac-player.sh
(4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- docs/CONFIG.md
🧰 Additional context used
🧬 Code Graph Analysis (1)
scripts/mac-player.sh (1)
scripts/utils.sh (2)
slice_text
(41-65)get_tmux_option
(3-12)
🪛 Shellcheck (0.10.0)
scripts/mac-player.sh
[warning] 265-265: Declare and assign separately to avoid masking return values.
(SC2155)
🔇 Additional comments (1)
scripts/mac-player.sh (1)
228-231
: Config surface looks good; minor note on speed granularityOptions are consistent with playerctl. Be aware that sub-second speed values won’t work with BSD sleep if used directly; the non-blocking refactor above avoids this portability issue entirely.
scripts/mac-player.sh
Outdated
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 comment
The 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
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
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 | |
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" = true ]; then | |
printf "%s" "$full_track" > "$cache_file" | |
else | |
sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file" | |
fi | |
fi |
🤖 Prompt for AI Agents
In scripts/mac-player.sh around lines 255 to 262, you compute full_track only
when the cache is stale but you only write to the cache when SCROLL=false,
leaving the cache missing or stale for SCROLL=true; always write to the cache
after computing full_track: if SCROLL=false write the truncated/sliced version
to "$cache_file", otherwise write the full_track to "$cache_file" (use a safe
redirect/printf to create/overwrite the file) so downstream cat/scroller always
has current content.
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.
This feature is great! just address the condition issue for the cache_file and we're good. I was looking for a better way to make it fluid between renders cause after some time it disappears but it's good as it is for now.
oh I almost forgot so for the scrolling feature you need to wrap the boolean values in strings [ "$SCROLL" = "true"]
and SCROLL=$(get_tmux_option "@dracula-mac-player-scroll" 'false')
cause in bash everything is a string. It something I found out recently when I did the adjustments.
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.
Actionable comments posted: 1
♻️ Duplicate comments (2)
scripts/mac-player.sh (2)
6-6
: Quote the sourced path to avoid breakage on paths containing spacesUnquoted $current_dir will break if the repo path has whitespace.
-source $current_dir/utils.sh +source "$current_dir/utils.sh"
188-206
: scroll() is blocking and will stall the status script; refactor to emit a single frame per callThe loop sleeps for len*speed seconds, causing the script to run for seconds per render. In tmux status, scripts should be fast and return; long-running loops can overlap and degrade UX.
If you want, I can provide a portable, non-blocking implementation that outputs one slice per invocation (driven by tmux’s refresh rate) and persists the offset between calls without relying on nanosecond time (which isn’t available on macOS date).
🧹 Nitpick comments (3)
scripts/mac-player.sh (3)
198-206
: Off-by-one/duplicate frame and redundant final printfLooping with i <= len and then printing scrolling_text again repeats the first frame. Use i < len and drop the last printf.
- for ((i = 0; i <= len; i++)); do + 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"
223-227
: Remote button options: duplication with later block — consider reading onceYou populate PLAY_PAUSE_BUTTON/BACK_BUTTON/NEXT_BUTTON here and again inside the “REMOTE_ACCESS == true” branch (Lines 240-242). Read them once to avoid divergence and unnecessary tmux lookups.
Proposed approach:
- Keep this initialization here.
- Remove the repeated get_tmux_option calls at Lines 240-242 and use the already-read values.
266-272
: ShellCheck SC2155: avoid command substitution in local declaration; also faster file readDeclare then assign. Use bash’s redirection for faster reads. This also keeps return codes clearer.
- local str=$(cat "$cache_file") + local str + str="$(< "$cache_file")" if [ "$SCROLL" = "true" ]; then scroll "$str" "$MAX_LENGTH" "$SCROLL_SPEED" else echo "$str" fi
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
scripts/mac-player.sh
(4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
scripts/mac-player.sh (2)
scripts/playerctl.sh (1)
scroll
(14-32)scripts/utils.sh (2)
slice_text
(41-65)get_tmux_option
(3-12)
🪛 Shellcheck (0.10.0)
scripts/mac-player.sh
[warning] 267-267: Declare and assign separately to avoid masking return values.
(SC2155)
🔇 Additional comments (1)
scripts/mac-player.sh (1)
228-231
: Nice: exposes scroll toggles and speed via tmux optionsClear defaults and easy to override. Matches playerctl behavior for consistency.
|
||
if [ "$SCROLL" = "true" ] && [ "${#str}" -ge $MAX_LENGTH ]; then | ||
echo "$full_track" > "$cache_file" | ||
else | ||
sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file" | ||
fi |
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.
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
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
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 |
🤖 Prompt for AI Agents
In scripts/mac-player.sh around lines 258 to 263, the branch checks ${#str}
before str is defined which always evaluates as zero and causes stale/missing
cache when SCROLL=true; change the check to use the length of the actual string
variable (e.g., ${#full_track}) or move this entire cache-write block to after
str is set, quote MAX_LENGTH in the numeric comparison ([ "${#full_track}" -ge
"$MAX_LENGTH" ]), and use printf '%s' "$full_track" (or the output of
sliceTrack) instead of echo when writing to the cache file so exact content is
written.
Initially, I did some work that added a small scrolling text effect to the
playerctl
plugin last year (#273). I revisited the plugin and decided to do some clean up on it. I decided to expose some more parameters to users such as defining the width of the plugin and also the scrolling speed.Additionally, I love the new Macos player plugin (#343) and decided to also add a similar scrolling effect for users. I exposed the scrolling speed as a parameter for users that wish to have this option on. I believe that since both of these plugins have very similar functions, there should be a common function that can be used to get the scrolling characters on screen. This function was added to the
utils.sh
file.Let me know if you have any questions or if there's something that needs to be fixed up!