module Engine.Types.Options
( Options(..)
, getOptions
, optionsP
) where
import RIO
import Options.Applicative.Simple qualified as Opt
import Paths_keid_core qualified
data Options = Options
{ Options -> Bool
optionsVerbose :: Bool
, Options -> Maybe Int
optionsMaxFPS :: Maybe Int
, Options -> Bool
optionsFullscreen :: Bool
, Options -> Natural
optionsDisplay :: Natural
, Options -> Maybe (Int, Int)
optionsSize :: Maybe (Int, Int)
, Options -> Maybe Int
optionsRecyclerWait :: Maybe Int
}
deriving (Int -> Options -> ShowS
[Options] -> ShowS
Options -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [Options] -> ShowS
$cshowList :: [Options] -> ShowS
show :: Options -> [Char]
$cshow :: Options -> [Char]
showsPrec :: Int -> Options -> ShowS
$cshowsPrec :: Int -> Options -> ShowS
Show)
getOptions :: IO Options
getOptions :: IO Options
getOptions = do
(Options
options, ()) <- forall a b.
[Char]
-> [Char]
-> [Char]
-> Parser a
-> ExceptT b (Writer (Mod CommandFields b)) ()
-> IO (a, b)
Opt.simpleOptions
$(Opt.simpleVersion Paths_keid_core.version)
[Char]
header
[Char]
description
Parser Options
optionsP
forall (f :: * -> *) a. Alternative f => f a
Opt.empty
forall (f :: * -> *) a. Applicative f => a -> f a
pure Options
options
where
header :: [Char]
header =
[Char]
"Another playground"
description :: [Char]
description =
forall a. Monoid a => a
mempty
optionsP :: Opt.Parser Options
optionsP :: Parser Options
optionsP = do
Bool
optionsVerbose <- Mod FlagFields Bool -> Parser Bool
Opt.switch forall a b. (a -> b) -> a -> b
$ forall a. Monoid a => [a] -> a
mconcat
[ forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
Opt.long [Char]
"verbose"
, forall (f :: * -> *) a. HasName f => Char -> Mod f a
Opt.short Char
'v'
, forall (f :: * -> *) a. [Char] -> Mod f a
Opt.help [Char]
"Show more and more detailed messages"
]
Maybe Int
optionsMaxFPS <- forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
Opt.optional forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ReadM a -> Mod OptionFields a -> Parser a
Opt.option forall a. Read a => ReadM a
Opt.auto forall a b. (a -> b) -> a -> b
$ forall a. Monoid a => [a] -> a
mconcat
[ forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
Opt.long [Char]
"max-fps"
, forall (f :: * -> *) a. [Char] -> Mod f a
Opt.help [Char]
"Limit the FPS"
, forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
Opt.metavar [Char]
"FPS"
]
Bool
optionsFullscreen <- Mod FlagFields Bool -> Parser Bool
Opt.switch forall a b. (a -> b) -> a -> b
$ forall a. Monoid a => [a] -> a
mconcat
[ forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
Opt.long [Char]
"fullscreen"
, forall (f :: * -> *) a. HasName f => Char -> Mod f a
Opt.short Char
'f'
, forall (f :: * -> *) a. [Char] -> Mod f a
Opt.help [Char]
"Run in fullscreen mode"
]
Maybe (Int, Int)
optionsSize <- forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
Opt.optional forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ReadM a -> Mod OptionFields a -> Parser a
Opt.option ReadM (Int, Int)
readSize forall a b. (a -> b) -> a -> b
$ forall a. Monoid a => [a] -> a
mconcat
[ forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
Opt.long [Char]
"size"
, forall (f :: * -> *) a. [Char] -> Mod f a
Opt.help [Char]
"Initial window size"
, forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
Opt.metavar [Char]
"WIDTHxHEIGHT"
]
Natural
optionsDisplay <- forall a. ReadM a -> Mod OptionFields a -> Parser a
Opt.option forall a. Read a => ReadM a
Opt.auto forall a b. (a -> b) -> a -> b
$ forall a. Monoid a => [a] -> a
mconcat
[ forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
Opt.long [Char]
"display"
, forall (f :: * -> *) a. [Char] -> Mod f a
Opt.help [Char]
"Select display number"
, forall (f :: * -> *) a. HasValue f => a -> Mod f a
Opt.value Natural
0
]
Maybe Int
optionsRecyclerWait <- forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
Opt.optional forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ReadM a -> Mod OptionFields a -> Parser a
Opt.option forall a. Read a => ReadM a
Opt.auto forall a b. (a -> b) -> a -> b
$ forall a. Monoid a => [a] -> a
mconcat
[ forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
Opt.long [Char]
"recycler-wait"
, forall (f :: * -> *) a. [Char] -> Mod f a
Opt.help [Char]
"Inject a delay before waiting for a timeline semaphore."
]
pure Options{Bool
Natural
Maybe Int
Maybe (Int, Int)
optionsRecyclerWait :: Maybe Int
optionsDisplay :: Natural
optionsSize :: Maybe (Int, Int)
optionsFullscreen :: Bool
optionsMaxFPS :: Maybe Int
optionsVerbose :: Bool
$sel:optionsRecyclerWait:Options :: Maybe Int
$sel:optionsSize:Options :: Maybe (Int, Int)
$sel:optionsDisplay:Options :: Natural
$sel:optionsFullscreen:Options :: Bool
$sel:optionsMaxFPS:Options :: Maybe Int
$sel:optionsVerbose:Options :: Bool
..}
readSize :: Opt.ReadM (Int, Int)
readSize :: ReadM (Int, Int)
readSize = do
[Char]
o <- forall s. IsString s => ReadM s
Opt.str
let ([Char]
w,[Char]
h) = forall a. (a -> Bool) -> [a] -> ([a], [a])
break (forall a. Eq a => a -> a -> Bool
== Char
'x') [Char]
o
case (forall a. Read a => [Char] -> Maybe a
readMaybe [Char]
w, forall a. Read a => [Char] -> Maybe a
readMaybe (forall a. Int -> [a] -> [a]
drop Int
1 [Char]
h)) of
(Just Int
w', Just Int
h') -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
w', Int
h')
(Maybe Int, Maybe Int)
_ -> forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail [Char]
"Can't read window size"