diff options
author | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2022-11-20 02:57:10 +0300 |
---|---|---|
committer | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2022-11-20 02:57:10 +0300 |
commit | ef03c3e6614481154c015487f87cf27a5ed788b7 (patch) | |
tree | b225445a37b5d5071746bed3178f6e92a9a288b3 /main.go | |
parent | 387fd15bf231e1cf38eaa7ad1543aaf911a4325e (diff) | |
download | waybar-mpris-ef03c3e6614481154c015487f87cf27a5ed788b7.tar.gz waybar-mpris-ef03c3e6614481154c015487f87cf27a5ed788b7.zip |
Add flag to limit the length of the titlenew-fmt
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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, "/")+")") |