@@ -46,22 +46,26 @@ func status(api spotify.APIInterface) (string, error) {
4646}
4747
4848func Show (playback * model.Playback ) string {
49- status := fmt .Sprintf ("🎵 %s\n " , playback .Item .Name )
50-
49+ var artistLine string
5150 switch playback .Item .Type {
5251 case "track" :
53- status += fmt . Sprintf ( "🎤 %s \n " , joinArtists (playback .Item .Artists ) )
52+ artistLine = joinArtists (playback .Item .Artists )
5453 case "episode" :
55- status += fmt . Sprintf ( "🎤 %s \n " , playback .Item .Show .Name )
54+ artistLine = playback .Item .Show .Name
5655 }
5756
57+ var isPlayingEmoji string
5858 if playback .IsPlaying {
59- status + = "▶️ "
59+ isPlayingEmoji = "▶️"
6060 } else {
61- status + = "⏸ "
61+ isPlayingEmoji = "⏸"
6262 }
6363
64- status += showProgressBar (playback .ProgressMs , playback .Item .DurationMs )
64+ progressBar := showProgressBar (playback .ProgressMs , playback .Item .DurationMs )
65+
66+ status := prefixLineWithEmoji ("🎵" , playback .Item .Name )
67+ status += prefixLineWithEmoji ("🎤" , artistLine )
68+ status += prefixLineWithEmoji (isPlayingEmoji , progressBar )
6569
6670 return status
6771}
@@ -85,7 +89,7 @@ func showProgressBar(progress, duration int) string {
8589 for i := bars ; i < length ; i ++ {
8690 status += " "
8791 }
88- status += fmt .Sprintf ("] %s\n " , formatTime (duration ))
92+ status += fmt .Sprintf ("] %s" , formatTime (duration ))
8993
9094 return status
9195}
@@ -94,3 +98,8 @@ func formatTime(ms int) string {
9498 s := ms / 1000
9599 return fmt .Sprintf ("%d:%02d" , s / 60 , s % 60 )
96100}
101+
102+ func prefixLineWithEmoji (emoji , line string ) string {
103+ // Carriage return jumps to start of line because emojis can have variable widths
104+ return fmt .Sprintf (" %s\r %s\n " , line , emoji )
105+ }
0 commit comments