ENH use optparse for xmobar
This commit is contained in:
parent
dea4ab6585
commit
b3f07ba590
|
@ -13,12 +13,12 @@ module Main (main) where
|
|||
|
||||
import Data.Internal.DBus
|
||||
import Data.Internal.Dependency
|
||||
import Options.Applicative
|
||||
import RIO hiding (hFlush)
|
||||
import qualified RIO.ByteString.Lazy as BL
|
||||
import RIO.List
|
||||
import RIO.Process
|
||||
import qualified RIO.Text as T
|
||||
import UnliftIO.Environment
|
||||
import XMonad.Core hiding (config)
|
||||
import XMonad.Internal.Command.Desktop
|
||||
import XMonad.Internal.Command.Power
|
||||
|
@ -40,19 +40,42 @@ import Xmobar.Plugins.Screensaver
|
|||
import Xmobar.Plugins.VPN
|
||||
|
||||
main :: IO ()
|
||||
main = getArgs >>= parse
|
||||
main = parse >>= xio
|
||||
|
||||
parse :: [String] -> IO ()
|
||||
parse [] = run
|
||||
parse ["--deps"] = withCache printDeps
|
||||
parse ["--test"] = withCache $ withDBus_ evalConfig
|
||||
parse _ = usage
|
||||
parse :: IO XOpts
|
||||
parse = execParser opts
|
||||
where
|
||||
parseOpts = parseDeps <|> parseTest <|> pure XRun
|
||||
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
|
||||
-- IDK why this is needed, I thought this was default
|
||||
hSetBuffering stdout LineBuffering
|
||||
withCache $ withDBus_ $ \db -> do
|
||||
liftIO $ hSetBuffering stdout LineBuffering
|
||||
withDBus_ $ \db -> do
|
||||
c <- evalConfig db
|
||||
liftIO $ xmobar c
|
||||
|
||||
|
@ -73,15 +96,6 @@ printDeps = withDBus_ $ \db ->
|
|||
concatMap dumpFeature $
|
||||
allFeatures db
|
||||
|
||||
usage :: IO ()
|
||||
usage =
|
||||
putStrLn $
|
||||
intercalate
|
||||
"\n"
|
||||
[ "xmobar: run greatest taskbar"
|
||||
, "xmobar --deps: print dependencies"
|
||||
]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- toplevel configuration
|
||||
|
||||
|
|
Loading…
Reference in New Issue