swiftbar

package module
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 6 Imported by: 0

README

go-bitbar logo

Travis Badge Go Report Card Badge GoDoc Badge

This repo contains a package for creating SwiftBar plugins in Go.

It is forked by me chew-z from go-bitbar and all credits should go there. I have just added logic for Swiftbar's WebView component. And in the future I hope to add some more logic (Swiftbar has some extended capabilities over original Bitbar and xbar (Bitbar reboot)) and push PR.

Usage

Creating a BitBar plugin is as simple as (see the godocs for more details):

package main

import "github.com/johnmccabe/go-bitbar"

func main() {
    app := bitbar.New()
    app.StatusLine("Hello")

    submenu := app.NewSubMenu()
    submenu.Line("World!")

    app.Render()
}

Examples

swiftbar

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	Bash     string
	Params   []string
	Terminal *bool
	Refresh  *bool
}

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

func (l *Line) Alternate(b bool) *Line

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) Ansi

func (l *Line) Ansi(b bool) *Line

Ansi sets a flag to control parsing of ANSI codes.

line.Ansi(false)

func (*Line) Bash

func (l *Line) Bash(s string) *Line

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

func (l *Line) Color(s string) *Line

Color sets the lines font color, can take a name or hex value.

line.Color("red")
line.Color("#ff0000")

func (*Line) Command

func (l *Line) Command(c Cmd) *Line

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

func (l *Line) CopyToClipboard(text string) *Line

CopyToClipboard is a helper to copy the specified text to the OSX clipboard.

line.CopyToClipboard("some text")

func (*Line) DropDown

func (l *Line) DropDown(b bool) *Line

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

func (l *Line) Emojize(b bool) *Line

Emojize sets a flag to control parsing of github style :mushroom: into 🍄.

line.Emojize(false)

func (*Line) Font

func (l *Line) Font(s string) *Line

Font sets the lines font.

line.Font("UbuntuMono-Bold")

func (*Line) Href

func (l *Line) Href(s string) *Line

Href adds a URL to the line and makes it clickable.

line.Href("http://github.com/johnmccabe/bitbar")

func (*Line) Image

func (l *Line) Image(img image.Image) *Line

Image set an image for the line. Use a 144 DPI resolution to support Retina displays.

line.Image(myImg)

func (*Line) Length

func (l *Line) Length(i int) *Line

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

func (l *Line) Params(s []string) *Line

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

func (l *Line) Refresh() *Line

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) Size

func (l *Line) Size(i int) *Line

Size sets the lines font size.

line.Size(12)

func (*Line) Style

func (l *Line) Style(s Style) *Line

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

func (l *Line) TemplateImage(s string) *Line

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...")

func (*Line) Terminal

func (l *Line) Terminal(b bool) *Line

Terminal sets a flag which controls whether a Terminal is opened when the bash script is run.

line.Bash("/Users/user/BitBar_Plugins/scripts/nginx.restart.sh").Terminal(true)

func (*Line) Trim

func (l *Line) Trim(b bool) *Line

Trim sets a flag to control whether leading/trailing whitespace is trimmed from the title. Defaults to `true`.

line.Trim(false)

func (*Line) WebView

func (l *Line) WebView(url string, dim ...string) *Line

WebView adds a URL to the line and makes it clickable.

line.WebView("http://github.com/johnmccabe/bitbar", 800, 640)

type Plugin

type Plugin struct {
	StatusBar StatusBar
	SubMenu   *SubMenu
}

Plugin holds the content of the Bitbar plugin, lines and submenus.

func New

func New() Plugin

New returns an empty Bitbar menu without any context

func (*Plugin) NewSubMenu

func (p *Plugin) NewSubMenu() *SubMenu

NewSubMenu creates a submenu off the main menu.

*menu.NewSubMenu()

func (*Plugin) Render

func (p *Plugin) Render()

Render the Bitbar menu to Stdout.

func (*Plugin) StatusLine

func (p *Plugin) StatusLine(s string) *Line

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 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 (d *SubMenu) HR() *Line

HR turns a line into a horizontal delimiter, useful for breaking menu items into logical groups.

submenu.Line("").HR()
func (d *SubMenu) Image(img image.Image) *Line

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 (d *SubMenu) Line(s string) *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 (d *SubMenu) NewSubMenu() *SubMenu

NewSubMenu creates a nested submenu off a submenu.

submenu.NewSubMenu()
type SubMenuItem interface{}

SubMenuItem is used to hold a Line or SubMenu.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL