oh-my-posh/src/segment_spotify.go

59 lines
1.2 KiB
Go
Raw Normal View History

2019-03-13 04:14:30 -07:00
package main
type spotify struct {
2022-01-22 10:46:56 -08:00
props Properties
env Environment
MusicPlayer
}
type MusicPlayer struct {
Status string
Artist string
Track string
Icon string
2019-03-13 04:14:30 -07:00
}
const (
// PlayingIcon indicates a song is playing
2019-03-13 04:14:30 -07:00
PlayingIcon Property = "playing_icon"
// PausedIcon indicates a song is paused
2019-03-13 04:14:30 -07:00
PausedIcon Property = "paused_icon"
// StoppedIcon indicates a song is stopped
2020-11-04 23:56:12 -08:00
StoppedIcon Property = "stopped_icon"
2022-01-22 10:46:56 -08:00
playing = "playing"
stopped = "stopped"
paused = "paused"
2019-03-13 04:14:30 -07:00
)
func (s *spotify) string() string {
2022-01-22 10:46:56 -08:00
segmentTemplate := s.props.getString(SegmentTemplate, "{{.Icon}}{{ if ne .Status \"stopped\"}}{{.Artist}} - {{.Track}}{{ end }}")
template := &textTemplate{
Template: segmentTemplate,
Context: s,
Env: s.env,
}
text, err := template.render()
if err != nil {
return err.Error()
}
return text
}
func (s *spotify) resolveIcon() {
switch s.Status {
case stopped:
2020-11-04 23:56:12 -08:00
// in this case, no artist or track info
2022-01-22 10:46:56 -08:00
s.Icon = s.props.getString(StoppedIcon, "\uF04D ")
case paused:
s.Icon = s.props.getString(PausedIcon, "\uF8E3 ")
case playing:
s.Icon = s.props.getString(PlayingIcon, "\uE602 ")
2019-03-13 04:14:30 -07:00
}
}
2022-01-01 11:09:52 -08:00
func (s *spotify) init(props Properties, env Environment) {
2019-03-13 04:14:30 -07:00
s.props = props
s.env = env
}