From fdb7a7b876fc0b46ff36751642cbc05ed4140232 Mon Sep 17 00:00:00 2001 From: Kleidi Bujari Date: Sun, 9 Aug 2026 17:38:22 -0700 Subject: init dfetch for system queries --- packages/code/dfetch/app/Dfetch/Battery.hs | 26 ++++++++++++++++++++++++++ packages/code/dfetch/app/Dfetch/Brightness.hs | 8 ++++++++ 2 files changed, 34 insertions(+) create mode 100644 packages/code/dfetch/app/Dfetch/Battery.hs create mode 100644 packages/code/dfetch/app/Dfetch/Brightness.hs (limited to 'packages/code/dfetch/app/Dfetch') diff --git a/packages/code/dfetch/app/Dfetch/Battery.hs b/packages/code/dfetch/app/Dfetch/Battery.hs new file mode 100644 index 0000000..6e6a0a8 --- /dev/null +++ b/packages/code/dfetch/app/Dfetch/Battery.hs @@ -0,0 +1,26 @@ +module Dfetch.Battery + ( Battery(..) + , allBatteries + ) where + +import System.FilePath (()) +import System.Directory (listDirectory) +import Data.List (isPrefixOf) + +basePath :: FilePath +basePath = "/sys/class/power_supply/" + +data Battery = Battery + {name :: String, capacity :: Int} deriving (Show) + +getCapacity :: String -> IO Battery +getCapacity name = Battery <$> pure name <*> capacity + where + path = basePath name "capacity" + capacity = read <$> readFile path + +findBatteries :: IO [String] +findBatteries = filter ("BAT" `isPrefixOf`) <$> listDirectory basePath + +allBatteries :: IO [Battery] +allBatteries = findBatteries >>= traverse getCapacity diff --git a/packages/code/dfetch/app/Dfetch/Brightness.hs b/packages/code/dfetch/app/Dfetch/Brightness.hs new file mode 100644 index 0000000..912905a --- /dev/null +++ b/packages/code/dfetch/app/Dfetch/Brightness.hs @@ -0,0 +1,8 @@ +module Dfetch.Brightness where + +import System.FilePath (()) +import System.Directory (listDirectory) +import Data.List (isPrefixOf) + +basePath :: FilePath +basePath = "/sys/class/backlight/" -- cgit v1.3.1