Update definition of i3bar.BlockGenerator
Signed-off-by: AKP <tom@tdpain.net>
This commit is contained in:
parent
39c4ec505e
commit
29ac240241
11 changed files with 99 additions and 20 deletions
|
@ -144,4 +144,5 @@ type Block struct {
|
|||
|
||||
type BlockGenerator interface {
|
||||
Block(*ColorSet) (*Block, error)
|
||||
GetNameAndInstance() (name, instance string)
|
||||
}
|
||||
|
|
|
@ -21,11 +21,14 @@ const (
|
|||
type AudioPlayer struct {
|
||||
ShowTextOnPause bool
|
||||
MaxLabelLen int
|
||||
|
||||
name string
|
||||
}
|
||||
|
||||
func NewAudioPlayer(maxLabelLength int) *AudioPlayer {
|
||||
return &AudioPlayer{
|
||||
MaxLabelLen: maxLabelLength,
|
||||
name: "audioPlayer",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,7 +106,7 @@ func (g *AudioPlayer) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
|||
}
|
||||
|
||||
b := new(i3bar.Block)
|
||||
b.Name = "audioPlayer"
|
||||
b.Name = g.name
|
||||
|
||||
b.FullText = musicNoteString
|
||||
b.ShortText = musicNoteString
|
||||
|
@ -124,3 +127,7 @@ func (g *AudioPlayer) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
|||
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (g *AudioPlayer) GetNameAndInstance() (string, string) {
|
||||
return g.name, ""
|
||||
}
|
|
@ -22,23 +22,25 @@ type Battery struct {
|
|||
OkThreshold float32
|
||||
WarningThreshold float32
|
||||
|
||||
Name string
|
||||
DeviceName string
|
||||
UseDesignMaxEnergy bool
|
||||
|
||||
name string
|
||||
previousWasBackgroundWarning bool
|
||||
}
|
||||
|
||||
func NewBattery(name string, fullThreshold, okThreshold, warningThreshold float32) i3bar.BlockGenerator {
|
||||
func NewBattery(deviceName string, fullThreshold, okThreshold, warningThreshold float32) i3bar.BlockGenerator {
|
||||
return &Battery{
|
||||
Name: name,
|
||||
DeviceName: deviceName,
|
||||
FullThreshold: fullThreshold,
|
||||
OkThreshold: okThreshold,
|
||||
WarningThreshold: warningThreshold,
|
||||
name: "battery",
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Battery) infoPath() string {
|
||||
return path.Join("/sys/class/power_supply", g.Name)
|
||||
return path.Join("/sys/class/power_supply", g.DeviceName)
|
||||
}
|
||||
|
||||
func (g *Battery) getPercentage() (float32, error) {
|
||||
|
@ -114,8 +116,8 @@ func (g *Battery) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
|||
}
|
||||
|
||||
block := &i3bar.Block{
|
||||
Name: "battery",
|
||||
Instance: g.Name,
|
||||
Name: g.name,
|
||||
Instance: g.DeviceName,
|
||||
FullText: fmt.Sprintf("%s %.1f%%", state, percentage),
|
||||
ShortText: fmt.Sprintf("%.1f%%", percentage),
|
||||
}
|
||||
|
@ -152,3 +154,7 @@ func (g *Battery) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
|||
|
||||
return block, nil
|
||||
}
|
||||
|
||||
func (g *Battery) GetNameAndInstance() (string, string) {
|
||||
return g.name, g.DeviceName
|
||||
}
|
||||
|
|
|
@ -16,12 +16,15 @@ type CPU struct {
|
|||
|
||||
idle0, total0 uint64
|
||||
idle1, total1 uint64
|
||||
|
||||
name string
|
||||
}
|
||||
|
||||
func NewCPU(okThreshold, warningThreshold float32) i3bar.BlockGenerator {
|
||||
m := &CPU{
|
||||
OkThreshold: okThreshold,
|
||||
WarningThreshold: warningThreshold,
|
||||
name: "cpu",
|
||||
}
|
||||
_ = m.doSample()
|
||||
return m
|
||||
|
@ -74,7 +77,7 @@ func (g *CPU) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
|||
p := g.getPercentage()
|
||||
|
||||
block := &i3bar.Block{
|
||||
Name: "cpu",
|
||||
Name: g.name,
|
||||
FullText: fmt.Sprintf("CPU: %.1f%%", p),
|
||||
ShortText: fmt.Sprintf("C: %.1f%%", p),
|
||||
}
|
||||
|
@ -87,3 +90,7 @@ func (g *CPU) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
|||
|
||||
return block, nil
|
||||
}
|
||||
|
||||
func (g *CPU) GetNameAndInstance() (string, string) {
|
||||
return g.name, ""
|
||||
}
|
|
@ -8,18 +8,25 @@ import (
|
|||
|
||||
type DateTime struct {
|
||||
// TODO: 12 hour mode?
|
||||
name string
|
||||
}
|
||||
|
||||
func NewDateTime() i3bar.BlockGenerator {
|
||||
return new(DateTime)
|
||||
return &DateTime{
|
||||
name: "datetime",
|
||||
}
|
||||
}
|
||||
|
||||
func (g *DateTime) Block(*i3bar.ColorSet) (*i3bar.Block, error) {
|
||||
cTime := time.Now().Local()
|
||||
|
||||
return &i3bar.Block{
|
||||
Name: "datetime",
|
||||
Name: g.name,
|
||||
FullText: cTime.Format("2006-01-02 15:04:05"),
|
||||
ShortText: cTime.Format("15:04:05"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (g *DateTime) GetNameAndInstance() (string, string) {
|
||||
return g.name, ""
|
||||
}
|
|
@ -14,6 +14,8 @@ type Disk struct {
|
|||
WarningThreshold float32
|
||||
|
||||
MountPath string
|
||||
|
||||
name string
|
||||
}
|
||||
|
||||
func NewDisk(mountPath string, okThreshold, warningThreshold float32) i3bar.BlockGenerator {
|
||||
|
@ -21,6 +23,7 @@ func NewDisk(mountPath string, okThreshold, warningThreshold float32) i3bar.Bloc
|
|||
OkThreshold: okThreshold,
|
||||
WarningThreshold: warningThreshold,
|
||||
MountPath: mountPath,
|
||||
name: "disk",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +49,8 @@ func (g *Disk) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
|||
}
|
||||
|
||||
block := &i3bar.Block{
|
||||
Name: "disk",
|
||||
Name: g.name,
|
||||
Instance: g.MountPath,
|
||||
FullText: fmt.Sprintf("Disk avail: %.1fGB", da),
|
||||
ShortText: fmt.Sprintf("D: %.1fGB", da),
|
||||
}
|
||||
|
@ -59,3 +63,7 @@ func (g *Disk) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
|||
|
||||
return block, nil
|
||||
}
|
||||
|
||||
func (g *Disk) GetNameAndInstance() (string, string) {
|
||||
return g.name, g.MountPath
|
||||
}
|
|
@ -10,11 +10,14 @@ import (
|
|||
|
||||
type IPAddress struct {
|
||||
Adapter string
|
||||
|
||||
name string
|
||||
}
|
||||
|
||||
func NewIPAddress(adapter string) i3bar.BlockGenerator {
|
||||
return &IPAddress{
|
||||
Adapter: adapter,
|
||||
name: "ipAddr",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,7 +65,10 @@ func (g *IPAddress) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
block := new(i3bar.Block)
|
||||
block := &i3bar.Block{
|
||||
Name: g.name,
|
||||
Instance: g.Adapter,
|
||||
}
|
||||
|
||||
if ipAddr == "" {
|
||||
block.TextColor = colors.Bad
|
||||
|
@ -75,3 +81,7 @@ func (g *IPAddress) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
|||
|
||||
return block, nil
|
||||
}
|
||||
|
||||
func (g *IPAddress) GetNameAndInstance() (string, string) {
|
||||
return g.name, g.Adapter
|
||||
}
|
|
@ -13,12 +13,15 @@ import (
|
|||
type Memory struct {
|
||||
OkThreshold float32
|
||||
WarningThreshold float32
|
||||
|
||||
name string
|
||||
}
|
||||
|
||||
func NewMemory(okThreshold, warningThreshold float32) i3bar.BlockGenerator {
|
||||
return &Memory{
|
||||
OkThreshold: okThreshold,
|
||||
WarningThreshold: warningThreshold,
|
||||
name: "memory",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +72,7 @@ func (g *Memory) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
|||
// TODO: Make the readout change between KB/MB/GB
|
||||
|
||||
block := &i3bar.Block{
|
||||
Name: "memory",
|
||||
Name: g.name,
|
||||
FullText: fmt.Sprintf("Mem: %.1fGB of %.1fGB", used, total),
|
||||
ShortText: fmt.Sprintf("M: %.1fGB", used),
|
||||
}
|
||||
|
@ -82,3 +85,7 @@ func (g *Memory) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
|||
|
||||
return block, nil
|
||||
}
|
||||
|
||||
func (g *Memory) GetNameAndInstance() (string, string) {
|
||||
return g.name, ""
|
||||
}
|
|
@ -4,17 +4,24 @@ import "github.com/codemicro/bar/internal/i3bar"
|
|||
|
||||
type PlainText struct {
|
||||
Text string
|
||||
|
||||
name string
|
||||
}
|
||||
|
||||
func NewPlainText(text string) i3bar.BlockGenerator {
|
||||
return &PlainText{
|
||||
Text: text,
|
||||
name: "plaintext",
|
||||
}
|
||||
}
|
||||
|
||||
func (g *PlainText) Block(*i3bar.ColorSet) (*i3bar.Block, error) {
|
||||
return &i3bar.Block{
|
||||
Name: "plaintext",
|
||||
Name: g.name,
|
||||
FullText: g.Text,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (g *PlainText) GetNameAndInstance() (string, string) {
|
||||
return g.name, ""
|
||||
}
|
|
@ -14,10 +14,14 @@ type PulseaudioVolume struct {
|
|||
// Sink is the target sink name to look for in Pulseaudio. Leave blank
|
||||
// to use the default sink.
|
||||
Sink string
|
||||
|
||||
name string
|
||||
}
|
||||
|
||||
func NewPulseaudioVolume() i3bar.BlockGenerator {
|
||||
return new(PulseaudioVolume)
|
||||
return &PulseaudioVolume{
|
||||
name: "pulseaudioVolume",
|
||||
}
|
||||
}
|
||||
|
||||
func (g *PulseaudioVolume) getInfo() (string, error) {
|
||||
|
@ -97,7 +101,7 @@ func (g *PulseaudioVolume) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
|||
}
|
||||
|
||||
block := new(i3bar.Block)
|
||||
block.Name = "pulseaudioVolume"
|
||||
block.Name = g.name
|
||||
block.Instance = g.Sink
|
||||
|
||||
if v.Muted {
|
||||
|
@ -114,3 +118,7 @@ func (g *PulseaudioVolume) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
|||
|
||||
return block, nil
|
||||
}
|
||||
|
||||
func (g *PulseaudioVolume) GetNameAndInstance() (string, string) {
|
||||
return g.name, g.Sink
|
||||
}
|
|
@ -13,12 +13,16 @@ import (
|
|||
type WiFi struct {
|
||||
Adapter string
|
||||
OkThreshold float32
|
||||
|
||||
name string
|
||||
}
|
||||
|
||||
func NewWiFi(adapter string, okThreshold float32) i3bar.BlockGenerator {
|
||||
return &WiFi{
|
||||
Adapter: adapter,
|
||||
OkThreshold: okThreshold,
|
||||
|
||||
name: "wifi",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,7 +112,10 @@ func (g *WiFi) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
block := new(i3bar.Block)
|
||||
block := &i3bar.Block{
|
||||
Name: g.name,
|
||||
Instance: g.Adapter,
|
||||
}
|
||||
|
||||
if ssid == "" {
|
||||
block.TextColor = colors.Bad
|
||||
|
@ -126,3 +133,7 @@ func (g *WiFi) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
|||
|
||||
return block, nil
|
||||
}
|
||||
|
||||
func (g *WiFi) GetNameAndInstance() (string, string) {
|
||||
return g.name, g.Adapter
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue