module Karabiner.Config.Internal where

import Data.Aeson.Types
import Data.Text (Text)
import Data.Aeson.Encode.Pretty hiding (Tab)
import Data.Functor ((<&>))
import System.Directory (getHomeDirectory)

expandUser :: FilePath -> IO FilePath
expandUser :: FilePath -> IO FilePath
expandUser = \case
  Char
'~':Char
'/':FilePath
path -> IO FilePath
getHomeDirectory IO FilePath -> (FilePath -> FilePath) -> IO FilePath
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<> (Char
'/'Char -> FilePath -> FilePath
forall a. a -> [a] -> [a]
:FilePath
path))
  FilePath
path -> FilePath -> IO FilePath
forall (f :: * -> *) a. Applicative f => a -> f a
pure FilePath
path

prettyConfig :: Config
prettyConfig :: Config
prettyConfig = Config
defConfig
  { confIndent :: Indent
confIndent = Int -> Indent
Spaces Int
2
  , confCompare :: Text -> Text -> Ordering
confCompare = Text -> Text -> Ordering
prettyConfigCompare
  }

prettyConfigCompare :: Text -> Text -> Ordering
prettyConfigCompare :: Text -> Text -> Ordering
prettyConfigCompare = [Text] -> Text -> Text -> Ordering
keyOrder
  [ Text
"title"
  , Text
"rules"
  , Text
"description"
  , Text
"manipulators"
  , Text
"type"
  , Text
"from"
  , Text
"to"
  , Text
"conditions"
  , Text
"key_code"
  , Text
"modifiers"
  ]

stripNulls :: [Pair] -> [Pair]
stripNulls :: [Pair] -> [Pair]
stripNulls [Pair]
xs = (Pair -> Bool) -> [Pair] -> [Pair]
forall a. (a -> Bool) -> [a] -> [a]
filter (\(Text
_,Value
v) -> Value
v Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
/= Value
Null) [Pair]
xs