From 20304248aa484394debe4729c5859b529a9c2f8b Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Tue, 8 Aug 2023 03:32:24 +0200 Subject: [PATCH] Code from other project because I'm lazy --- app/Main.hs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 65ae4a0..7277ed5 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,4 +1,19 @@ -module Main where +batteryCapacityFile = "/sys/class/power_supply/BAT0/capacity" :: FilePath +batteryStatusFile = "/sys/class/power_supply/BAT0/status" :: FilePath main :: IO () -main = putStrLn "Hello, Haskell!" +main = do + batteryCapacity <- readFile batteryCapacityFile + batteryStatus <- readFile batteryStatusFile + putStrLn $ formatInfo batteryStatus batteryCapacity + +formatInfo :: String -> String -> String +formatInfo status capacity = icon ++ " " ++ init capacity ++ "%" + where icon + | init status == "Full" = "🙂" + | init status == "Charging" = "🔋" + | init status == "Not charging" = "â™ģ" + | init status == "Unknown" = "Unknown" + | read capacity <= 20 = "đŸĒĢ" + | read capacity <= 100 = "🙃" + | otherwise = "Silly"