summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-01-28 05:11:09 +0000
committerjao <jao@gnu.org>2022-01-29 06:42:29 +0000
commit0d3021eb601dadfa10fae30f108108894086c82c (patch)
tree887481657041ed1dad5e86d47ab61594e52654b6 /src
parent93da696658061e1c14fdca70b6c0f04c412b1fd8 (diff)
downloadxmobar-0d3021eb601dadfa10fae30f108108894086c82c.tar.gz
xmobar-0d3021eb601dadfa10fae30f108108894086c82c.tar.bz2
Basic text output, without colors, working
Diffstat (limited to 'src')
-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
-rw-r--r--src/Xmobar/Config/Parse.hs7
-rw-r--r--src/Xmobar/Config/Types.hs1
6 files changed, 49 insertions, 22 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
diff --git a/src/Xmobar/Config/Parse.hs b/src/Xmobar/Config/Parse.hs
index f7c8b31..e7d5933 100644
--- a/src/Xmobar/Config/Parse.hs
+++ b/src/Xmobar/Config/Parse.hs
@@ -2,7 +2,7 @@
------------------------------------------------------------------------------
-- |
-- Module: Xmobar.Config.Parse
--- Copyright: (c) 2018, 2020 Jose Antonio Ortega Ruiz
+-- Copyright: (c) 2018, 2020, 2022 Jose Antonio Ortega Ruiz
-- License: BSD3-style (see LICENSE)
--
-- Maintainer: jao@gnu.org
@@ -62,7 +62,7 @@ parseConfig defaultConfig =
perms = permute $ Config
<$?> pFont <|?> pFontList <|?> pWmClass <|?> pWmName
<|?> pBgColor <|?> pFgColor
- <|?> pPosition <|?> pTextOffset <|?> pTextOffsets
+ <|?> pPosition <|?> pTextOutput <|?> pTextOffset <|?> pTextOffsets
<|?> pIconOffset <|?> pBorder
<|?> pBdColor <|?> pBdWidth <|?> pAlpha <|?> pHideOnStart
<|?> pAllDesktops <|?> pOverrideRedirect <|?> pPickBroadest
@@ -76,9 +76,10 @@ parseConfig defaultConfig =
, "position" , "textOffset", "textOffsets", "iconOffset"
, "allDesktops", "overrideRedirect", "pickBroadest"
, "hideOnStart", "lowerOnStart", "persistent", "iconRoot"
- , "alpha", "commands", "verbose", "signal"
+ , "alpha", "commands", "verbose", "signal", "textOutput"
]
+ pTextOutput = readField textOutput "textOutput"
pFont = strField font "font"
pFontList = strListField additionalFonts "additionalFonts"
pWmClass = strField wmClass "wmClass"
diff --git a/src/Xmobar/Config/Types.hs b/src/Xmobar/Config/Types.hs
index 8bbae40..816edaa 100644
--- a/src/Xmobar/Config/Types.hs
+++ b/src/Xmobar/Config/Types.hs
@@ -36,6 +36,7 @@ data Config =
, bgColor :: String -- ^ Backgroud color
, fgColor :: String -- ^ Default font color
, position :: XPosition -- ^ Top Bottom or Static
+ , textOutput :: Bool -- ^ Write data to stdout instead of X
, textOffset :: Int -- ^ Offset from top of window for text
, textOffsets :: [Int] -- ^ List of offsets for additionalFonts
, iconOffset :: Int -- ^ Offset from top of window for icons