Crate bitbar

Source
Expand description

This is bitbar, a library crate which includes helpers for writing BitBar plugins in Rust. BitBar is a system that makes it easy to add menus to the macOS menu bar. There are two apps implementing the BitBar system: SwiftBar and xbar. This crate supports both of them, as well as the discontinued original BitBar app.

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.

BitBar plugins must have filenames of the format name.duration.extension, even though macOS binaries normally don’t have extensions. You will have to add an extension, e.g. .o, to make Rust binaries work as plugins.

§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"),
    ]));
}

There is also a list of real-world examples.

Re-exports§

pub use crate::flavor::Flavor;

Modules§

attr
Parameters for modifying the appearance or behavior of ContentItems.
flavor
Features specific to individual BitBar implementations (e.g. SwiftBar)

Structs§

ContentItem
A menu item that’s not a separator.
Menu
A BitBar menu.

Enums§

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

Traits§

AsyncMainOutputtokio
Members of this trait can be returned from a main function annotated with main.
CommandOutput
Members of this trait can be returned from a subcommand function annotated with command or fallback_command.
MainOutput
Members of this trait can be returned from a main function annotated with main.

Attribute Macros§

command
Registers a subcommand that you can run from a menu item’s command.
fallback_command
Defines a function that is called when no other bitbar::command matches.
main
Annotate your main function with this.