METADATA = {'version': 1}
+CMD_PASTE = 'wl-paste'
+CLIP_LEN_MAX = 32
+MSG_CLIPBOARD_EMPTY = 'Nothing is copied'
+
AUDIO_DEVS_LABELS = (('sink', 'vol'),
('source', '--mic'))
return int(stripped_text)
+def info_clipboard(
+ ) -> tuple[str, ...]:
+ 'Produce clipboard contents summary.'
+ texts = []
+ args: tuple[str, ...]
+ for args in (tuple(), ('--primary',)):
+ proc = subprocess_run((CMD_PASTE,) + args,
+ check=False, capture_output=True)
+ if proc.returncode:
+ stderr = proc.stderr.decode('utf8', 'replace').strip()
+ clip = '(empty)' if stderr == MSG_CLIPBOARD_EMPTY else '(error)'
+ else:
+ try:
+ clip = proc.stdout.decode('utf8').replace('\n', ' ').strip()
+ except UnicodeDecodeError:
+ clip = '(binary)'
+ if len(clip) > CLIP_LEN_MAX:
+ clip = clip[:CLIP_LEN_MAX] + '…'
+ texts += [f'{(args[0] if args else CMD_PASTE)}: [{clip}]']
+ return tuple(texts)
+
+
def info_audio(
) -> str:
"Produce audio devices' volume, muteness."
print('[', end='')
while True:
print(json_dumps([{'full_text': text}
- for text in info_network() + (info_battery(),
- info_thermal(),
- info_datetime(),
- info_audio())]),
+ for text in info_clipboard() + info_network() + (
+ info_battery(),
+ info_thermal(),
+ info_datetime(),
+ info_audio())]),
end=',\n', flush=True)
sleep(1)