aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYaroslav de la Peña Smirnov <yps@yaroslavps.com>2022-11-20 02:57:10 +0300
committerYaroslav de la Peña Smirnov <yps@yaroslavps.com>2022-11-20 02:57:10 +0300
commitef03c3e6614481154c015487f87cf27a5ed788b7 (patch)
treeb225445a37b5d5071746bed3178f6e92a9a288b3
parent387fd15bf231e1cf38eaa7ad1543aaf911a4325e (diff)
downloadwaybar-mpris-new-fmt.tar.gz
waybar-mpris-new-fmt.zip
Add flag to limit the length of the titlenew-fmt
-rw-r--r--README.md2
-rw-r--r--main.go9
2 files changed, 10 insertions, 1 deletions
diff --git a/README.md b/README.md
index 0a8712c..b617c52 100644
--- a/README.md
+++ b/README.md
@@ -60,6 +60,7 @@ When running, the program will pipe out json in waybar's format. Add something l
Usage of ./waybar-mpris:
--autofocus Auto switch to currently playing music players.
--interpolate Interpolate track position (helpful for players that don't update regularly, e.g mpDris2)
+ --max-title int Maximum length of title. If the title's longer N-3 characters will be printed and ... will be printed at the end. (default 70)
--pause string Pause symbol/text to use. (default "\uf8e3")
--play string Play symbol/text to use. (default "▶")
--replace Replace existing waybar-mpris if found. When false, new instance will clone the original instances output.
@@ -83,6 +84,7 @@ Usage of ./waybar-mpris:
* `--autofocus` makes waybar-mpris automatically focus on currently playing music players.
* `--position` enables the display of the track position.
* `--interpolate` increments the track position every second. This is useful for players (e.g mpDris2) that don't regularly update the position.
+* `--max-title` the maximum number of characters before the title cuts off.
* `--replace`: By default, new instances will attach to the existing one so that the output is identical. This lets this instance replace any others running. It isn't recommended.
* `--send` sends commands to an already running waybar-mpris instance via a unix socket. Commands:
* `player-next`: Switch to displaying and controlling next available player.
diff --git a/main.go b/main.go
index 4593ca2..7597155 100644
--- a/main.go
+++ b/main.go
@@ -41,6 +41,7 @@ var (
replace = false
isSharing = false
isDataSharing = false
+ maxTitleLen = 70
writer io.Writer = os.Stdout
shareWriter, dataWriter io.Writer
)
@@ -184,7 +185,11 @@ func formatOutput(p *player, icon string, fstr string) string {
case tokAlbum:
buf = append(buf, []byte(p.Album)...)
case tokTitle:
- buf = append(buf, []byte(p.Title)...)
+ title := p.Title
+ if maxTitleLen > 0 && len(title) > maxTitleLen {
+ title = title[:maxTitleLen-3] + "..."
+ }
+ buf = append(buf, []byte(title)...)
case tokPosition:
position := secondsToString(int(p.Position / 1000000))
buf = append(buf, []byte(position)...)
@@ -571,6 +576,8 @@ func main() {
"Interpolate track position (helpful for players that don't update regularly, e.g mpDris2)")
flag.BoolVar(&replace, "replace", replace,
"Replace existing waybar-mpris if found. When false, new instance will clone the original instances output.")
+ flag.IntVar(&maxTitleLen, "max-title", maxTitleLen,
+ "Maximum length of title. If the title's longer N-3 characters will be printed and ... will be printed at the end.")
var command string
flag.StringVar(&command, "send", "", "send command to already runnning waybar-mpris instance. (options: "+strings.Join(commands, "/")+")")