diff --git a/config/config.go b/config/config.go index 99aa5b8..c7b5c2c 100644 --- a/config/config.go +++ b/config/config.go @@ -27,6 +27,7 @@ type ConfigS struct { ImageWidthExtraY int `yaml:"image_width_extra_y" mapstructure:"image_width_extra_y"` HideImage bool `yaml:"hide_image" mapstructure:"hide_image"` RoundedCorners bool `yaml:"rounded_corners" mapstructure:"rounded_corners"` + UseNerdIcons bool `yaml:"use_nerd_icons" mapstructure:"use_nerd_icons"` } func NewConfigS() *ConfigS { @@ -34,8 +35,6 @@ func NewConfigS() *ConfigS { CacheDir: utils.CheckDirectoryFmt(userCacheDir), RedrawInterval: 500, Colors: NewColors(), - HideImage: false, - RoundedCorners: false, } } diff --git a/ui/progress.go b/ui/progress.go index ffdd871..0c08d71 100644 --- a/ui/progress.go +++ b/ui/progress.go @@ -16,6 +16,33 @@ import ( var ( state *spotify.PlayerState ctrackId spotify.ID + devices = map[string]string{ + "computer": "󰍹", + "tablet": "", + "smartphone": "󰄜", + "speaker": "󰓃", + "tv": "", + "avr": "󰤽", + "stb": "󰤽", + "audio_dongle": "󱡬", + "game_console": "󰺵", + "cast_video": "󰄙", + "cast_audio": "󰄙", + "automobile": "", + } + playIcons = map[bool]string{ + true: "", + false: "", + } + shuffleIcons = map[bool]string{ + true: "󰒟", + false: "󰒞", + } + repeatIcons = map[string]string{ + "track": "󰑘", + "off": "󰑗", + "context": "󰑖", + } ) // ProgressBar is a two-lined Box. First line is the BarTitle @@ -142,24 +169,60 @@ func progressRoutine() { }() } -func progressFunc() (string, string, string, float64) { - percentage := 0.0 - barTitle := " - " - barText := "---:---" - barTopTitle := "[]" - playing := "Paused" +func deviceIcon(d spotify.PlayerDevice) string { + if val, ok := devices[strings.ToLower(d.Type)]; cfg.UseNerdIcons && ok { + return val + } + return "Device:" +} + +func topTitle(playing, shuffle bool, repeat string, device spotify.PlayerDevice) ( + playState, deviceIcn, deviceName, shuffleState, repeatState string) { + + icon := "" + playState = "Paused" + shuffleState = fmt.Sprintf("%t", shuffle) + + if playing { + playState = "Playing" + } + + if cfg.UseNerdIcons { + icon = playIcons[playing] + icon += " " + repeat = repeatIcons[repeat] + shuffleState = shuffleIcons[shuffle] + } + + playState = icon + playState + deviceIcn = deviceIcon(device) + deviceName = device.Name + repeatState = repeat + return +} + +func progressFunc() (barTitle, barTopTitle, barText string, percentage float64) { + percentage = 0 + barTitle = " - " + barText = "---:---" + barTopTitle = "[]" if state != nil { - if state.Playing { - playing = "Playing" - } - barTopTitle = fmt.Sprintf("[%s Device: %s Shuffle: %t Repeat: %s]", playing, state.Device.Name, state.ShuffleState, state.RepeatState) + barTopTitle = fmt.Sprintf("[ %s %s %s Shuffle: %s Repeat: %s ]", + wrap( + topTitle( + state.Playing, + state.ShuffleState, + state.RepeatState, + state.Device))...) if state.Item != nil { barTitle = fmt.Sprintf("%s%s[-:-:-] - %s%s", cfg.Colors.PBarTrack.String(), state.Item.Name, cfg.Colors.PBarArtist.String(), artistName(state.Item.Artists)) - barText = utils.StrTime(float64(state.Progress/1000)) + "/" + utils.StrTime(float64(state.Item.Duration/1000)) + barText = utils.StrTime(float64(state.Progress/1000)) + + "/" + + utils.StrTime(float64(state.Item.Duration/1000)) percentage = (float64(state.Progress) / float64(state.Item.Duration)) * 100 } } - return barTitle, barTopTitle, barText, percentage + return } diff --git a/ui/utils.go b/ui/utils.go index 53438f3..3ba8415 100644 --- a/ui/utils.go +++ b/ui/utils.go @@ -127,3 +127,7 @@ func artistName(s []spotify.SimpleArtist) string { } return "" } + +func wrap(args ...interface{}) []interface{} { + return args +}