Crate bitbar[][src]

This is bitbar, a library crate which includes helpers for writing BitBar or SwiftBar plugins in Rust.

There are two main entry points:

  • It's recommended to use the main attribute and write a main function that returns a Menu, along with optional command functions and an optional fallback_command function.
  • For additional control over your plugin's behavior, you can directly Display a Menu.

Features

The following feature is enabled by default:

  • tokio: Adds a dependency to the tokio crate, allowing you to use async fns with the main attribute.

The following features can be enabled via Cargo:

  • base64: Adds a depencency to the base64 crate and implements conversion methods from PNG files that aren't already base64-encoded to Images.
  • css-colors: Adds a dependency to the css-colors crate and implements IntoColor for its color types RGB, RGBA, HSL, and HSLA.
  • image: Adds a depencency to the image crate. If the base64 feature is also enabled, implements TryFrom<DynamicImage> for Image.
  • serenity: Adds a dependency to the serenity crate and implements IntoColor for its Colour type.
  • tokio02: Adds a dependency to the outdated version 0.2 of the tokio crate, allowing you to use async fns with the main attribute while using that version's runtime. The tokio feature should be disabled when using this feature.
  • tokio03: Adds a dependency to the outdated version 0.3 of the tokio crate, allowing you to use async fns with the main attribute while using that version's runtime. The tokio feature should be disabled when using this feature.
  • url1: Adds a dependency to the outdated version 1 of the url crate and implements IntoUrl for its Url type.

Example

use bitbar::{Menu, MenuItem};

#[bitbar::main]
fn main() -> Menu {
    Menu(vec![
        MenuItem::new("Title"),
        MenuItem::Sep,
        MenuItem::new("Menu Item"),
    ])
}

Or:

use bitbar::{Menu, MenuItem};

fn main() {
    print!("{}", Menu(vec![
        MenuItem::new("Title"),
        MenuItem::Sep,
        MenuItem::new("Menu Item"),
    ]));
}

Structs

Command

Used by ContentItem::command.

ContentItem

A menu item that's not a separator.

Image

Used by ContentItem::image and ContentItem::template_image.

Menu

A BitBar menu.

Enums

Extra

A menu item's alternate mode or submenu.

MenuItem

A menu item can either be a separator or a content item.

Params

BitBar only supports up to five parameters for bash= commands (see https://github.com/matryer/bitbar/issues/490).

Traits

CommandOutput

Members of this trait can be returned from a subcommand function annotated with [bitbar::command] or [bitbar::fallback_command].

IntoColor

Used by ContentItem::color.

IntoUrl

Used by ContentItem::href.

MainOutput

Members of this trait can be returned from a main function annotated with [bitbar::main].

Attribute Macros

command

Registers a subcommand that you can run from a menu item's command.

fallback_command

Registers a function that is called when no other bitbar::command matches.

main

Annotate your main function with this.