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 {
|
type BlockGenerator interface {
|
||||||
Block(*ColorSet) (*Block, error)
|
Block(*ColorSet) (*Block, error)
|
||||||
|
GetNameAndInstance() (name, instance string)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,11 +21,14 @@ const (
|
||||||
type AudioPlayer struct {
|
type AudioPlayer struct {
|
||||||
ShowTextOnPause bool
|
ShowTextOnPause bool
|
||||||
MaxLabelLen int
|
MaxLabelLen int
|
||||||
|
|
||||||
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAudioPlayer(maxLabelLength int) *AudioPlayer {
|
func NewAudioPlayer(maxLabelLength int) *AudioPlayer {
|
||||||
return &AudioPlayer{
|
return &AudioPlayer{
|
||||||
MaxLabelLen: maxLabelLength,
|
MaxLabelLen: maxLabelLength,
|
||||||
|
name: "audioPlayer",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +106,7 @@ func (g *AudioPlayer) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
b := new(i3bar.Block)
|
b := new(i3bar.Block)
|
||||||
b.Name = "audioPlayer"
|
b.Name = g.name
|
||||||
|
|
||||||
b.FullText = musicNoteString
|
b.FullText = musicNoteString
|
||||||
b.ShortText = musicNoteString
|
b.ShortText = musicNoteString
|
||||||
|
@ -124,3 +127,7 @@ func (g *AudioPlayer) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
||||||
|
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *AudioPlayer) GetNameAndInstance() (string, string) {
|
||||||
|
return g.name, ""
|
||||||
|
}
|
|
@ -11,10 +11,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
batteryStateFull = "FULL"
|
batteryStateFull = "FULL"
|
||||||
batteryStateDischarging = "BAT"
|
batteryStateDischarging = "BAT"
|
||||||
batteryStateCharging = "CHR"
|
batteryStateCharging = "CHR"
|
||||||
batteryStateUnknown = "UNK"
|
batteryStateUnknown = "UNK"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Battery struct {
|
type Battery struct {
|
||||||
|
@ -22,23 +22,25 @@ type Battery struct {
|
||||||
OkThreshold float32
|
OkThreshold float32
|
||||||
WarningThreshold float32
|
WarningThreshold float32
|
||||||
|
|
||||||
Name string
|
DeviceName string
|
||||||
UseDesignMaxEnergy bool
|
UseDesignMaxEnergy bool
|
||||||
|
|
||||||
|
name string
|
||||||
previousWasBackgroundWarning bool
|
previousWasBackgroundWarning bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBattery(name string, fullThreshold, okThreshold, warningThreshold float32) i3bar.BlockGenerator {
|
func NewBattery(deviceName string, fullThreshold, okThreshold, warningThreshold float32) i3bar.BlockGenerator {
|
||||||
return &Battery{
|
return &Battery{
|
||||||
Name: name,
|
DeviceName: deviceName,
|
||||||
FullThreshold: fullThreshold,
|
FullThreshold: fullThreshold,
|
||||||
OkThreshold: okThreshold,
|
OkThreshold: okThreshold,
|
||||||
WarningThreshold: warningThreshold,
|
WarningThreshold: warningThreshold,
|
||||||
|
name: "battery",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Battery) infoPath() string {
|
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) {
|
func (g *Battery) getPercentage() (float32, error) {
|
||||||
|
@ -114,8 +116,8 @@ func (g *Battery) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
block := &i3bar.Block{
|
block := &i3bar.Block{
|
||||||
Name: "battery",
|
Name: g.name,
|
||||||
Instance: g.Name,
|
Instance: g.DeviceName,
|
||||||
FullText: fmt.Sprintf("%s %.1f%%", state, percentage),
|
FullText: fmt.Sprintf("%s %.1f%%", state, percentage),
|
||||||
ShortText: fmt.Sprintf("%.1f%%", percentage),
|
ShortText: fmt.Sprintf("%.1f%%", percentage),
|
||||||
}
|
}
|
||||||
|
@ -152,3 +154,7 @@ func (g *Battery) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
||||||
|
|
||||||
return block, nil
|
return block, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *Battery) GetNameAndInstance() (string, string) {
|
||||||
|
return g.name, g.DeviceName
|
||||||
|
}
|
||||||
|
|
|
@ -16,12 +16,15 @@ type CPU struct {
|
||||||
|
|
||||||
idle0, total0 uint64
|
idle0, total0 uint64
|
||||||
idle1, total1 uint64
|
idle1, total1 uint64
|
||||||
|
|
||||||
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCPU(okThreshold, warningThreshold float32) i3bar.BlockGenerator {
|
func NewCPU(okThreshold, warningThreshold float32) i3bar.BlockGenerator {
|
||||||
m := &CPU{
|
m := &CPU{
|
||||||
OkThreshold: okThreshold,
|
OkThreshold: okThreshold,
|
||||||
WarningThreshold: warningThreshold,
|
WarningThreshold: warningThreshold,
|
||||||
|
name: "cpu",
|
||||||
}
|
}
|
||||||
_ = m.doSample()
|
_ = m.doSample()
|
||||||
return m
|
return m
|
||||||
|
@ -74,7 +77,7 @@ func (g *CPU) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
||||||
p := g.getPercentage()
|
p := g.getPercentage()
|
||||||
|
|
||||||
block := &i3bar.Block{
|
block := &i3bar.Block{
|
||||||
Name: "cpu",
|
Name: g.name,
|
||||||
FullText: fmt.Sprintf("CPU: %.1f%%", p),
|
FullText: fmt.Sprintf("CPU: %.1f%%", p),
|
||||||
ShortText: fmt.Sprintf("C: %.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
|
return block, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *CPU) GetNameAndInstance() (string, string) {
|
||||||
|
return g.name, ""
|
||||||
|
}
|
|
@ -8,18 +8,25 @@ import (
|
||||||
|
|
||||||
type DateTime struct {
|
type DateTime struct {
|
||||||
// TODO: 12 hour mode?
|
// TODO: 12 hour mode?
|
||||||
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDateTime() i3bar.BlockGenerator {
|
func NewDateTime() i3bar.BlockGenerator {
|
||||||
return new(DateTime)
|
return &DateTime{
|
||||||
|
name: "datetime",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *DateTime) Block(*i3bar.ColorSet) (*i3bar.Block, error) {
|
func (g *DateTime) Block(*i3bar.ColorSet) (*i3bar.Block, error) {
|
||||||
cTime := time.Now().Local()
|
cTime := time.Now().Local()
|
||||||
|
|
||||||
return &i3bar.Block{
|
return &i3bar.Block{
|
||||||
Name: "datetime",
|
Name: g.name,
|
||||||
FullText: cTime.Format("2006-01-02 15:04:05"),
|
FullText: cTime.Format("2006-01-02 15:04:05"),
|
||||||
ShortText: cTime.Format("15:04:05"),
|
ShortText: cTime.Format("15:04:05"),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *DateTime) GetNameAndInstance() (string, string) {
|
||||||
|
return g.name, ""
|
||||||
|
}
|
|
@ -14,6 +14,8 @@ type Disk struct {
|
||||||
WarningThreshold float32
|
WarningThreshold float32
|
||||||
|
|
||||||
MountPath string
|
MountPath string
|
||||||
|
|
||||||
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDisk(mountPath string, okThreshold, warningThreshold float32) i3bar.BlockGenerator {
|
func NewDisk(mountPath string, okThreshold, warningThreshold float32) i3bar.BlockGenerator {
|
||||||
|
@ -21,6 +23,7 @@ func NewDisk(mountPath string, okThreshold, warningThreshold float32) i3bar.Bloc
|
||||||
OkThreshold: okThreshold,
|
OkThreshold: okThreshold,
|
||||||
WarningThreshold: warningThreshold,
|
WarningThreshold: warningThreshold,
|
||||||
MountPath: mountPath,
|
MountPath: mountPath,
|
||||||
|
name: "disk",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +49,8 @@ func (g *Disk) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
block := &i3bar.Block{
|
block := &i3bar.Block{
|
||||||
Name: "disk",
|
Name: g.name,
|
||||||
|
Instance: g.MountPath,
|
||||||
FullText: fmt.Sprintf("Disk avail: %.1fGB", da),
|
FullText: fmt.Sprintf("Disk avail: %.1fGB", da),
|
||||||
ShortText: fmt.Sprintf("D: %.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
|
return block, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *Disk) GetNameAndInstance() (string, string) {
|
||||||
|
return g.name, g.MountPath
|
||||||
|
}
|
|
@ -10,11 +10,14 @@ import (
|
||||||
|
|
||||||
type IPAddress struct {
|
type IPAddress struct {
|
||||||
Adapter string
|
Adapter string
|
||||||
|
|
||||||
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIPAddress(adapter string) i3bar.BlockGenerator {
|
func NewIPAddress(adapter string) i3bar.BlockGenerator {
|
||||||
return &IPAddress{
|
return &IPAddress{
|
||||||
Adapter: adapter,
|
Adapter: adapter,
|
||||||
|
name: "ipAddr",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +65,10 @@ func (g *IPAddress) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
block := new(i3bar.Block)
|
block := &i3bar.Block{
|
||||||
|
Name: g.name,
|
||||||
|
Instance: g.Adapter,
|
||||||
|
}
|
||||||
|
|
||||||
if ipAddr == "" {
|
if ipAddr == "" {
|
||||||
block.TextColor = colors.Bad
|
block.TextColor = colors.Bad
|
||||||
|
@ -75,3 +81,7 @@ func (g *IPAddress) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
||||||
|
|
||||||
return block, nil
|
return block, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *IPAddress) GetNameAndInstance() (string, string) {
|
||||||
|
return g.name, g.Adapter
|
||||||
|
}
|
|
@ -13,12 +13,15 @@ import (
|
||||||
type Memory struct {
|
type Memory struct {
|
||||||
OkThreshold float32
|
OkThreshold float32
|
||||||
WarningThreshold float32
|
WarningThreshold float32
|
||||||
|
|
||||||
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMemory(okThreshold, warningThreshold float32) i3bar.BlockGenerator {
|
func NewMemory(okThreshold, warningThreshold float32) i3bar.BlockGenerator {
|
||||||
return &Memory{
|
return &Memory{
|
||||||
OkThreshold: okThreshold,
|
OkThreshold: okThreshold,
|
||||||
WarningThreshold: warningThreshold,
|
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
|
// TODO: Make the readout change between KB/MB/GB
|
||||||
|
|
||||||
block := &i3bar.Block{
|
block := &i3bar.Block{
|
||||||
Name: "memory",
|
Name: g.name,
|
||||||
FullText: fmt.Sprintf("Mem: %.1fGB of %.1fGB", used, total),
|
FullText: fmt.Sprintf("Mem: %.1fGB of %.1fGB", used, total),
|
||||||
ShortText: fmt.Sprintf("M: %.1fGB", used),
|
ShortText: fmt.Sprintf("M: %.1fGB", used),
|
||||||
}
|
}
|
||||||
|
@ -82,3 +85,7 @@ func (g *Memory) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
||||||
|
|
||||||
return block, nil
|
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 {
|
type PlainText struct {
|
||||||
Text string
|
Text string
|
||||||
|
|
||||||
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPlainText(text string) i3bar.BlockGenerator {
|
func NewPlainText(text string) i3bar.BlockGenerator {
|
||||||
return &PlainText{
|
return &PlainText{
|
||||||
Text: text,
|
Text: text,
|
||||||
|
name: "plaintext",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *PlainText) Block(*i3bar.ColorSet) (*i3bar.Block, error) {
|
func (g *PlainText) Block(*i3bar.ColorSet) (*i3bar.Block, error) {
|
||||||
return &i3bar.Block{
|
return &i3bar.Block{
|
||||||
Name: "plaintext",
|
Name: g.name,
|
||||||
FullText: g.Text,
|
FullText: g.Text,
|
||||||
}, nil
|
}, 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
|
// Sink is the target sink name to look for in Pulseaudio. Leave blank
|
||||||
// to use the default sink.
|
// to use the default sink.
|
||||||
Sink string
|
Sink string
|
||||||
|
|
||||||
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPulseaudioVolume() i3bar.BlockGenerator {
|
func NewPulseaudioVolume() i3bar.BlockGenerator {
|
||||||
return new(PulseaudioVolume)
|
return &PulseaudioVolume{
|
||||||
|
name: "pulseaudioVolume",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *PulseaudioVolume) getInfo() (string, error) {
|
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 := new(i3bar.Block)
|
||||||
block.Name = "pulseaudioVolume"
|
block.Name = g.name
|
||||||
block.Instance = g.Sink
|
block.Instance = g.Sink
|
||||||
|
|
||||||
if v.Muted {
|
if v.Muted {
|
||||||
|
@ -114,3 +118,7 @@ func (g *PulseaudioVolume) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
||||||
|
|
||||||
return block, nil
|
return block, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *PulseaudioVolume) GetNameAndInstance() (string, string) {
|
||||||
|
return g.name, g.Sink
|
||||||
|
}
|
|
@ -13,12 +13,16 @@ import (
|
||||||
type WiFi struct {
|
type WiFi struct {
|
||||||
Adapter string
|
Adapter string
|
||||||
OkThreshold float32
|
OkThreshold float32
|
||||||
|
|
||||||
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWiFi(adapter string, okThreshold float32) i3bar.BlockGenerator {
|
func NewWiFi(adapter string, okThreshold float32) i3bar.BlockGenerator {
|
||||||
return &WiFi{
|
return &WiFi{
|
||||||
Adapter: adapter,
|
Adapter: adapter,
|
||||||
OkThreshold: okThreshold,
|
OkThreshold: okThreshold,
|
||||||
|
|
||||||
|
name: "wifi",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +112,10 @@ func (g *WiFi) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
block := new(i3bar.Block)
|
block := &i3bar.Block{
|
||||||
|
Name: g.name,
|
||||||
|
Instance: g.Adapter,
|
||||||
|
}
|
||||||
|
|
||||||
if ssid == "" {
|
if ssid == "" {
|
||||||
block.TextColor = colors.Bad
|
block.TextColor = colors.Bad
|
||||||
|
@ -126,3 +133,7 @@ func (g *WiFi) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
||||||
|
|
||||||
return block, nil
|
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