- 
                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 5 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 | ||
| 
          
            
          
           | 
    @@ -185,6 +184,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 | ||
| 
        
          
        
         | 
    @@ -206,7 +224,9 @@ main() { | |
| 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 | ||
| 
        
          
        
         | 
    @@ -217,15 +237,23 @@ main() { | |
| # Remote Access | ||
| if [[ "$REMOTE_ACCESS" == true ]]; then | ||
| remoteControl "$PLAY_PAUSE_BUTTON" "$BACK_BUTTON" "$NEXT_BUTTON" "$REMOTE_APP" | ||
| 
     | 
||
| fi | ||
| 
     | 
||
| if [ ! -f "$cache_file" ] || [ $(($(date +%s) - $(stat -f%c "$cache_file"))) -ge "$RATE" ]; then | ||
| trackStatus "$PAUSE_ICON" "$PLAY_ICON" > "$cache_file" | ||
| sliceTrack "$(cat $cache_file)" "$MAX_LENGTH" > "$cache_file" | ||
| trackStatus "$PAUSE_ICON" "$PLAY_ICON" >"$cache_file" | ||
| 
     | 
||
| if [ "$SCROLL" = false ]; then | ||
| sliceTrack "$(cat $cache_file)" "$MAX_LENGTH" >"$cache_file" | ||
| fi | ||
| 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