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)
|
import Monitors.Volume (queryVolume)
|
||||||
|
|
||||||
usage :: IO String
|
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 :: IO ()
|
||||||
main = do
|
main = do
|
||||||
args <- getArgs
|
args <- getArgs
|
||||||
output <- case args of
|
output <- case args of
|
||||||
[ "bat", cmd ] -> queryBattery cmd
|
[ "bat", cmd ] -> queryBattery cmd
|
||||||
|
[ "bat" ] -> queryBattery "acpi"
|
||||||
[ "vol", cmd ] -> queryVolume cmd
|
[ "vol", cmd ] -> queryVolume cmd
|
||||||
|
[ "vol" ] -> queryVolume "pamixer"
|
||||||
[ "net", cmd ] -> queryNet cmd
|
[ "net", cmd ] -> queryNet cmd
|
||||||
|
[ "net" ] -> queryNet "nmcli"
|
||||||
[ "date" ] -> queryDate True
|
[ "date" ] -> queryDate True
|
||||||
[ "date-min" ] -> queryDate False
|
[ "date-min" ] -> queryDate False
|
||||||
_ -> usage
|
_ -> usage
|
||||||
|
|
|
@ -76,15 +76,20 @@ parseMixerInfo = fmap fmtMixer . matchRegex regex
|
||||||
fmtData :: MixerData -> String
|
fmtData :: MixerData -> String
|
||||||
fmtData = (separator ++ ) . getStatus
|
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 :: String -> IO Bool
|
||||||
getMute cmd = parseMute <$> readProcess cmd ["--get-mute"] ""
|
getMute cmd = parseMute <$> readProcessIgnoreCode cmd ["--get-mute"] ""
|
||||||
where
|
where
|
||||||
parseMute "true" = True
|
parseMute "true" = True
|
||||||
parseMute "false" = False
|
parseMute "false" = False
|
||||||
parseMute _ = False
|
parseMute _ = False
|
||||||
|
|
||||||
getVol :: String -> IO Int
|
getVol :: String -> IO Int
|
||||||
getVol cmd = parseVol <$> readProcess cmd ["--get-volume"] ""
|
getVol cmd = parseVol <$> readProcessIgnoreCode cmd ["--get-volume"] ""
|
||||||
where
|
where
|
||||||
parseVol x = case readMaybe x of (Just vol) -> vol
|
parseVol x = case readMaybe x of (Just vol) -> vol
|
||||||
Nothing -> 0
|
Nothing -> 0
|
||||||
|
|
Loading…
Reference in New Issue