Documentation ¶
Overview ¶
Package goi3bar is a package that is capable of generating output suitable for i3bar. i3bar output is created by outputting JSON, which is defined in the i3bar documentation, found at http://i3wm.org/docs/i3bar-protocol.html
How to put data on the bar ¶
A single i3bar output struct is represented as an Output. Any applet wanting to display information on the bar must create output of type []Output. The two interfaces that produce []Output are Producer and Generator.
Registering new plugins ¶
To register a new plugins on the bar, prodvide a unique key and Producer to I3bar.Register. Remember to specify an order of applets before starting the bar. This can be done by providing all keys in the desired order as a slice to the I3bar.Order function.
Producer and Generator ¶
The Producer is the interface that must be implemented when registering a plugin with an I3bar. It has one method, Produce(), which returns a channel of []Output. Whenever the I3bar produces new output, it will use the most recently received []Output it received from that Producer.
It is recommended that you implement this interface only if you have a need to manage your own output scheduling - if you can generate output in a non-blocking way, implement the Generator method instead.
Examples of required implementation of the Producer interface can be found in the disk IO or CPU percentage plugins.
If you do not need to manage your own scheduling, you should implement the Generator interface instead. It has one method, Generate(), that is assumed to be non-blocking and will be called at regular intervals. To register a generator with an I3bar, wrap it in a BaseProducer, which will return a Producer with managed scheduling.
Examples of the Generator+BaseProducer plugins are the clock, battery, disk usage and network packages
Clicker ¶
The Clicker is the interface that must be implemented to support interaction through click events. To properly support this, you must also emit a Name value in your Output structs, which must match the name your Producer was registered with, otherwise the event will be unable to be routed back to your Producer.
Builder ¶
The Builder is the interface that must be implemented when making your plugin available to the user through the configuration file interface. Look in the config package docs for detailed info on how to provide an API through the config file.
Index ¶
- Constants
- Variables
- func IsColorValid(c string) (err error)
- func ParseColor(c string) (string, error)
- type BaseProducer
- type BaseProducerClicker
- type ClickEvent
- type Clicker
- type Colors
- type Generator
- type GeneratorClicker
- type I3bar
- type InvalidColorErr
- type MultiGenerator
- type MultiProducer
- type OrderedMultiGenerator
- type Output
- type Producer
- type ProducerClicker
- type StaticGenerator
- type Update
Constants ¶
const ( DefaultColorGeneral = "#FFFFFF" DefaultColorOK = "#00FF00" DefaultColorWarn = "#FFA500" DefaultColorCrit = "#FF0000" )
These colors are the default colors used for alert state if none are given.
Variables ¶
var ColorRegexp = regexp.MustCompile("#[0-9A-Fa-f]{6}")
var DefaultColors = Colors{ General: DefaultColorGeneral, OK: DefaultColorOK, Warn: DefaultColorWarn, Crit: DefaultColorCrit, }
These are colors that should be used through the program. They will respect custom configuration given by the user in their JSON config.
Functions ¶
func IsColorValid ¶
func ParseColor ¶
Types ¶
type BaseProducer ¶
A BaseProducer is a simple Producer, which generates output at regular intervals using a Generator.
func (*BaseProducer) Produce ¶
func (p *BaseProducer) Produce(kill <-chan struct{}) <-chan []Output
Produce implements Producer. It creates a new value from the Generator every interval, and sends it down the provided channel
type BaseProducerClicker ¶
type BaseProducerClicker struct { GeneratorClicker Interval time.Duration Name string }
A BaseProducerClicker is like a BaseProducer, but it uses a GeneratorClicker instead of a Generator so it can also implement Clicker
func (*BaseProducerClicker) Produce ¶
func (p *BaseProducerClicker) Produce(kill <-chan struct{}) <-chan []Output
type ClickEvent ¶
type Clicker ¶
type Clicker interface {
Click(ClickEvent) error
}
A Clicker receives click events from the i3bar. If a registered Producer also implements Clicker, then that its' Click method will be called with the click event received from i3bar.
type Colors ¶
type Generator ¶
A Generator generates content to put on an i3bar. Other functions will call Generate to create output for the i3bar. A Generator should define how, not when the output is built.
type GeneratorClicker ¶
A GeneratorClicker is both a Generator and a Clicker. It exists so we can have a concrete implementation built on BaseProducer that can also be used for plugins that implement Clicker
type I3bar ¶
type I3bar struct {
// contains filtered or unexported fields
}
I3bar is the data structure that represents a single i3bar.
func NewI3bar ¶
NewI3bar returns a new *I3bar. The update duration determines how often data will be sent to i3bar through stdout
func (*I3bar) Order ¶
Order determines the order in which items appear on the i3bar. The given slice must have each registered key appearing in it exactly once.
type InvalidColorErr ¶
type InvalidColorErr string
func (InvalidColorErr) Error ¶
func (i InvalidColorErr) Error() string
type MultiGenerator ¶
type MultiGenerator struct {
// contains filtered or unexported fields
}
MultiGenerator is a Generator that combines the output of multiple Generators. Consistent order is not guaranteed across multiple generations
func NewMultiGenerator ¶
func NewMultiGenerator(g []Generator) MultiGenerator
NewMultiGenerator takes a slice of generators and returns a single Generator
func (MultiGenerator) Generate ¶
func (m MultiGenerator) Generate() ([]Output, error)
Generate implements Generator
type MultiProducer ¶
type MultiProducer struct {
// contains filtered or unexported fields
}
MultiProducer is a simple Producer that groups multiple Producers.
func NewMultiProducer ¶
func NewMultiProducer(m map[string]Producer) MultiProducer
NewMultiProducer creates a new MultiProducer
func (MultiProducer) MultiRegister ¶
func (m MultiProducer) MultiRegister(r registerer)
MultiRegister takes a registerer and uses it to register all of its' Producers
func (MultiProducer) Produce ¶
func (m MultiProducer) Produce(kill <-chan struct{}) <-chan []Output
Produce implements Producer
type OrderedMultiGenerator ¶
type OrderedMultiGenerator struct {
// contains filtered or unexported fields
}
OrderedMultiGenerator is a Generator that can generate output for multiple Generators, and keeps the order of outputs the same.
func (*OrderedMultiGenerator) Generate ¶
func (g *OrderedMultiGenerator) Generate() ([]Output, error)
Generate implements Generator
type Output ¶
type Output struct { Align string `json:"align,omitempty"` Color string `json:"color,omitempty"` FullText string `json:"full_text"` Instance string `json:"instance,omitempty"` MinWidth string `json:"min_width,omitempty"` Name string `json:"name,omitempty"` ShortText string `json:"short_text,omitempty"` Separator bool `json:"separator"` Urgent bool `json:"urgent"` }
Output represends a single item on the i3bar.
type Producer ¶
type Producer interface {
Produce(kill <-chan struct{}) <-chan []Output
}
A Producer pushes content updates to the i3bar. It is responsible for managing how often an item delivers its updates to the i3bar. These updates are usually generated using a Generator.
type ProducerClicker ¶
A ProducerClicker is both a Producer and a Clicker. It exists so we can have a concrete implementation built on BaseProducer that can also be used for plugins that implement Clicker
type StaticGenerator ¶
type StaticGenerator []Output
A StaticGenerator is a simple Generator that returns the same Output each time.
func (StaticGenerator) Generate ¶
func (g StaticGenerator) Generate() ([]Output, error)
Generate implements Generator