summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/Monitors/Batt.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Plugins/Monitors/Batt.hs')
-rw-r--r--src/Plugins/Monitors/Batt.hs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/Plugins/Monitors/Batt.hs b/src/Plugins/Monitors/Batt.hs
index 81c9aee..fba45dd 100644
--- a/src/Plugins/Monitors/Batt.hs
+++ b/src/Plugins/Monitors/Batt.hs
@@ -21,8 +21,9 @@ import System.FilePath ((</>))
import System.IO (IOMode(ReadMode), hGetLine, withFile)
import System.Posix.Files (fileExist)
import System.Console.GetOpt
-import Data.List (sort, sortOn, group)
+import Data.List (sort, sortBy, group)
import Data.Maybe (fromMaybe)
+import Data.Ord (comparing)
import Text.Read (readMaybe)
data BattOpts = BattOpts
@@ -163,6 +164,11 @@ readBattery sc files =
grabs f = handle onError' $ withFile f ReadMode hGetLine
onError' = const (return "Idle") :: SomeException -> IO String
+-- sortOn is only available starting at ghc 7.10
+sortOn :: Ord b => (a -> b) -> [a] -> [a]
+sortOn f =
+ map snd . sortBy (comparing fst) . map (\x -> let y = f x in y `seq` (y, x))
+
readBatteries :: BattOpts -> [Files] -> IO Result
readBatteries opts bfs =
do bats <- mapM (readBattery (scale opts)) (take 3 bfs)