module Engine.Types.Options ( Options(..) , getOptions , optionsP ) where import RIO import Options.Applicative.Simple qualified as Opt import Paths_keid_core qualified -- | Command line arguments data Options = Options { optionsVerbose :: Bool , optionsMaxFPS :: Maybe Int , optionsFullscreen :: Bool , optionsDisplay :: Natural , optionsSize :: Maybe (Int, Int) , optionsRecyclerWait :: Maybe Int } deriving (Show) getOptions :: IO Options getOptions = do (options, ()) <- Opt.simpleOptions $(Opt.simpleVersion Paths_keid_core.version) header description optionsP Opt.empty pure options where header = "Another playground" description = mempty optionsP :: Opt.Parser Options optionsP = do optionsVerbose <- Opt.switch $ mconcat [ Opt.long "verbose" , Opt.short 'v' , Opt.help "Show more and more detailed messages" ] optionsMaxFPS <- Opt.optional . Opt.option Opt.auto $ mconcat [ Opt.long "max-fps" , Opt.help "Limit the FPS" , Opt.metavar "FPS" ] optionsFullscreen <- Opt.switch $ mconcat [ Opt.long "fullscreen" , Opt.short 'f' , Opt.help "Run in fullscreen mode" ] optionsSize <- Opt.optional . Opt.option readSize $ mconcat [ Opt.long "size" , Opt.help "Initial window size" , Opt.metavar "WIDTHxHEIGHT" ] optionsDisplay <- Opt.option Opt.auto $ mconcat [ Opt.long "display" , Opt.help "Select display number" , Opt.value 0 ] optionsRecyclerWait <- Opt.optional . Opt.option Opt.auto $ mconcat [ Opt.long "recycler-wait" , Opt.help "Inject a delay before waiting for a timeline semaphore." ] pure Options{..} readSize :: Opt.ReadM (Int, Int) readSize = do o <- Opt.str let (w,h) = break (== 'x') o case (readMaybe w, readMaybe (drop 1 h)) of (Just w', Just h') -> pure (w', h') _ -> fail "Can't read window size"