From e4623831ab548e9d6f9a38b872b8a4795aad855d Mon Sep 17 00:00:00 2001 From: Konstantin Koslowski Date: Wed, 12 May 2021 07:37:35 +0200 Subject: [PATCH] waybar: more improvements to waybar_khal --- bin/waybar_khal.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/bin/waybar_khal.py b/bin/waybar_khal.py index c5c4b04..4b7b64f 100755 --- a/bin/waybar_khal.py +++ b/bin/waybar_khal.py @@ -4,6 +4,8 @@ from datetime import date, datetime, timedelta import json from html import escape +TEXT_MAX_LEN = 40 + today = date.today().strftime("%Y-%m-%d") days = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Today", "Tomorrow" ] @@ -17,9 +19,9 @@ start = subprocess.check_output("khal list --format \"{start}\" now "+next_week, end = subprocess.check_output("khal list --format \"{end}\" now "+next_week, shell=True).decode("UTF-8").split("\n") -text = "" +text = "-" +tooltip = "" alt = "idle" -event = "-" for i in range(len(title)): t = escape(title[i]) s = escape(start[i]) @@ -47,18 +49,22 @@ for i in range(len(title)): ## ongoing if ts_start < ts_now: if ts_start < ts_now and ts_now < ts_end: - event = f"{t}" + text = f"{t_start[1]} - {t_end[1]} {t}" alt = "now" ## upcoming - elif event == "-": - event = f"{t}" + elif text == "-": + text = f"{t_start[1]} - {t_end[1]} {t}" alt = "today" line = f"{t_start[1]} - {t_end[1]}: {t}" - text += f"\n{line}" + tooltip += f"\n{line}" + data = {} -data["text"] = event + +if len(text) > TEXT_MAX_LEN: + text = f"{text[0:TEXT_MAX_LEN]}…" +data["text"] = text data["alt"] = alt -data["tooltip"] = text +data["tooltip"] = tooltip print(json.dumps(data))