diff options
| author | Kleidi Bujari <mail@4kb.net> | 2026-08-09 17:38:22 -0700 |
|---|---|---|
| committer | Kleidi Bujari <mail@4kb.net> | 2026-08-17 14:15:15 -0700 |
| commit | fdb7a7b876fc0b46ff36751642cbc05ed4140232 (patch) | |
| tree | eee2304fbbfb62d31d94a033ead0c876c1b036ae /packages/code/dfetch/app/Dfetch | |
| parent | 4b56064566c1a7ef6a8c21e11dc1045bc8c3587d (diff) | |
| download | depot-fdb7a7b876fc0b46ff36751642cbc05ed4140232.tar.gz depot-fdb7a7b876fc0b46ff36751642cbc05ed4140232.tar.bz2 depot-fdb7a7b876fc0b46ff36751642cbc05ed4140232.zip | |
init dfetch for system queries
Diffstat (limited to 'packages/code/dfetch/app/Dfetch')
| -rw-r--r-- | packages/code/dfetch/app/Dfetch/Battery.hs | 26 | ||||
| -rw-r--r-- | packages/code/dfetch/app/Dfetch/Brightness.hs | 8 |
2 files changed, 34 insertions, 0 deletions
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/" |
