SteveEdson / bitbar-php

PHP formatter for BitBar plugins
MIT License
67 stars 7 forks source link

Sub-menu support documentation #12

Closed dg01d closed 6 years ago

dg01d commented 6 years ago

Hi Steve,

Love the library, makes lines and dropdowns a breeze, but:

As of v1.8.0, Bitbar supports sub menus.

Could you explain how it supports them? I can see that the logic in the file is public function addSubMenu() but I can't get this to work in my scripts.

SteveEdson commented 6 years ago

Thanks!

No problem, i'll update the readme, but here's how it can be done:

// Create BitBar formatter
$bb = new BitBar();

// Create the first line
$line = $bb->newLine();

// Set the text and formatting
$mainMenu = $line
    ->setText("Servers")
    ->setColour("yellow");

$mainMenu = $mainMenu->addSubMenu()
    ->newLine()
    ->setText("Server 1")
    ->setUrl('http://server1.com');

$mainMenu = $mainMenu->addSubMenu()
    ->newLine()
    ->setText("Server 2")
    ->setUrl('http://server2.com');

$mainMenu->show();

Thanks!