matryer / xbar

Put the output from any script or program into your macOS Menu Bar (the BitBar reboot)
https://xbarapp.com
MIT License
17.59k stars 642 forks source link

coding question #477

Closed C4Wiz closed 6 years ago

C4Wiz commented 6 years ago

here is my code it returns true or false, how do i make it so if it returns true it's one color, and if it returns false it's another, but keep the Update text black?

print("Update: %s" % versions['core_update']) + "| color=black"

gingerbeardman commented 6 years ago

Use ANSI escape codes to change the text in the middle of the printed string.

See https://github.com/matryer/bitbar-plugins/blob/master/Tutorial/ansi.sh

This example picks a random colour (red/green) for the random number that comes after "Update:"

#!/usr/bin/env php
<?php

$GREEN = "\033[32m";
$RED = "\033[31m";
$BLACK = "\033[0m";

$COLOUR = (rand(0,1)) ? $RED : $GREEN;

printf("Update: $COLOUR%s", rand(0,10)) . "$BLACK| ansi=true color=black";
C4Wiz commented 6 years ago

i thank you for your responce, but again no idea what you mean.

gingerbeardman commented 6 years ago

Please remove your code, put it in a pastebin

i thank you for your responce, but again no idea what you mean. here is my complete code

Your task is to figure out how the Tutorial and my simple example work. 🔰 💯

C4Wiz commented 6 years ago

https://pastebin.com/zQmtzV6b

gingerbeardman commented 6 years ago

I'm happy to help/guide you, but I won't do it for you :)

Ask specific questions and I will explain to you the answer.

C4Wiz commented 6 years ago

@gingerbeardman i think im close but i get a syntax error on this line: if not versions['core_current'] == versions[core_latest']:

print("Core: %s (%s)" % (versions['core_current'],
                         versions['core_branch'])) + "| color=black"
    if not versions['core_current'] == versions[core_latest']:
     print("Update available: %s" % versions['core_latest']) + "| color=red"
    else:
     print("Up to date| color=green")
C4Wiz commented 6 years ago

i actually figured it out!

    print("Core: %s (%s)" % (versions['core_current'],
                             versions['core_branch'])) + "| color=black"
    if versions['core_current'] != versions['core_latest']:
     print("Update available: %s" % versions['core_latest']) + "| color=red"
    else:
     print("Up to date| color=green")