diff options
author | jao <jao@gnu.org> | 2018-11-25 15:10:29 +0000 |
---|---|---|
committer | jao <jao@gnu.org> | 2018-11-25 15:10:29 +0000 |
commit | 77df1ac30fa7af5948f7ff64f5fee9aed64552b3 (patch) | |
tree | 647a4eb67ff1c293a5c530538ee88fc0093b577a /src/Xmobar/Plugins/Monitors/ThermalZone.hs | |
parent | e0d6da82de8d0d1cef98896164c6016b84e47068 (diff) | |
download | xmobar-77df1ac30fa7af5948f7ff64f5fee9aed64552b3.tar.gz xmobar-77df1ac30fa7af5948f7ff64f5fee9aed64552b3.tar.bz2 |
Back to app/src, since it seems they're the default convention for stack
Diffstat (limited to 'src/Xmobar/Plugins/Monitors/ThermalZone.hs')
-rw-r--r-- | src/Xmobar/Plugins/Monitors/ThermalZone.hs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/Xmobar/Plugins/Monitors/ThermalZone.hs b/src/Xmobar/Plugins/Monitors/ThermalZone.hs new file mode 100644 index 0000000..bc46b59 --- /dev/null +++ b/src/Xmobar/Plugins/Monitors/ThermalZone.hs @@ -0,0 +1,49 @@ +------------------------------------------------------------------------------ +-- | +-- Module : Plugins.Monitors.ThermalZone +-- Copyright : (c) 2011, 2013 Jose Antonio Ortega Ruiz +-- License : BSD3-style (see LICENSE) +-- +-- Maintainer : jao@gnu.org +-- Stability : unstable +-- Portability : portable +-- Created : Fri Feb 25, 2011 03:18 +-- +-- +-- A thermal zone plugin based on the sysfs linux interface. +-- See http://kernel.org/doc/Documentation/thermal/sysfs-api.txt +-- +------------------------------------------------------------------------------ + +module Xmobar.Plugins.Monitors.ThermalZone (thermalZoneConfig, runThermalZone) where + +import Xmobar.Plugins.Monitors.Common + +import System.Posix.Files (fileExist) +import Control.Exception (IOException, catch) +import qualified Data.ByteString.Char8 as B + +-- | Default thermal configuration. +thermalZoneConfig :: IO MConfig +thermalZoneConfig = mkMConfig "<temp>C" ["temp"] + +-- | Retrieves thermal information. Argument is name of thermal +-- directory in \/sys\/clas\/thermal. Returns the monitor string +-- parsed according to template (either default or user specified). +runThermalZone :: [String] -> Monitor String +runThermalZone args = do + let zone = head args + file = "/sys/class/thermal/thermal_zone" ++ zone ++ "/temp" + handleIOError :: IOException -> IO (Maybe B.ByteString) + handleIOError _ = return Nothing + parse = return . (read :: String -> Int) . B.unpack + exists <- io $ fileExist file + if exists + then do contents <- io $ catch (fmap Just $ B.readFile file) handleIOError + case contents of + Just d -> do + mdegrees <- parse d + temp <- showWithColors show (mdegrees `quot` 1000) + parseTemplate [ temp ] + Nothing -> getConfigValue naString + else getConfigValue naString |