Copyright | (c) Dennis Gosnell 2023 |
---|---|
License | BSD3 |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
Termonad.Preferences.File
Description
This module contains functions for reading and writing to the preferences file.
The preferences file is generally stored in
~.configtermonad/termonad.yaml
. It stores run-time preferences that
have been set through the Preferences dialog. Preferences are loaded on
app startup, but only if the termonad.hs
configuration file doesn't exist.
Synopsis
- getPreferencesFile :: IO FilePath
- tmConfigFromPreferencesFile :: IO TMConfig
- readFileWithDefaults :: FilePath -> IO (Either Text ConfigOptions)
- mergeObjVals :: Value -> Value -> Value
- writePreferencesFile :: FilePath -> ConfigOptions -> IO ()
- saveToPreferencesFile :: TMConfig -> IO ()
Documentation
>>>
import Data.Aeson(object, (.=))
getPreferencesFile :: IO FilePath Source #
Get the path to the preferences file ~/.config/termonad/termonad.yaml
.
tmConfigFromPreferencesFile :: IO TMConfig Source #
Read the configuration for the preferences file
~/.config/termonad/termonad.yaml
. This file stores only the options
of
TMConfig
so hooks
are initialized with defaultConfigHooks
. If the
file doesn't exist, create it with the default values.
Any options that do not exist will get initialized with values from
defaultConfigOptions
.
readFileWithDefaults :: FilePath -> IO (Either Text ConfigOptions) Source #
Read the ConfigOptions
out of a configuration file.
Merge the raw ConfigOptions
with defaultConfigOptions
. This makes sure
that old versions of the configuration file will still be able to be read
even if new options are added to ConfigOptions
in new versions of
Termonad.
Arguments
:: Value | Value that has been set explicitly in the User's configuration file. |
-> Value | Default value that will be used if no explicitly set value. |
-> Value | Merged values. |
Merge Value
s recursively.
This merges Value
s recursively in Object
values, taking values that
have been explicitly over the defaults. The defaults are only used if
there is no value that has been explicitly set.
For Array
, String
, Number
, Bool
, and Null
, take the first Value
(the one that has been explicitly set in the user's config file):
>>>
mergeObjVals (Array [Number 1, Number 2]) (Array [String "hello"])
Array [Number 1.0,Number 2.0]>>>
mergeObjVals (String "hello") (String "bye")
String "hello">>>
mergeObjVals (Number 1) (Number 2)
Number 1.0>>>
mergeObjVals (Bool True) (Bool False)
Bool True>>>
mergeObjVals Null Null
Null
Note that Value
s in Array
s are not recursed into:
>>>
let obj1 = object ["hello" .= Number 2]
>>>
let obj2 = object ["hello" .= String "bye"]
>>>
mergeObjVals (Array [obj1]) (Array [obj2])
Array [Object (fromList [("hello",Number 2.0)])]
Object
s are recursed into. Unique keys from both Maps will be used.
Keys that are in both Maps will be merged according to the rules above:
>>>
let object1 = object ["hello" .= Number 1, "bye" .= Number 100]
>>>
let object2 = object ["hello" .= Number 2, "goat" .= String "chicken"]
>>>
mergeObjVals object1 object2
Object (fromList [("bye",Number 100.0),("goat",String "chicken"),("hello",Number 1.0)])
Value
s of different types will use the second Value
:
>>>
mergeObjVals Null (String "bye")
String "bye">>>
mergeObjVals (Bool True) (Number 2)
Number 2.0>>>
mergeObjVals (Object mempty) (Bool False)
Bool False
writePreferencesFile :: FilePath -> ConfigOptions -> IO () Source #
saveToPreferencesFile :: TMConfig -> IO () Source #
Save the configuration to the preferences file
~/.config/termonad/termonad.yaml