Created
February 14, 2021 22:13
-
-
Save paulc/a9bb09131570a3528b7066b05bd4d0c2 to your computer and use it in GitHub Desktop.
Some useful utils for BitBar/SwiftBar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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