Documentation ¶
Overview ¶
Package statusbar displays various information on the dwm statusbar.
The design of this statusbar manager is modular by nature; you create the main process with this package and then populate it with only the information you want using individual modules. For example, if you want to show only the time and weather, then you would import only those two modules and add their objects to the statusbar, resulting in only the time and weather to appear on the statusbar for dwm. This modular design allows flexibility in customizing each individual statusbar and ease in management.
This package is the engine that controls the modular routines. For the modules currently integrated with this framework and included in this repository, see the child packages that begin with "sb". There are currently modules that display a range of information, including various system resources, personal TODO lists, the current weather, VPN status, and the current time.
To integrate a custom module into this statusbar framework, the routine's object needs to implement the RoutineHandler interface, which includes these methods:
Update() (bool, error) String() string Error() string Name() string
It is suggested that this object be created by New(), which will also initialize any members of the object (if needed).
The sample code below creates a new statusbar, adds some routines to it, and begins displaying the formatted output. In dwm, we are using the dualstatus patch, which creates a top and bottom bar for extra statusbar real estate. The top bar will display the time, and the bottom bar will display the disk usage and CPU stats.
import ( "github.com/snhilde/statusbar" "github.com/snhilde/statusbar/sbtime" "github.com/snhilde/statusbar/sbdisk" "github.com/snhilde/statusbar/sbcpuusage" "github.com/snhilde/statusbar/sbcputemp" ) func main() { // Create the initial engine. bar := statusbar.New() // sbtime.New() takes two arguments: time format and a triplet of color codes for normal, warning, and error // outputs. It returns a new routine that implements the RoutineHandler interface. // bar.Append() takes two arguments: the new routine object and the update interval (how often in seconds the // routine should run its Update() method). bar.Append(sbtime.New("Jan 2 - 03:04", [3]string{"#FFFFFF", "#BB4F2E", "#A1273E"}), 1) // This inserts the splitting character for the dualstatus patch. Before this is called, the routines already // added are displayed on the top bar. After this is called, all subsequently added routines are displayed on // the bottom bar. bar.Split() // The second bar will start with the output from the disk routine. It will display the space used // and total space of the given filesystem. The routine will update every 5 seconds. bar.Append(sbdisk.New([]string{"/"}, [3]string{"#FFFFFF", "#BB4F2E", "#A1273E"}), 5) // The next two routines will display (separately) the current percentage of CPU used and the // temperature of the CPU, each updated every second. bar.Append(sbcpuusage.New([3]string{"#FFFFFF", "#BB4F2E", "#A1273E"}), 1) bar.Append(sbcputemp.New([3]string{"#8FFFFF", "#BB4F2E", "#A1273E"}), 1) // The statusbar will now run indefinitely, updating every routine at the provided interval. All routines run // concurrently in their own thread and are independent of each other. bar.Run() }
Package statusbar formats and displays information on the dwm statusbar by managing modular data routines.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RoutineHandler ¶
type RoutineHandler interface { // Update updates the routine's information. This is run on a periodic interval according to the time provided when // adding the routine to the statusbar engine. It returns two arguments: a bool and an error. The bool indicates // whether or not the engine should continue to run the routine. You can think of it as representing the "ok" // status. The error is any error encountered during the process. For example, on a normal run with no error, Update // would return (true, nil). On a run with a non-critical error, Update would return (true, error). On a run with a // critical error where the routine should be stopped, Update would return (false, error). The returned error will // be logged to stderr. Generally, the error returned from Update should be detailed and specific for debugging the // routine, while the error returned from Error should be shorter, more concise, and more general. Update() (bool, error) // String formats and returns the routine's output. String() string // Error formats and returns an error message. Generally, the error returned from Error should be shorter, more // concise, and more general, while the error returned from Update should be detailed and specific for debugging the // routine. Error() string // Name returns the display name of the module. Name() string }
RoutineHandler allows information monitors (commonly called routines) to be linked in.
type Statusbar ¶
type Statusbar struct {
// contains filtered or unexported fields
}
Statusbar is the main type for this package. It holds information about the bar as a whole.
func New ¶
func New() Statusbar
New creates a new statusbar. The default delimiters around each routine are square brackets ('[' and ']').
func (*Statusbar) Append ¶
func (sb *Statusbar) Append(handler RoutineHandler, seconds int)
Append adds a routine to the statusbar's list. Routines are displayed in the order they are added. handler is the RoutineHandler module. seconds is the amount of time between each run of the routine.
Example ¶
// Add the sbtime routine to our statusbar. // sbtime.New() takes two arguments: the format to use for the time string and a triplet of color codes. timeFmt := "Jan 2 - 03:04" colorNormal := "#FFFFFF" colorWarning := "#BB4F2E" colorError := "#A1273E" colors := [3]string{colorNormal, colorWarning, colorError} // Create a new routine. timeRoutine := sbtime.New(timeFmt, colors) // Append the routine to the bar. bar.Append(timeRoutine, 1) // Or, as a one-liner: bar.Append(sbtime.New("Jan 2 - 03:04", [3]string{"#FFFFFF", "#BB4F2E", "#A1273E"}), 1)
Output:
func (*Statusbar) EnableRESTAPI ¶
EnableRESTAPI enables the engine to run the REST API on port port. These can be used to interact with the statusbar and its routines while they are running.
func (*Statusbar) Run ¶
func (sb *Statusbar) Run()
Run spins up all the routines and displays them on the statusbar. If the APIs are enabled, this also runs the API engines.
func (*Statusbar) SetMarkers ¶
SetMarkers sets the left and right delimiters around each routine. If not set, these will default to '[' and ']'.
func (*Statusbar) Split ¶
func (sb *Statusbar) Split()
Split splits the statusbar at this point, when using dualstatus patch for dwm. A semicolon (';') is inserted at this point in the routine list, which signals to dualstatus to split the statusbar at this point. Before this is called, the routines already added are displayed on the top bar. After this is called, all subsequently added routines are displayed on the bottom bar.
Directories ¶
Path | Synopsis |
---|---|
Package restapi implements a REST API engine using the Gin routing framework.
|
Package restapi implements a REST API engine using the Gin routing framework. |
Package sbbattery displays the percentage of battery capacity left with a charging status indicator.
|
Package sbbattery displays the percentage of battery capacity left with a charging status indicator. |
Package sbcputemp displays the temperature of the CPU in degrees Celsius.
|
Package sbcputemp displays the temperature of the CPU in degrees Celsius. |
Package sbcpuusage displays the percentage of CPU resources currently being used.
|
Package sbcpuusage displays the percentage of CPU resources currently being used. |
Package sbdisk displays disk resources for each filesystem provided.
|
Package sbdisk displays disk resources for each filesystem provided. |
Package sbfan displays the current fan speed in RPM.
|
Package sbfan displays the current fan speed in RPM. |
Package sbgithubclones displays the daily and weekly clone count for a Github repository.
|
Package sbgithubclones displays the daily and weekly clone count for a Github repository. |
Package sbload displays the average system load over the last one, five, and fifteen minutes.
|
Package sbload displays the average system load over the last one, five, and fifteen minutes. |
Package sbnetwork displays the number of bytes sent and received per given time period for either the provided network interfaces or the ones currently marked as active.
|
Package sbnetwork displays the number of bytes sent and received per given time period for either the provided network interfaces or the ones currently marked as active. |
Package sbnordvpn displays the current status of the NordVPN connection, including the city and any connection errors.
|
Package sbnordvpn displays the current status of the NordVPN connection, including the city and any connection errors. |
Package sbram displays the currently used and total system memory.
|
Package sbram displays the currently used and total system memory. |
Package sbtime displays the current time in the provided format.
|
Package sbtime displays the current time in the provided format. |
Package sbtodo displays the first two lines of a TODO list.
|
Package sbtodo displays the first two lines of a TODO list. |
Package sbvolume displays the current volume as a percentage.
|
Package sbvolume displays the current volume as a percentage. |
Package sbweather displays the current weather in the provided zip code.
|
Package sbweather displays the current weather in the provided zip code. |