Compare commits
2 Commits
37e8aa3554
...
165195cd96
Author | SHA1 | Date |
---|---|---|
Ricard Illa | 165195cd96 | |
Ricard Illa | b58336c621 |
|
@ -9,15 +9,18 @@ import Monitors.Net (queryNet)
|
|||
import Monitors.Volume (queryVolume)
|
||||
|
||||
usage :: IO String
|
||||
usage = printf "%s bat | vol | net | date" <$> getProgName
|
||||
usage = printf "%s bat (acpi_command) | vol (pamixer_command) | net (nmcli_command) | date" <$> getProgName
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
args <- getArgs
|
||||
output <- case args of
|
||||
[ "bat", cmd ] -> queryBattery cmd
|
||||
[ "bat" ] -> queryBattery "acpi"
|
||||
[ "vol", cmd ] -> queryVolume cmd
|
||||
[ "vol" ] -> queryVolume "pamixer"
|
||||
[ "net", cmd ] -> queryNet cmd
|
||||
[ "net" ] -> queryNet "nmcli"
|
||||
[ "date" ] -> queryDate True
|
||||
[ "date-min" ] -> queryDate False
|
||||
_ -> usage
|
||||
|
|
|
@ -76,15 +76,20 @@ parseMixerInfo = fmap fmtMixer . matchRegex regex
|
|||
fmtData :: MixerData -> String
|
||||
fmtData = (separator ++ ) . getStatus
|
||||
|
||||
readProcessIgnoreCode :: FilePath -> [String] -> String -> IO String
|
||||
readProcessIgnoreCode cmd args stdin = do
|
||||
(_,out,_) <- readProcessWithExitCode cmd args stdin
|
||||
return out
|
||||
|
||||
getMute :: String -> IO Bool
|
||||
getMute cmd = parseMute <$> readProcess cmd ["--get-mute"] ""
|
||||
getMute cmd = parseMute <$> readProcessIgnoreCode cmd ["--get-mute"] ""
|
||||
where
|
||||
parseMute "true" = True
|
||||
parseMute "false" = False
|
||||
parseMute _ = False
|
||||
|
||||
getVol :: String -> IO Int
|
||||
getVol cmd = parseVol <$> readProcess cmd ["--get-volume"] ""
|
||||
getVol cmd = parseVol <$> readProcessIgnoreCode cmd ["--get-volume"] ""
|
||||
where
|
||||
parseVol x = case readMaybe x of (Just vol) -> vol
|
||||
Nothing -> 0
|
||||
|
|
Loading…
Reference in New Issue