summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/System/Utils.hs
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2018-11-25 23:43:41 +0000
committerjao <jao@gnu.org>2018-11-25 23:43:41 +0000
commit24c84e47177b6ebbe3df99db53220def6c0951ec (patch)
tree76ab584623118b7dde610c94639d44951cf83b6e /src/Xmobar/System/Utils.hs
parent54cf675f1299a74466950be240a708a762335d5d (diff)
downloadxmobar-24c84e47177b6ebbe3df99db53220def6c0951ec.tar.gz
xmobar-24c84e47177b6ebbe3df99db53220def6c0951ec.tar.bz2
Xmobar.System.Utils, Xmobar.X11.Events
Diffstat (limited to 'src/Xmobar/System/Utils.hs')
-rw-r--r--src/Xmobar/System/Utils.hs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/Xmobar/System/Utils.hs b/src/Xmobar/System/Utils.hs
new file mode 100644
index 0000000..d4bdd78
--- /dev/null
+++ b/src/Xmobar/System/Utils.hs
@@ -0,0 +1,54 @@
+{-# LANGUAGE CPP #-}
+
+------------------------------------------------------------------------------
+-- |
+-- Module: Utils
+-- Copyright: (c) 2010, 2018 Jose Antonio Ortega Ruiz
+-- License: BSD3-style (see LICENSE)
+--
+-- Maintainer: Jose A Ortega Ruiz <jao@gnu.org>
+-- Stability: unstable
+-- Portability: unportable
+-- Created: Sat Dec 11, 2010 20:55
+--
+--
+-- Miscellaneous utility functions
+--
+------------------------------------------------------------------------------
+
+
+module Xmobar.System.Utils (expandHome, changeLoop, hGetLineSafe)
+where
+
+import Control.Monad
+import Control.Concurrent.STM
+
+import System.Environment
+import System.FilePath
+import System.IO
+
+#if defined XFT || defined UTF8
+import qualified System.IO as S (hGetLine)
+#endif
+
+hGetLineSafe :: Handle -> IO String
+#if defined XFT || defined UTF8
+hGetLineSafe = S.hGetLine
+#else
+hGetLineSafe = hGetLine
+#endif
+
+
+expandHome :: FilePath -> IO FilePath
+expandHome ('~':'/':path) = fmap (</> path) (getEnv "HOME")
+expandHome p = return p
+
+changeLoop :: Eq a => STM a -> (a -> IO ()) -> IO ()
+changeLoop s f = atomically s >>= go
+ where
+ go old = do
+ f old
+ go =<< atomically (do
+ new <- s
+ guard (new /= old)
+ return new)