summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2018-11-25 00:58:21 +0000
committerjao <jao@gnu.org>2018-11-25 00:58:21 +0000
commit0b7b43ef83a2ab6fd894c20e028b9d69372c7266 (patch)
tree8ce2b4d7efbd97bca387cbf7613ca9863a14d59e
parent7d11e5b47d06d38b23fc1190aba640de9daa76e0 (diff)
downloadxmobar-0b7b43ef83a2ab6fd894c20e028b9d69372c7266.tar.gz
xmobar-0b7b43ef83a2ab6fd894c20e028b9d69372c7266.tar.bz2
Plugins.Utils -> Utils
-rw-r--r--src/app/Configuration.hs26
-rw-r--r--src/lib/Xmobar.hs3
-rw-r--r--src/lib/Xmobar/Commands.hs2
-rw-r--r--src/lib/Xmobar/Config.hs16
-rw-r--r--src/lib/Xmobar/Plugins.hs2
-rw-r--r--src/lib/Xmobar/Plugins/BufferedPipeReader.hs1
-rw-r--r--src/lib/Xmobar/Plugins/CommandReader.hs1
-rw-r--r--src/lib/Xmobar/Plugins/MBox.hs2
-rw-r--r--src/lib/Xmobar/Plugins/Mail.hs2
-rw-r--r--src/lib/Xmobar/Plugins/MarqueePipeReader.hs3
-rw-r--r--src/lib/Xmobar/Plugins/PipeReader.hs5
-rw-r--r--src/lib/Xmobar/Plugins/StdinReader.hs1
-rw-r--r--src/lib/Xmobar/Signal.hs2
-rw-r--r--src/lib/Xmobar/Utils.hs (renamed from src/lib/Xmobar/Plugins/Utils.hs)22
-rw-r--r--src/lib/Xmobar/XUtil.hs15
-rw-r--r--xmobar.cabal6
16 files changed, 57 insertions, 52 deletions
diff --git a/src/app/Configuration.hs b/src/app/Configuration.hs
index e1e3c24..1cf3ebf 100644
--- a/src/app/Configuration.hs
+++ b/src/app/Configuration.hs
@@ -24,12 +24,8 @@ import Text.ParserCombinators.Parsec.Number (int)
import Text.ParserCombinators.Parsec.Perm ((<|?>), (<$?>), permute)
import Control.Monad.IO.Class (liftIO)
-import System.Posix.Files
-import System.FilePath ((</>))
import System.Environment
-import System.Directory (getHomeDirectory)
-
-import Xmobar.Config
+import System.Posix.Files (fileExist)
import qualified Xmobar.Config as C
@@ -177,7 +173,7 @@ commandsErr = "commands: this usually means that a command could not" ++
"\nwhich follows the offending one."
-- | Reads the configuration files or quits with an error
-readConfig :: FilePath -> String -> IO (Config,[String])
+readConfig :: FilePath -> String -> IO (C.Config,[String])
readConfig f usage = do
file <- liftIO $ fileExist f
s <- liftIO $ if file then readFileSafe f else error $
@@ -186,22 +182,10 @@ readConfig f usage = do
": configuration file contains errors at:\n" ++ show err)
return $ parseConfig s
-xdgConfigDir :: IO String
-xdgConfigDir = do env <- getEnvironment
- case lookup "XDG_CONFIG_HOME" env of
- Just val -> return val
- Nothing -> fmap (</> ".config") getHomeDirectory
-
-xmobarConfigDir :: IO FilePath
-xmobarConfigDir = fmap (</> "xmobar") xdgConfigDir
-
-getXdgConfigFile :: IO FilePath
-getXdgConfigFile = fmap (</> "xmobarrc") xmobarConfigDir
-
-- | Read default configuration file or load the default config
-readDefaultConfig :: String -> IO (Config,[String])
+readDefaultConfig :: String -> IO (C.Config,[String])
readDefaultConfig usage = do
- xdgConfigFile <- getXdgConfigFile
+ xdgConfigFile <- C.getXdgConfigFile
xdgConfigFileExists <- liftIO $ fileExist xdgConfigFile
home <- liftIO $ getEnv "HOME"
let defaultConfigFile = home ++ "/.xmobarrc"
@@ -210,4 +194,4 @@ readDefaultConfig usage = do
then readConfig xdgConfigFile usage
else if defaultConfigFileExists
then readConfig defaultConfigFile usage
- else return (defaultConfig,[])
+ else return (C.defaultConfig,[])
diff --git a/src/lib/Xmobar.hs b/src/lib/Xmobar.hs
index a90ec3e..547c549 100644
--- a/src/lib/Xmobar.hs
+++ b/src/lib/Xmobar.hs
@@ -15,7 +15,7 @@
--
-----------------------------------------------------------------------------
-module Xmobar (xmobar, Runnable (..)) where
+module Xmobar (xmobar, Runnable (..), module Xmobar.Config) where
import Xmobar.EventLoop (startLoop, startCommand)
import Xmobar.Config
@@ -30,7 +30,6 @@ import Control.Exception (bracket)
import Xmobar.Parsers
import Xmobar.XUtil
-import Xmobar.Config()
import Xmobar.Signal (setupSignalHandler, withDeferSignals)
import Xmobar.Window
import Xmobar.Types
diff --git a/src/lib/Xmobar/Commands.hs b/src/lib/Xmobar/Commands.hs
index ececdd9..9c92de0 100644
--- a/src/lib/Xmobar/Commands.hs
+++ b/src/lib/Xmobar/Commands.hs
@@ -32,7 +32,7 @@ import System.Exit
import System.IO (hClose)
import Xmobar.Signal
-import Xmobar.XUtil
+import Xmobar.Utils (hGetLineSafe)
class Show e => Exec e where
alias :: e -> String
diff --git a/src/lib/Xmobar/Config.hs b/src/lib/Xmobar/Config.hs
index 21b29fa..364ce17 100644
--- a/src/lib/Xmobar/Config.hs
+++ b/src/lib/Xmobar/Config.hs
@@ -21,8 +21,12 @@ module Xmobar.Config
, XPosition (..), Align (..), Border(..)
, defaultConfig
, runnableTypes
+ , getXdgConfigFile
) where
+import System.Environment
+import System.Directory (getHomeDirectory)
+import System.FilePath ((</>))
import Xmobar.Commands
import {-# SOURCE #-} Xmobar.Runnable
@@ -168,3 +172,15 @@ runnableTypes :: Command :*: Monitors :*: Date :*: PipeReader :*:
#endif
MarqueePipeReader :*: ()
runnableTypes = undefined
+
+xdgConfigDir :: IO String
+xdgConfigDir = do env <- getEnvironment
+ case lookup "XDG_CONFIG_HOME" env of
+ Just val -> return val
+ Nothing -> fmap (</> ".config") getHomeDirectory
+
+xmobarConfigDir :: IO FilePath
+xmobarConfigDir = fmap (</> "xmobar") xdgConfigDir
+
+getXdgConfigFile :: IO FilePath
+getXdgConfigFile = fmap (</> "xmobarrc") xmobarConfigDir
diff --git a/src/lib/Xmobar/Plugins.hs b/src/lib/Xmobar/Plugins.hs
index e8c6403..284a9f5 100644
--- a/src/lib/Xmobar/Plugins.hs
+++ b/src/lib/Xmobar/Plugins.hs
@@ -17,8 +17,6 @@
module Xmobar.Plugins
( Exec (..)
, tenthSeconds
- , hGetLineSafe
) where
import Xmobar.Commands
-import Xmobar.XUtil
diff --git a/src/lib/Xmobar/Plugins/BufferedPipeReader.hs b/src/lib/Xmobar/Plugins/BufferedPipeReader.hs
index d4d30a1..4bb80db 100644
--- a/src/lib/Xmobar/Plugins/BufferedPipeReader.hs
+++ b/src/lib/Xmobar/Plugins/BufferedPipeReader.hs
@@ -23,6 +23,7 @@ import System.IO.Unsafe(unsafePerformIO)
import Xmobar.Environment
import Xmobar.Plugins
import Xmobar.Signal
+import Xmobar.Utils(hGetLineSafe)
data BufferedPipeReader = BufferedPipeReader String [(Int, Bool, String)]
deriving (Read, Show)
diff --git a/src/lib/Xmobar/Plugins/CommandReader.hs b/src/lib/Xmobar/Plugins/CommandReader.hs
index 80b6299..e90fa62 100644
--- a/src/lib/Xmobar/Plugins/CommandReader.hs
+++ b/src/lib/Xmobar/Plugins/CommandReader.hs
@@ -17,6 +17,7 @@ module Xmobar.Plugins.CommandReader where
import System.IO
import Xmobar.Plugins
+import Xmobar.Utils (hGetLineSafe)
import System.Process(runInteractiveCommand, getProcessExitCode)
data CommandReader = CommandReader String String
diff --git a/src/lib/Xmobar/Plugins/MBox.hs b/src/lib/Xmobar/Plugins/MBox.hs
index 2281629..20e63cf 100644
--- a/src/lib/Xmobar/Plugins/MBox.hs
+++ b/src/lib/Xmobar/Plugins/MBox.hs
@@ -18,7 +18,7 @@ module Xmobar.Plugins.MBox (MBox(..)) where
import Prelude
import Xmobar.Plugins
#ifdef INOTIFY
-import Xmobar.Plugins.Utils (changeLoop, expandHome)
+import Xmobar.Utils (changeLoop, expandHome)
import Control.Monad (when)
import Control.Concurrent.STM
diff --git a/src/lib/Xmobar/Plugins/Mail.hs b/src/lib/Xmobar/Plugins/Mail.hs
index c41b5b3..d8946bf 100644
--- a/src/lib/Xmobar/Plugins/Mail.hs
+++ b/src/lib/Xmobar/Plugins/Mail.hs
@@ -17,7 +17,7 @@ module Xmobar.Plugins.Mail where
import Xmobar.Plugins
#ifdef INOTIFY
-import Xmobar.Plugins.Utils (expandHome, changeLoop)
+import Xmobar.Utils (expandHome, changeLoop)
import Control.Monad
import Control.Concurrent.STM
diff --git a/src/lib/Xmobar/Plugins/MarqueePipeReader.hs b/src/lib/Xmobar/Plugins/MarqueePipeReader.hs
index ad6f27f..ad1ae40 100644
--- a/src/lib/Xmobar/Plugins/MarqueePipeReader.hs
+++ b/src/lib/Xmobar/Plugins/MarqueePipeReader.hs
@@ -16,7 +16,8 @@ module Xmobar.Plugins.MarqueePipeReader where
import System.IO (openFile, IOMode(ReadWriteMode), Handle)
import Xmobar.Environment
-import Xmobar.Plugins (tenthSeconds, Exec(alias, start), hGetLineSafe)
+import Xmobar.Plugins (tenthSeconds, Exec(alias, start))
+import Xmobar.Utils(hGetLineSafe)
import System.Posix.Files (getFileStatus, isNamedPipe)
import Control.Concurrent(forkIO, threadDelay)
import Control.Concurrent.STM (TChan, atomically, writeTChan, tryReadTChan, newTChan)
diff --git a/src/lib/Xmobar/Plugins/PipeReader.hs b/src/lib/Xmobar/Plugins/PipeReader.hs
index 7166163..593a4a7 100644
--- a/src/lib/Xmobar/Plugins/PipeReader.hs
+++ b/src/lib/Xmobar/Plugins/PipeReader.hs
@@ -15,8 +15,9 @@
module Xmobar.Plugins.PipeReader where
import System.IO
-import Xmobar.Plugins
-import Xmobar.Environment
+import Xmobar.Plugins(Exec(..))
+import Xmobar.Environment(expandEnv)
+import Xmobar.Utils(hGetLineSafe)
import System.Posix.Files
import Control.Concurrent(threadDelay)
import Control.Exception
diff --git a/src/lib/Xmobar/Plugins/StdinReader.hs b/src/lib/Xmobar/Plugins/StdinReader.hs
index 372e4f9..ad8e60c 100644
--- a/src/lib/Xmobar/Plugins/StdinReader.hs
+++ b/src/lib/Xmobar/Plugins/StdinReader.hs
@@ -25,6 +25,7 @@ import System.IO
import Control.Exception (SomeException(..), handle)
import Xmobar.Plugins
import Xmobar.Actions (stripActions)
+import Xmobar.Utils (hGetLineSafe)
data StdinReader = StdinReader | UnsafeStdinReader
deriving (Read, Show)
diff --git a/src/lib/Xmobar/Signal.hs b/src/lib/Xmobar/Signal.hs
index bdc4be1..fd68e80 100644
--- a/src/lib/Xmobar/Signal.hs
+++ b/src/lib/Xmobar/Signal.hs
@@ -33,7 +33,7 @@ import DBus (IsVariant(..))
import Control.Monad ((>=>))
#endif
-import Xmobar.Plugins.Utils (safeHead)
+import Xmobar.Utils (safeHead)
data WakeUp = WakeUp deriving (Show,Typeable)
instance Exception WakeUp
diff --git a/src/lib/Xmobar/Plugins/Utils.hs b/src/lib/Xmobar/Utils.hs
index 6546c15..ce8c4ad 100644
--- a/src/lib/Xmobar/Plugins/Utils.hs
+++ b/src/lib/Xmobar/Utils.hs
@@ -1,7 +1,9 @@
+{-# LANGUAGE CPP #-}
+
------------------------------------------------------------------------------
-- |
--- Module: Plugins.Utils
--- Copyright: (c) 2010 Jose Antonio Ortega Ruiz
+-- Module: Utils
+-- Copyright: (c) 2010, 2018 Jose Antonio Ortega Ruiz
-- License: BSD3-style (see LICENSE)
--
-- Maintainer: Jose A Ortega Ruiz <jao@gnu.org>
@@ -15,18 +17,30 @@
------------------------------------------------------------------------------
-module Xmobar.Plugins.Utils (expandHome, changeLoop, safeHead) where
+module Xmobar.Utils (expandHome, changeLoop, safeHead, 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
+expandHome p = return p
changeLoop :: Eq a => STM a -> (a -> IO ()) -> IO ()
changeLoop s f = atomically s >>= go
diff --git a/src/lib/Xmobar/XUtil.hs b/src/lib/Xmobar/XUtil.hs
index 536a2fb..c4b4531 100644
--- a/src/lib/Xmobar/XUtil.hs
+++ b/src/lib/Xmobar/XUtil.hs
@@ -22,7 +22,6 @@ module Xmobar.XUtil
, textWidth
, printString
, nextEvent'
- , hGetLineSafe
) where
import Control.Concurrent
@@ -36,26 +35,16 @@ import qualified Graphics.X11.Xlib as Xlib (textExtents, textWidth)
import Graphics.X11.Xlib.Extras
import System.Mem.Weak ( addFinalizer )
import System.Posix.Types (Fd(..))
-import System.IO
-
-#if defined XFT || defined UTF8
-import qualified System.IO as S (hGetLine)
-#endif
#if defined XFT
import Xmobar.MinXft
import Graphics.X11.Xrender
+#else
+import System.IO(hPutStrLn, stderr)
#endif
import Xmobar.ColorCache
-hGetLineSafe :: Handle -> IO String
-#if defined XFT || defined UTF8
-hGetLineSafe = S.hGetLine
-#else
-hGetLineSafe = hGetLine
-#endif
-
-- Hide the Core Font/Xft switching here
data XFont = Core FontStruct
| Utf8 FontSet
diff --git a/xmobar.cabal b/xmobar.cabal
index 330704a..efe5a5d 100644
--- a/xmobar.cabal
+++ b/xmobar.cabal
@@ -133,6 +133,7 @@ library
other-modules: Xmobar.Localize,
Xmobar.Parsers,
+ Xmobar.Utils,
Xmobar.XUtil,
Xmobar.StatFS,
Xmobar.ColorCache,
@@ -140,8 +141,7 @@ library
Xmobar.Draw,
Xmobar.Signal,
Xmobar.Environment,
- Xmobar.EventLoop,
- Xmobar.Plugins.Utils
+ Xmobar.EventLoop
extra-libraries: Xrandr Xrender
@@ -302,9 +302,9 @@ test-suite XmobarTest
Xmobar.Commands,
Xmobar.Signal,
Xmobar.XUtil,
+ Xmobar.Utils,
Xmobar.ColorCache,
Xmobar.Plugins,
- Xmobar.Plugins.Utils,
Xmobar.Plugins.Monitors.Common
if flag(with_alsa) || flag(all_extensions)