Skip to content

Instantly share code, notes, and snippets.

@CRTified
Created October 1, 2017 18:15
Show Gist options
  • Save CRTified/efea3e1bc87bcfd7efe541ee55b5539d to your computer and use it in GitHub Desktop.
Save CRTified/efea3e1bc87bcfd7efe541ee55b5539d to your computer and use it in GitHub Desktop.
ACPI logger
-- Define acpi power logger
acpi_power :: String -> [String] -> Logger
acpi_power dev attr =
io $ do
attrOut <- mapM (\x -> liftIO $ readFile $ sysFsPath ++ x) attr
return $ Just $ filter (/= '\n') (intercalate " " attrOut)
where
sysFsPath = "/sys/class/power_supply/" ++ dev ++ "/"
file_reader :: String -> Logger
file_reader file =
io $ do
c <- liftIO $ readFile file
return $ Just $ filter (/= '\n') c
-- Define specific battery logger
colorBatteryBG :: String -> String
colorBatteryBG batState
| batState == "Discharging" = colors !! 1
| batState == "Charging" = colors !! 0
| otherwise = colors !! 0
colorBattery :: (Int, String) -> String
colorBattery (batVal, batState)
| batVal < 30 =
dzenColor (colors !! 8) (colorBatteryBG batState) ("░ " ++ show batVal)
| batVal < 80 =
dzenColor (colors !! 10) (colorBatteryBG batState) ("▒ " ++ show batVal)
| batVal > 95 =
dzenColor (colors !! 7) (colorBatteryBG batState) ("█ " ++ show batVal)
| otherwise =
dzenColor (colors !! 7) (colorBatteryBG batState) ("▓ " ++ show batVal)
parseBattery :: String -> (Int, String)
parseBattery cmdOut = (batVal, batState)
where
outputWords = words cmdOut
batVal = read $ outputWords !! 0 :: Int
batState = outputWords !! 1
battery =
onLogger
(colorBattery . parseBattery)
(acpi_power "BAT0" ["capacity", "status"])
acpower =
onLogger
(\x ->
case x of
"1" -> "⚡"
_ -> " ") $
acpi_power "AC" ["online"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment