diff options
Diffstat (limited to 'users/kassouni/palette')
| -rw-r--r-- | users/kassouni/palette/bluetooth.nix | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/users/kassouni/palette/bluetooth.nix b/users/kassouni/palette/bluetooth.nix index 71e1aaf..4d2a594 100644 --- a/users/kassouni/palette/bluetooth.nix +++ b/users/kassouni/palette/bluetooth.nix @@ -13,14 +13,13 @@ # The interpolated store paths below are longer than 79 columns. flakeIgnore = [ "E501" ]; } '' - import html import json import subprocess import sys BT = "${pkgs.bluez}/bin/bluetoothctl" JC = "${pkgs.jc}/bin/jc" - ROFI = "${pkgs.rofi}/bin/rofi" + FUZZEL = "${pkgs.fuzzel}/bin/fuzzel" def devices(*args): @@ -38,10 +37,9 @@ def label(device, connected): - """Pango markup row. Names are escaped, they are not our text.""" - name = html.escape(device["name"]) + name = device["name"] if device["address"] in connected: - name += ' <span alpha="45%">connected</span>' + name += " (connected)" return name @@ -56,8 +54,7 @@ rows = [label(d, connected) for d in known] choice = subprocess.run( - [ROFI, "-dmenu", "-i", "-markup-rows", "-format", "i", - "-p", "bluetooth"], + [FUZZEL, "--dmenu", "--index", "--prompt", "bluetooth "], input="\n".join(rows), capture_output=True, text=True, @@ -65,7 +62,11 @@ if choice.returncode != 0: return 1 - device = known[int(choice.stdout.strip())] + index = int(choice.stdout.strip() or -1) + if not 0 <= index < len(known): + return 1 + + device = known[index] action = ( "disconnect" if device["address"] in connected else "connect" ) |
