forked from spezifisch/stmps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui_helpers.go
58 lines (48 loc) · 1.35 KB
/
gui_helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2023 The STMPS Authors
// SPDX-License-Identifier: GPL-3.0-only
package main
import (
"fmt"
"github.com/rivo/tview"
"github.com/spezifisch/stmps/mpvplayer"
"github.com/spezifisch/stmps/subsonic"
)
func makeModal(p tview.Primitive, width, height int) tview.Primitive {
return tview.NewGrid().
SetColumns(0, width, 0).
SetRows(0, height, 0).
AddItem(p, 1, 1, 1, 1, 0, 0, true)
}
func formatPlayerStatus(volume int64, position int64, duration int64) string {
if position < 0 {
position = 0
}
if duration < 0 {
duration = 0
}
positionMin, positionSec := secondsToMinAndSec(position)
durationMin, durationSec := secondsToMinAndSec(duration)
return fmt.Sprintf("[%d%%][::b][%02d:%02d/%02d:%02d]", volume,
positionMin, positionSec, durationMin, durationSec)
}
func formatSongForStatusBar(currentSong *mpvplayer.QueueItem) (text string) {
if currentSong == nil {
return
}
if currentSong.Title != "" {
text += "[::-] [white]" + tview.Escape(currentSong.Title)
}
if currentSong.Artist != "" {
text += " [gray]by [white]" + tview.Escape(currentSong.Artist)
}
return
}
func formatSongForPlaylistEntry(entity subsonic.SubsonicEntity) (text string) {
if entity.Title != "" {
text += "[::-] [white]" + tview.Escape(entity.Title)
}
if entity.Artist != "" {
text += " [gray]by [white]" + tview.Escape(entity.Artist)
}
return
}