summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/App
diff options
context:
space:
mode:
Diffstat (limited to 'src/Xmobar/App')
-rw-r--r--src/Xmobar/App/Config.hs3
-rw-r--r--src/Xmobar/App/Main.hs25
-rw-r--r--src/Xmobar/App/Opts.hs12
-rw-r--r--src/Xmobar/App/TextEventLoop.hs23
4 files changed, 44 insertions, 19 deletions
diff --git a/src/Xmobar/App/Config.hs b/src/Xmobar/App/Config.hs
index a227681..e798010 100644
--- a/src/Xmobar/App/Config.hs
+++ b/src/Xmobar/App/Config.hs
@@ -1,7 +1,7 @@
------------------------------------------------------------------------------
-- |
-- Module: Xmobar.Config.Defaults
--- Copyright: (c) 2018, 2019, 2020 Jose Antonio Ortega Ruiz
+-- Copyright: (c) 2018, 2019, 2020, 2022 Jose Antonio Ortega Ruiz
-- License: BSD3-style (see LICENSE)
--
-- Maintainer: jao@gnu.org
@@ -65,6 +65,7 @@ defaultConfig =
"<fc=#00FF00>%uname%</fc> * <fc=#FF0000>%theDate%</fc>"
, verbose = False
, signal = SignalChan Nothing
+ , textOutput = False
}
-- | Return the path to the xmobar data directory. This directory is
diff --git a/src/Xmobar/App/Main.hs b/src/Xmobar/App/Main.hs
index b67012d..ead3249 100644
--- a/src/Xmobar/App/Main.hs
+++ b/src/Xmobar/App/Main.hs
@@ -42,14 +42,15 @@ import Xmobar.X11.Types
import Xmobar.X11.Text
import Xmobar.X11.Window
import Xmobar.App.Opts (recompileFlag, verboseFlag, getOpts, doOpts)
-import Xmobar.App.EventLoop (startLoop)
import Xmobar.App.CommandThreads (startCommand, newRefreshLock, refreshLock)
+import Xmobar.App.EventLoop (startLoop)
+import Xmobar.App.TextEventLoop (startTextLoop)
import Xmobar.App.Compile (recompile, trace)
import Xmobar.App.Config
import Xmobar.App.Timer (withTimer)
-xmobar :: Config -> IO ()
-xmobar conf = withDeferSignals $ do
+xXmobar :: Config -> IO ()
+xXmobar conf = withDeferSignals $ do
initThreads
d <- openDisplay ""
fs <- initFont d (font conf)
@@ -70,6 +71,24 @@ xmobar conf = withDeferSignals $ do
ts = textOffsets conf ++ replicate (length fl) (-1)
startLoop (XConf d r w (fs :| fl) (to :| ts) ic conf) sig refLock vars
+textXmobar :: Config -> IO ()
+textXmobar conf = withDeferSignals $ do
+ initThreads
+ cls <- mapM (parseTemplate (commands conf) (sepChar conf))
+ (splitTemplate (alignSep conf) (template conf))
+ let confSig = unSignalChan (signal conf)
+ sig <- maybe newEmptyTMVarIO pure confSig
+ unless (isJust confSig) $ setupSignalHandler sig
+ refLock <- newRefreshLock
+ withTimer (refreshLock refLock) $
+ bracket (mapM (mapM $ startCommand sig) cls)
+ cleanupThreads
+ $ \vars -> do
+ startTextLoop conf sig refLock vars
+
+xmobar :: Config -> IO ()
+xmobar cfg = if textOutput cfg then textXmobar cfg else xXmobar cfg
+
configFromArgs :: Config -> IO Config
configFromArgs cfg = getArgs >>= getOpts >>= doOpts cfg . fst
diff --git a/src/Xmobar/App/Opts.hs b/src/Xmobar/App/Opts.hs
index daa7de6..39d3060 100644
--- a/src/Xmobar/App/Opts.hs
+++ b/src/Xmobar/App/Opts.hs
@@ -1,7 +1,7 @@
------------------------------------------------------------------------------
-- |
-- Module: Xmobar.App.Opts
--- Copyright: (c) 2018, 2019, 2020 Jose Antonio Ortega Ruiz
+-- Copyright: (c) 2018, 2019, 2020, 2022 Jose Antonio Ortega Ruiz
-- License: BSD3-style (see LICENSE)
--
-- Maintainer: jao@gnu.org
@@ -14,7 +14,10 @@
--
------------------------------------------------------------------------------
-module Xmobar.App.Opts (recompileFlag, verboseFlag, getOpts, doOpts) where
+module Xmobar.App.Opts ( recompileFlag
+ , verboseFlag
+ , getOpts
+ , doOpts) where
import Control.Monad (when)
import System.Console.GetOpt
@@ -30,6 +33,7 @@ data Opts = Help
| Verbose
| Recompile
| Version
+ | TextOutput
| Font String
| AddFont String
| BgColor String
@@ -56,6 +60,7 @@ options =
, Option "v" ["verbose"] (NoArg Verbose) "Emit verbose debugging messages"
, Option "r" ["recompile"] (NoArg Recompile) "Force recompilation"
, Option "V" ["version"] (NoArg Version) "Show version information"
+ , Option "T" ["text"] (NoArg TextOutput) "Write text-only output to stdout"
, Option "f" ["font"] (ReqArg Font "font name") "Font name"
, Option "N" ["add-font"] (ReqArg AddFont "font name") "Add to the list of additional fonts"
, Option "w" ["wmclass"] (ReqArg WmClass "class") "X11 WM_CLASS property"
@@ -106,7 +111,7 @@ usage = usageInfo header options ++ footer
info :: String
info = "xmobar " ++ showVersion version
- ++ "\n (C) 2010 - 2020 Jose A Ortega Ruiz"
+ ++ "\n (C) 2010 - 2022 Jose A Ortega Ruiz"
++ "\n (C) 2007 - 2010 Andrea Rossato\n "
++ mail ++ "\n" ++ license ++ "\n"
@@ -127,6 +132,7 @@ doOpts conf (o:oo) =
Help -> doOpts' conf
Version -> doOpts' conf
Recompile -> doOpts' conf
+ TextOutput -> doOpts' (conf {textOutput = True})
Verbose -> doOpts' (conf {verbose = True})
Font s -> doOpts' (conf {font = s})
AddFont s -> doOpts' (conf {additionalFonts = additionalFonts conf ++ [s]})
diff --git a/src/Xmobar/App/TextEventLoop.hs b/src/Xmobar/App/TextEventLoop.hs
index ae3a9e3..50ee17c 100644
--- a/src/Xmobar/App/TextEventLoop.hs
+++ b/src/Xmobar/App/TextEventLoop.hs
@@ -16,35 +16,34 @@
--
------------------------------------------------------------------------------
-module Xmobar.App.TextEventLoop (startLoop) where
+module Xmobar.App.TextEventLoop (startTextLoop) where
import Prelude hiding (lookup)
import Control.Monad.Reader
import Control.Concurrent
-import Control.Concurrent.Async (Async, async)
+import Control.Concurrent.Async (Async)
import Control.Concurrent.STM
-import Control.Exception (bracket_, handle, SomeException(..))
+import Control.Exception (handle, SomeException(..))
import Xmobar.System.Signal
import Xmobar.Config.Types (Config)
-import Xmobar.Run.Exec
-import Xmobar.Run.Runnable
+
import Xmobar.X11.Parsers (parseStringAsText)
-import Xmobar.App.CommandThreads (startCommand, refreshLockT)
+import Xmobar.App.CommandThreads (refreshLockT)
#ifdef DBUS
import Xmobar.System.DBus
#endif
-- | Starts the main event loop and threads
-startLoop :: Config
- -> TMVar SignalType
- -> TMVar ()
- -> [[([Async ()], TVar String)]]
- -> IO ()
-startLoop cfg sig pauser vs = do
+startTextLoop :: Config
+ -> TMVar SignalType
+ -> TMVar ()
+ -> [[([Async ()], TVar String)]]
+ -> IO ()
+startTextLoop cfg sig pauser vs = do
tv <- newTVarIO []
_ <- forkIO (handle (handler "checker") (checker tv [] vs sig pauser))
#ifdef DBUS