-
Notifications
You must be signed in to change notification settings - Fork 346
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
Open
LinkUpGames
wants to merge
10
commits into
dracula:master
Choose a base branch
from
LinkUpGames:music-player-adjustments
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
34b3579
Updated playerctl and mac player modules
LinkUpGames 8763e9d
formatting updated
LinkUpGames fc5efb1
Formatting fixes
LinkUpGames a8deaec
small typo
LinkUpGames f829cc0
Code rabbit typo fixes
LinkUpGames a149f17
Made sure max length is respected for the player
LinkUpGames dec42b4
Merge branch 'master' into music-player-adjustments
LinkUpGames e0b5235
changed to strings
LinkUpGames 8057a9c
Updated logic and simplified final output
LinkUpGames a65d4d6
fixes
LinkUpGames File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,15 +3,14 @@ | |
| 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 | ||
| local active_player | ||
| local pause_icon="$1" | ||
| local play_icon="$2" | ||
|
|
||
| active_player=$(osascript -e " | ||
| active_player=$(osascript -e " | ||
| property playerList : {\"Spotify\", \"Music\", \"Safari\", \"Google Chrome\"} | ||
| property nativePlayerList : {\"Spotify\", \"Music\"} | ||
|
|
||
|
|
@@ -128,20 +127,18 @@ function trackStatus() { | |
| detectPlayer() | ||
| ") | ||
|
|
||
| case "$active_player" in | ||
| "not running") echo "not running" ;; | ||
| "stopped") echo "stopped" ;; | ||
| "can't encode") echo "unable to encode" ;; | ||
| "Not Supported") echo "not supported" ;; | ||
|
|
||
| case "$active_player" in | ||
| "not running") echo "not running" ;; | ||
| "stopped") echo "stopped" ;; | ||
| "can't encode") echo "unable to encode" ;; | ||
| "Not Supported") echo "not supported" ;; | ||
|
|
||
| *) echo "$active_player" ;; | ||
| esac | ||
| *) echo "$active_player" ;; | ||
| esac | ||
LinkUpGames marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| } | ||
|
|
||
| function sliceTrack() | ||
| { | ||
| function sliceTrack() { | ||
| local str="$1" | ||
| local std="$2" | ||
| local len=${#str} | ||
|
|
@@ -158,7 +155,6 @@ function sliceTrack() | |
| echo "$result" | ||
| } | ||
|
|
||
|
|
||
| function remoteControl() { | ||
| toggle_button="$1" | ||
| back_button="$2" | ||
|
|
@@ -185,10 +181,33 @@ 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") | ||
| echo -ne "\r" | ||
| echo "$scrolling_text" | ||
| echo -ne "\r" | ||
|
|
||
| sleep "$speed" | ||
| done | ||
|
|
||
| echo -ne "\r" | ||
| echo "$scrolling_text" | ||
| echo -ne "\r" | ||
| } | ||
|
|
||
| main() { | ||
| # save buffer to prevent lag | ||
| local cache_file="/tmp/tmux_mac_player_cache" | ||
| local cache_file="/tmp/tmux_mac_player_cache" | ||
|
|
||
| RATE=$(get_tmux_option "@dracula-refresh-rate" 5) | ||
|
|
||
|
|
@@ -206,7 +225,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,16 +238,24 @@ 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 | ||
|
|
||
| # Allow scrolling | ||
| local str=$(cat "$cache_file") | ||
| if [ "$SCROLL" = true ]; then | ||
| scroll "$str" "$MAX_LENGTH" "$SCROLL_SPEED" | ||
| else | ||
| echo "$str" | ||
| fi | ||
|
|
||
| cat "$cache_file" | ||
| } | ||
|
|
||
| main | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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