From ef03c3e6614481154c015487f87cf27a5ed788b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yaroslav=20de=20la=20Pe=C3=B1a=20Smirnov?= Date: Sun, 20 Nov 2022 02:57:10 +0300 Subject: Add flag to limit the length of the title --- main.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'main.go') 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, "/")+")") -- cgit v1.2.3