From 9f88fc3b0416f7810eb56e95b23365869af1af50 Mon Sep 17 00:00:00 2001 From: "J.M. Dana" Date: Tue, 24 Feb 2015 22:15:34 +0000 Subject: [bluetooth] separator is configurable now --- py3status/modules/bluetooth.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/py3status/modules/bluetooth.py b/py3status/modules/bluetooth.py index 3585c4d..30f270b 100644 --- a/py3status/modules/bluetooth.py +++ b/py3status/modules/bluetooth.py @@ -23,6 +23,7 @@ class Py3status: cache_timeout = 10 color_good = None color_bad = None + separator = '|' def bluetooth(self, i3s_output_list, i3s_config): # The whole command: @@ -39,7 +40,7 @@ class Py3status: out = check_output(shlex.split("hcitool name %s" % mac)) names.append(out.strip().decode("utf-8")) - output += "|".join(names) + output += self.separator.join(names) color = self.color_good or i3s_config['color_good'] else: -- cgit v1.3 From 044e3745ec2f0deab3fbe36582962617da4d7525 Mon Sep 17 00:00:00 2001 From: "J.M. Dana" Date: Tue, 24 Feb 2015 22:37:45 +0000 Subject: [bluetooth] Configurable formatting format_prefix: the prefix string that will be shown when there are active connections. format: the string that will be shown when there are active connections. Accepts the placeholders {name} and {mac}. format_no_conn_prefix: the prefix string that will be shown when there are no connections. format_no_conn: the string that will be shown if there are no connections. --- py3status/modules/bluetooth.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/py3status/modules/bluetooth.py b/py3status/modules/bluetooth.py index 30f270b..eed7692 100644 --- a/py3status/modules/bluetooth.py +++ b/py3status/modules/bluetooth.py @@ -23,6 +23,11 @@ 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): @@ -31,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 += self.separator.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, -- cgit v1.3