Skip to content

Instantly share code, notes, and snippets.

@paulc
Created February 14, 2021 22:13
Show Gist options
  • Save paulc/a9bb09131570a3528b7066b05bd4d0c2 to your computer and use it in GitHub Desktop.
Save paulc/a9bb09131570a3528b7066b05bd4d0c2 to your computer and use it in GitHub Desktop.
Some useful utils for BitBar/SwiftBar
import shlex
#
# Some useful utils for BitBar/SwiftBar
#
class Line:
def __init__(self,text,**params):
self.text = text
self.params = params
def quote_params(self):
return " ".join([f"{k}={shlex.quote(str(v))}" for k,v in self.params.items()])
def __str__(self):
if self.params:
return f"{self.text} | {self.quote_params()}"
else:
return f"{self.text}"
class Bar:
def __init__(self,header,*lines):
self.header = header
self.lines = lines
def __str__(self):
if self.lines:
return "\n".join([str(self.header),"---",*map(str,self.lines)])
else:
return str(self.header)
class Menu:
def __init__(self,title,*items):
self.title = title
self.items = items
def __str__(self):
return "\n".join([str(self.title),*[f"-- {v}" for v in self.items]])
class Seperator:
def __str__(self):
return "---"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment