summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Environment.hs1
-rw-r--r--src/Plugins/MarqueePipeReader.hs9
-rw-r--r--src/Plugins/Monitors/Batt.hs8
-rw-r--r--src/Plugins/PipeReader.hs1
4 files changed, 14 insertions, 5 deletions
diff --git a/src/Environment.hs b/src/Environment.hs
index f0edece..8fbb35f 100644
--- a/src/Environment.hs
+++ b/src/Environment.hs
@@ -13,6 +13,7 @@
-----------------------------------------------------------------------------
module Environment where
+import Control.Applicative ((<$>))
import Data.Maybe (fromMaybe)
import System.Environment (lookupEnv)
diff --git a/src/Plugins/MarqueePipeReader.hs b/src/Plugins/MarqueePipeReader.hs
index 0b3a710..c46fff4 100644
--- a/src/Plugins/MarqueePipeReader.hs
+++ b/src/Plugins/MarqueePipeReader.hs
@@ -22,9 +22,10 @@ import Control.Concurrent(forkIO, threadDelay)
import Control.Concurrent.STM (TChan, atomically, writeTChan, tryReadTChan, newTChan)
import Control.Exception
import Control.Monad(forever, unless)
+import Control.Applicative ((<$>))
type Length = Int -- length of the text to display
-type Rate = Int -- delay in tenth seconds
+type Rate = Int -- delay in tenth seconds
type Separator = String -- if text wraps around, use separator
data MarqueePipeReader = MarqueePipeReader String (Length, Rate, Separator) String
@@ -48,16 +49,16 @@ instance Exec MarqueePipeReader where
pipeToChan :: Handle -> TChan String -> IO ()
pipeToChan h chan = do
- line <- hGetLineSafe h
+ line <- hGetLineSafe h
atomically $ writeTChan chan line
writer :: String -> Separator -> Length -> Rate -> TChan String -> (String -> IO ()) -> IO ()
-writer txt sep len rate chan cb = do
+writer txt sep len rate chan cb = do
cb (take len txt)
mbnext <- atomically $ tryReadTChan chan
case mbnext of
Just new -> writer (toInfTxt new sep) sep len rate chan cb
- Nothing -> tenthSeconds rate >> writer (drop 1 txt) sep len rate chan cb
+ Nothing -> tenthSeconds rate >> writer (drop 1 txt) sep len rate chan cb
toInfTxt :: String -> String -> String
toInfTxt line sep = concat (repeat $ line ++ " " ++ sep ++ " ")
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)
diff --git a/src/Plugins/PipeReader.hs b/src/Plugins/PipeReader.hs
index 653a72d..b3e178d 100644
--- a/src/Plugins/PipeReader.hs
+++ b/src/Plugins/PipeReader.hs
@@ -21,6 +21,7 @@ import System.Posix.Files
import Control.Concurrent(threadDelay)
import Control.Exception
import Control.Monad(forever, unless)
+import Control.Applicative ((<$>))
data PipeReader = PipeReader String String
deriving (Read, Show)