summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUltrabug <ultrabug@ultrabug.net>2015-02-25 15:00:38 +0100
committerUltrabug <ultrabug@ultrabug.net>2015-02-25 15:00:38 +0100
commit8538fd563d21d4fa4611c8861794044c058ed158 (patch)
tree7ed60a3a3014cf86ba60441adaec7c76e326ae30
parent42c486bdec6f453c3db6fff2f8a88e2ec5486bea (diff)
parent044e3745ec2f0deab3fbe36582962617da4d7525 (diff)
Merge pull request #72 from jmdana/bluetooth_format
add configurable formatting to the bluetooth module by @jmdana
-rw-r--r--py3status/modules/bluetooth.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/py3status/modules/bluetooth.py b/py3status/modules/bluetooth.py
index 3585c4d..eed7692 100644
--- a/py3status/modules/bluetooth.py
+++ b/py3status/modules/bluetooth.py
@@ -23,6 +23,12 @@ class Py3status:
cache_timeout = 10
color_good = None
color_bad = None
+ format_prefix = "BT: "
+ # both {name} and {mac} are accepted
+ format = "{name}"
+ format_no_conn_prefix = "BT: "
+ format_no_conn = "OFF"
+ separator = '|'
def bluetooth(self, i3s_output_list, i3s_config):
# The whole command:
@@ -30,20 +36,29 @@ class Py3status:
out = check_output(shlex.split("hcitool con"))
macs = re.findall(BTMAC_RE, out.decode("utf-8"))
- output = "BT: "
color = self.color_bad or i3s_config['color_bad']
if macs != []:
- names = []
+ data = []
for mac in macs:
out = check_output(shlex.split("hcitool name %s" % mac))
- names.append(out.strip().decode("utf-8"))
+ fmt_str = self.format.format(
+ name=out.strip().decode("utf-8"),
+ mac=mac
+ )
+ data.append(fmt_str)
- output += "|".join(names)
+ output = "{format_prefix}{data}".format(
+ format_prefix=self.format_prefix,
+ data=self.separator.join(data)
+ )
color = self.color_good or i3s_config['color_good']
else:
- output += "OFF"
+ output = "{format_prefix}{format}".format(
+ format_prefix=self.format_no_conn_prefix,
+ format=self.format_no_conn
+ )
response = {
'cached_until': time() + self.cache_timeout,