ENH use optparse for xmobar

This commit is contained in:
Nathan Dwarshuis 2023-01-01 11:44:36 -05:00
parent dea4ab6585
commit b3f07ba590
1 changed files with 33 additions and 19 deletions

View File

@ -13,12 +13,12 @@ module Main (main) where
import Data.Internal.DBus import Data.Internal.DBus
import Data.Internal.Dependency import Data.Internal.Dependency
import Options.Applicative
import RIO hiding (hFlush) import RIO hiding (hFlush)
import qualified RIO.ByteString.Lazy as BL import qualified RIO.ByteString.Lazy as BL
import RIO.List import RIO.List
import RIO.Process import RIO.Process
import qualified RIO.Text as T import qualified RIO.Text as T
import UnliftIO.Environment
import XMonad.Core hiding (config) import XMonad.Core hiding (config)
import XMonad.Internal.Command.Desktop import XMonad.Internal.Command.Desktop
import XMonad.Internal.Command.Power import XMonad.Internal.Command.Power
@ -40,19 +40,42 @@ import Xmobar.Plugins.Screensaver
import Xmobar.Plugins.VPN import Xmobar.Plugins.VPN
main :: IO () main :: IO ()
main = getArgs >>= parse main = parse >>= xio
parse :: [String] -> IO () parse :: IO XOpts
parse [] = run parse = execParser opts
parse ["--deps"] = withCache printDeps where
parse ["--test"] = withCache $ withDBus_ evalConfig parseOpts = parseDeps <|> parseTest <|> pure XRun
parse _ = usage opts =
info (parseOpts <**> helper) $
fullDesc <> header "xmobar: the best taskbar ever"
run :: IO () data XOpts = XDeps | XTest | XRun
parseDeps :: Parser XOpts
parseDeps =
flag'
XDeps
(long "deps" <> short 'd' <> help "print dependencies")
parseTest :: Parser XOpts
parseTest =
flag'
XTest
(long "test" <> short 't' <> help "test dependencies without running")
xio :: XOpts -> IO ()
xio o = withCache $
case o of
XDeps -> printDeps
XTest -> withDBus_ evalConfig
XRun -> run
run :: FIO ()
run = do run = do
-- IDK why this is needed, I thought this was default -- IDK why this is needed, I thought this was default
hSetBuffering stdout LineBuffering liftIO $ hSetBuffering stdout LineBuffering
withCache $ withDBus_ $ \db -> do withDBus_ $ \db -> do
c <- evalConfig db c <- evalConfig db
liftIO $ xmobar c liftIO $ xmobar c
@ -73,15 +96,6 @@ printDeps = withDBus_ $ \db ->
concatMap dumpFeature $ concatMap dumpFeature $
allFeatures db allFeatures db
usage :: IO ()
usage =
putStrLn $
intercalate
"\n"
[ "xmobar: run greatest taskbar"
, "xmobar --deps: print dependencies"
]
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- toplevel configuration -- toplevel configuration