Documentation ¶
Overview ¶
Package bitbar simplifies the creation of Bitbar plugins.
Provides helper functions for adding lines and submenus along with setting command, style options etc using function chaining.
See the BitBar project for more info - https://github.com/matryer/bitbar
Example ¶
Example Bitbar plugin resulting in the following output:
MenuItem 1 | color=red href=http://localhost:8080 dropdown=false MenuItem 2 | dropdown=false --- DropDown Level 1 A | color=red font=UbuntuMono-Bold size=12 -- DropDown Level 2 A -- DropDown Level 1 B | bash="/path/to/cmd" param1=arg1 param2=arg2 ---- DropDown Level 3 A DropDown Level 1 B | color=red font=UbuntuMono-Bold size=12
b := New() s := Style{ Font: "UbuntuMono-Bold", Color: "red", Size: 12, } c := Cmd{ Bash: "/path/to/cmd", Params: []string{"arg1", "arg2"}, } b.StatusLine("MenuItem 1").Href("http://localhost:8080").Color("red").DropDown(false) b.StatusLine("MenuItem 2").DropDown(false) menu := b.NewSubMenu() menu.Line("DropDown Level 1 A").Style(s) submenu := b.SubMenu.NewSubMenu() submenu.Line("DropDown Level 2 A") submenu.Line("DropDown Level 1 B").Command(c) subsubmenu := submenu.NewSubMenu() subsubmenu.Line("DropDown Level 3 A") menu.Line("DropDown Level 1 B").Style(s) b.Render()
Output:
Index ¶
- type Cmd
- type Line
- func (l *Line) Alternate(b bool) *Line
- func (l *Line) Ansi(b bool) *Line
- func (l *Line) Bash(s string) *Line
- func (l *Line) Color(s string) *Line
- func (l *Line) Command(c Cmd) *Line
- func (l *Line) CopyToClipboard(text string) *Line
- func (l *Line) DropDown(b bool) *Line
- func (l *Line) Emojize(b bool) *Line
- func (l *Line) Font(s string) *Line
- func (l *Line) Href(s string) *Line
- func (l *Line) Image(img image.Image) *Line
- func (l *Line) Length(i int) *Line
- func (l *Line) Params(s []string) *Line
- func (l *Line) Refresh() *Line
- func (l *Line) Size(i int) *Line
- func (l *Line) Style(s Style) *Line
- func (l *Line) TemplateImage(s string) *Line
- func (l *Line) Terminal(b bool) *Line
- func (l *Line) Trim(b bool) *Line
- type Plugin
- type StatusBar
- type Style
- type SubMenu
- type SubMenuItem
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cmd ¶
Cmd wraps options related to commands which can be added to a line using the *line.Command(c Cmd) function.
type Line ¶
type Line struct {
// contains filtered or unexported fields
}
Line holds the content, styling and behaviour of a line in a Bitbar menu, both in the menu and submenus
func (*Line) Alternate ¶
Alternate sets a flag to mark a line as an alternate to the previous one for when the Option key is pressed in the dropdown.
line.Alternate(false)
func (*Line) Bash ¶
Bash makes makes the line clickable and adds a script that will be run on click.
line.Bash("/Users/user/BitBar_Plugins/scripts/nginx.restart.sh")
func (*Line) Color ¶
Color sets the lines font color, can take a name or hex value.
line.Color("red") line.Color("#ff0000")
func (*Line) Command ¶
Command provides a alternate method for setting the bash script and params along with some related flags via a Command struct.
cmd := bitbar.Cmd{ Bash: "/Users/user/BitBar_Plugins/scripts/nginx.restart.sh", Params: []string{"--verbose"}, Terminal: false, Refresh: true, } line.Command(cmd)
func (*Line) CopyToClipboard ¶
CopyToClipboard is a helper to copy the specified text to the OSX clipboard.
line.CopyToClipboard("some text")
func (*Line) DropDown ¶
DropDown sets a flag which controls whether the line only appears and cycles in the status bar but not in the dropdown.
line.DropDown(false)
func (*Line) Emojize ¶
Emojize sets a flag to control parsing of github style :mushroom: into 🍄.
line.Emojize(false)
func (*Line) Href ¶
Href adds a URL to the line and makes it clickable.
line.Href("http://github.com/johnmccabe/bitbar")
func (*Line) Image ¶
Image set an image for the line. Use a 144 DPI resolution to support Retina displays.
line.Image(myImg)
func (*Line) Length ¶
Length truncates the line after the specified number of characters. An elipsis will be added to any truncated strings, as well as a tooltip displaying the full string.
line.DropDown(false)
func (*Line) Params ¶
Params adds arguments which are passed to the script specified by *Line.Bash().
args := []string{"--verbose"} line.Bash("/Users/user/BitBar_Plugins/scripts/nginx.restart.sh").Params(args)
func (*Line) Refresh ¶
Refresh controls whether clicking the line results in the plugin being refreshed. If the line has a bash script attached then the plugin is refreshed after the script finishes.
line.Bash("/Users/user/BitBar_Plugins/scripts/nginx.restart.sh").Refresh() line.Refresh()
func (*Line) Style ¶
Style provides a alternate method for setting the text style related options.
style := bitbar.Style{ Color: "red", Font: "UbuntuMono-Bold", Size: 14, Length: 20, Trim: false, Emojize: false, Ansi: false, } line.Style(false)
func (*Line) TemplateImage ¶
TemplateImage sets an image for the line. The image data must be passed as base64 encoded string and should consist of only black and clear pixels. The alpha channel in the image can be used to adjust the opacity of black content, however. This is the recommended way to set an image for the statusbar. Use a 144 DPI resolution to support Retina displays. The imageformat can be any of the formats supported by Mac OS X.
line.TemplateImage("iVBORw0KGgoAAAANSUhEUgAAA...")
type Plugin ¶
Plugin holds the content of the Bitbar plugin, lines and submenus.
func (*Plugin) StatusLine ¶
StatusLine creates a line adding text to the status bar which will be added before the main dropdown delimiter (`---`), multiple StatusLines will be cycled through over and over.
*menu.StatusLine("Text for the status bar")
type StatusBar ¶
type StatusBar struct {
Lines []*Line
}
StatusBar holds one of more Lines of text which are rendered in the status bar. Multiple Lines will be cycled through over and over
type Style ¶
type Style struct { Color string Font string Size int Length int Trim *bool Emojize *bool Ansi *bool }
Style wraps options related to text presentation which can be added to a line using the *line.Style(s Style) function.
type SubMenu ¶
type SubMenu struct { Level int Lines []SubMenuItem }
SubMenu contains a slice of SubMenuItems which can be Lines or additional SubMenus. The Level indicates how nested the submenu is which is used during render to prepend the correct number of `--` prefixes.
func (*SubMenu) HR ¶
HR turns a line into a horizontal delimiter, useful for breaking menu items into logical groups.
submenu.Line("").HR()
func (*SubMenu) Image ¶
Image adds a line with an image to the dropdown which will be added after the main dropdown delimiter (`---`). Use a 144 DPI resolution to support Retina displays.
line.Image(myImg)
func (*SubMenu) Line ¶
Line creates a line adding text to the dropdown which will be added after the main dropdown delimiter (`---`).
submenu.Line("Submenu item text")
func (*SubMenu) NewSubMenu ¶
NewSubMenu creates a nested submenu off a submenu.
submenu.NewSubMenu()