You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.4 KiB
56 lines
1.4 KiB
3 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"barista.run/bar"
|
||
|
"barista.run/colors"
|
||
|
"barista.run/modules/media"
|
||
|
"barista.run/modules/volume"
|
||
|
"barista.run/modules/volume/alsa"
|
||
|
"barista.run/outputs"
|
||
|
"barista.run/pango"
|
||
|
)
|
||
|
|
||
|
func mediaFormatFunc(m media.Info) bar.Output {
|
||
|
if m.PlaybackStatus == media.Stopped || m.PlaybackStatus == media.Disconnected {
|
||
|
return nil
|
||
|
}
|
||
|
artist := truncate(m.Artist, 20)
|
||
|
title := truncate(m.Title, 40-len(artist))
|
||
|
if len(title) < 20 {
|
||
|
artist = truncate(m.Artist, 40-len(title))
|
||
|
}
|
||
|
iconAndPosition := pango.Icon("nf-fa-music").Color(colors.Hex("#f70"))
|
||
|
if m.PlaybackStatus == media.Playing {
|
||
|
iconAndPosition.Append(
|
||
|
spacer, pango.Textf("%s/%s",
|
||
|
formatMediaTime(m.Position()),
|
||
|
formatMediaTime(m.Length)),
|
||
|
)
|
||
|
}
|
||
|
return outputs.Pango(iconAndPosition, spacer, title, " - ", artist)
|
||
|
}
|
||
|
|
||
|
func volumeSegment() bar.Module {
|
||
|
return volume.New(alsa.DefaultMixer()).Output(func(v volume.Volume) bar.Output {
|
||
|
pct := v.Pct()
|
||
|
var indicatorText *pango.Node
|
||
|
var pctText *pango.Node
|
||
|
if pct > 99 {
|
||
|
pctText = pango.Text("MAX")
|
||
|
} else {
|
||
|
pctText = pango.Textf("%2d%%", pct)
|
||
|
}
|
||
|
if v.Mute {
|
||
|
indicatorText = pango.Text("MUT").Color(colors.Scheme("degraded"))
|
||
|
pctText = pctText.Color(colors.Scheme("degraded")).XSmall()
|
||
|
} else {
|
||
|
indicatorText = pango.Text("Vol").XSmall()
|
||
|
}
|
||
|
return outputs.Pango(
|
||
|
indicatorText,
|
||
|
spacer,
|
||
|
pctText,
|
||
|
)
|
||
|
})
|
||
|
}
|