From 6ac13d70d701bc6f0e8a24ef4fa67e501403fe81 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 11 Dec 2010 14:18:49 -0500 Subject: Don't hard code the number of values Make an infinite list of empty strings so that if something is asked for and cannot be provided, index errors don't occur. --- Plugins/Monitors/Cpu.hs | 2 +- Plugins/Monitors/MultiCpu.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/Monitors/Cpu.hs b/Plugins/Monitors/Cpu.hs index 71e8ac3..fb5e9e2 100644 --- a/Plugins/Monitors/Cpu.hs +++ b/Plugins/Monitors/Cpu.hs @@ -39,7 +39,7 @@ parseCPU = return percent formatCpu :: [Float] -> Monitor [String] -formatCpu [] = return [""] +formatCpu [] = return $ repeat "" formatCpu xs = do let t = foldr (+) 0 $ take 3 xs b <- showPercentBar (100 * t) t diff --git a/Plugins/Monitors/MultiCpu.hs b/Plugins/Monitors/MultiCpu.hs index 17620d5..492ad96 100644 --- a/Plugins/Monitors/MultiCpu.hs +++ b/Plugins/Monitors/MultiCpu.hs @@ -50,7 +50,7 @@ percent b a = if tot > 0 then map (/ tot) $ take 4 dif else [0, 0, 0, 0] tot = foldr (+) 0 dif formatMultiCpus :: [[Float]] -> Monitor [String] -formatMultiCpus [] = showPercentsWithColors $ replicate 15 0.0 +formatMultiCpus [] = return $ repeat "" formatMultiCpus xs = fmap concat $ mapM formatCpu xs formatCpu :: [Float] -> Monitor [String] -- cgit v1.2.3 From 096aee3a1667e056fe906967cc2b078e8122e2b4 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 11 Dec 2010 14:19:42 -0500 Subject: Use `head' rather than `flip (!!) 0' --- Plugins/Monitors/Cpu.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Monitors/Cpu.hs b/Plugins/Monitors/Cpu.hs index fb5e9e2..ab89246 100644 --- a/Plugins/Monitors/Cpu.hs +++ b/Plugins/Monitors/Cpu.hs @@ -28,7 +28,7 @@ cpuData = do s <- B.readFile "/proc/stat" cpuParser :: B.ByteString -> [Float] cpuParser = - map (read . B.unpack) . tail . B.words . flip (!!) 0 . B.lines + map (read . B.unpack) . tail . B.words . head . B.lines parseCPU :: IO [Float] parseCPU = -- cgit v1.2.3