termonad-4.2.0.0: Terminal emulator configurable in Haskell
Safe HaskellNone
LanguageHaskell2010

Termonad.PreferencesFile

Synopsis

Documentation

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.

mergeObjVals Source #

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 Values recursively.

This merges Values 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 Values in Arrays are not recursed into:

>>> let obj1 = Object $ HashMap.singleton "hello" (Number 2)
>>> let obj2 = Object $ HashMap.singleton "hello" (String "bye")
>>> mergeObjVals (Array [obj1]) (Array [obj2])
Array [Object (fromList [("hello",Number 2.0)])]

Objects 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 hash1 = HashMap.fromList [("hello", Number 1), ("bye", Number 100)]
>>> let hash2 = HashMap.fromList [("hello", Number 2), ("goat", String "chicken")]
>>> mergeObjVals (Object hash1) (Object hash2)
Object (fromList [("bye",Number 100.0),("goat",String "chicken"),("hello",Number 1.0)])

Values 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

saveToPreferencesFile :: TMConfig -> IO () Source #

Save the configuration to the preferences file ~/.config/termonad/termonad.yaml