obtuse/app/Main.hs

20 lines
765 B
Haskell
Raw Normal View History

batteryCapacityFile = "/sys/class/power_supply/BAT0/capacity" :: FilePath
batteryStatusFile = "/sys/class/power_supply/BAT0/status" :: FilePath
2023-08-08 03:31:10 +02:00
main :: IO ()
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"