ENH use optparse for xmonad

This commit is contained in:
Nathan Dwarshuis 2023-01-01 11:41:04 -05:00
parent 0e1b117639
commit dea4ab6585
2 changed files with 66 additions and 52 deletions

View File

@ -16,6 +16,7 @@ import Data.Text.IO (hPutStrLn)
import Graphics.X11.Types import Graphics.X11.Types
import Graphics.X11.Xlib.Atom import Graphics.X11.Xlib.Atom
import Graphics.X11.Xlib.Extras import Graphics.X11.Xlib.Extras
import Options.Applicative hiding (action)
import RIO import RIO
import RIO.Directory import RIO.Directory
import RIO.List import RIO.List
@ -26,7 +27,6 @@ import System.Process
( getPid ( getPid
, getProcessExitCode , getProcessExitCode
) )
import UnliftIO.Environment
import XMonad import XMonad
import XMonad.Actions.CopyWindow import XMonad.Actions.CopyWindow
import XMonad.Actions.CycleWS import XMonad.Actions.CycleWS
@ -66,15 +66,38 @@ import XMonad.Util.NamedActions
import XMonad.Util.WorkspaceCompare import XMonad.Util.WorkspaceCompare
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"] = void $ withCache . evalConf =<< connectDBusX parseOpts = parseDeps <|> parseTest <|> pure XRun
parse _ = usage opts =
info (parseOpts <**> helper) $
fullDesc <> header "xmonad: the best window manager 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 -> undefined
XRun -> run
run :: FIO ()
run = do run = do
-- These first two commands are only significant when xmonad is restarted. -- These first two commands are only significant when xmonad is restarted.
-- The 'launch' function below this will turn off buffering (so flushes are -- The 'launch' function below this will turn off buffering (so flushes are
@ -89,7 +112,6 @@ run = do
-- signal handlers to carry over to the top. -- signal handlers to carry over to the top.
uninstallSignalHandlers uninstallSignalHandlers
hSetBuffering stdout LineBuffering hSetBuffering stdout LineBuffering
withCache $ do
withDBusX_ $ \db -> do withDBusX_ $ \db -> do
let fs = features $ dbSysClient db let fs = features $ dbSysClient db
startDBusInterfaces db fs startDBusInterfaces db fs
@ -237,15 +259,6 @@ allFeatures db = withRunInIO $ \runIO -> do
where where
ts = ThreadState {tsChildPIDs = [], tsXmobar = Nothing} ts = ThreadState {tsChildPIDs = [], tsXmobar = Nothing}
usage :: IO ()
usage =
putStrLn $
intercalate
"\n"
[ "xmonad: run greatest window manager"
, "xmonad --deps: print dependencies"
]
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- Concurrency configuration -- Concurrency configuration

View File

@ -35,6 +35,7 @@ dependencies:
- typed-process >= 0.2.8.0 - typed-process >= 0.2.8.0
- network >= 3.1.2.7 - network >= 3.1.2.7
- unliftio >= 0.2.21.0 - unliftio >= 0.2.21.0
- optparse-applicative >= 0.16.1.0
library: library:
source-dirs: lib/ source-dirs: lib/