module Navi.Utils
(
getFieldOptArrayOf,
commandDecoder,
urgencyLevelOptDecoder,
)
where
import DBus.Notify (UrgencyLevel (..))
import Navi.Prelude
import Pythia.Data.Command (Command (..))
getFieldOptArrayOf :: DecodeTOML a => Text -> Decoder [a]
getFieldOptArrayOf :: forall a. DecodeTOML a => Text -> Decoder [a]
getFieldOptArrayOf =
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. a -> Maybe a -> a
fromMaybe [])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Decoder a -> Text -> Decoder (Maybe a)
getFieldOptWith (forall a. Decoder a -> Decoder [a]
getArrayOf forall a. DecodeTOML a => Decoder a
tomlDecoder)
urgencyLevelOptDecoder :: Decoder (Maybe UrgencyLevel)
urgencyLevelOptDecoder :: Decoder (Maybe UrgencyLevel)
urgencyLevelOptDecoder = forall a. Decoder a -> Text -> Decoder (Maybe a)
getFieldOptWith Decoder UrgencyLevel
urgencyLevelDecoder Text
"urgency"
urgencyLevelDecoder :: Decoder UrgencyLevel
urgencyLevelDecoder :: Decoder UrgencyLevel
urgencyLevelDecoder = do
Text
t <- forall a. DecodeTOML a => Decoder a
tomlDecoder
case Text
t of
Text
"low" -> forall (f :: Type -> Type) a. Applicative f => a -> f a
pure UrgencyLevel
Low
Text
"normal" -> forall (f :: Type -> Type) a. Applicative f => a -> f a
pure UrgencyLevel
Normal
Text
"critical" -> forall (f :: Type -> Type) a. Applicative f => a -> f a
pure UrgencyLevel
Critical
Text
bad -> forall (m :: Type -> Type) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ Text -> String
unpack forall a b. (a -> b) -> a -> b
$ Text
"Invalid value: " forall a. Semigroup a => a -> a -> a
<> Text
bad
{-# INLINEABLE urgencyLevelDecoder #-}
commandDecoder :: Decoder Command
commandDecoder :: Decoder Command
commandDecoder = Text -> Command
MkCommand forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. DecodeTOML a => Text -> Decoder a
getField Text
"command"