From d855a29b7673efb29b3132a59f8f48af9915a839 Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Wed, 23 Nov 2022 17:54:04 +0100 Subject: [PATCH] [Newm] Revamp display of some elements --- .config/newm/config.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/.config/newm/config.py b/.config/newm/config.py index 410f8f5..d66af8c 100644 --- a/.config/newm/config.py +++ b/.config/newm/config.py @@ -197,13 +197,28 @@ def key_bindings(layout: Layout) -> list[tuple[str, Callable[[], Any]]]: ] +battery_icons = { + 100: {True: "", False: ""}, + 90: {True: "", False: ""}, + 80: {True: "", False: ""}, + 70: {True: "", False: ""}, + 60: {True: "", False: ""}, + 50: {True: "", False: ""}, + 40: {True: "", False: ""}, + 30: {True: "", False: ""}, + 20: {True: "", False: ""}, + 10: {True: "", False: ""}, + 0: {True: "", False: ""}, +} + + def battery_status() -> str: battery = psutil.sensors_battery() - plugged = "+" if battery.power_plugged else "-" percent = format(battery.percent, ".1f") minutes = battery.secsleft // 60 remaining = "{0:0>2}:{1:0>2}".format(minutes // 60, minutes % 60) - return f"{percent}%{plugged} ({remaining})" + icon = battery_icons[(int(float(percent)) // 10) * 10][battery.power_plugged] + return f"{icon} {percent}% ({remaining})" def unread_emails() -> str: @@ -214,11 +229,11 @@ def unread_emails() -> str: check=True, ).stdout nbr_unread: int = len(str(unread).split("\n")) - return f"Emails: {nbr_unread}" + return f" {nbr_unread}" def cpu_usage() -> str: - cpu: str = format(psutil.cpu_percent(interval=None), ".1f") + cpu: str = format(psutil.cpu_percent(interval=1), ".1f") return f" {cpu}%"