25 lines
838 B
Haskell
25 lines
838 B
Haskell
module Main where
|
|
|
|
batteryCapacityFile :: String
|
|
batteryCapacityFile = "/sys/class/power_supply/BAT0/capacity"
|
|
|
|
batteryStatusFile :: FilePath
|
|
batteryStatusFile = "/sys/class/power_supply/BAT0/status"
|
|
|
|
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 == "Discharging" = "🙃"
|
|
| init status == "Not charging" = "♻"
|
|
| init status == "Unknown" = "Unknown"
|
|
| (read capacity :: Int) <= 20 = "🪫"
|
|
| otherwise = "Silly"
|