app-settings: A library to manage application settings (INI file-like)

[ bsd3, configuration, library ] [ Propose Tags ]

A library to deal with application settings.

This library deals with read-write application settings. You will have to specify the settings that your application uses, their name, types and default values.

Setting types must implement the Read and Show typeclasses.

The settings are saved in a file in an INI-like key-value format (without sections).

Reading and updating settings is done in pure code, the IO monad is only used to load settings and save them to disk. It is advised for the user to create a module in your project holding settings handling.

You can then declare settings:

fontSize :: Setting Double
fontSize = Setting "fontSize" 14

dateFormat :: Setting String
dateFormat = Setting "dateFormat" "%x"

backgroundColor :: Setting (Int, Int, Int)
backgroundColor = Setting "backcolor" (255, 0, 0)

Optionally you can declare the list of all your settings:

defaultConfig :: DefaultConfig
defaultConfig = getDefaultConfig $ do
    setting fontSize
    setting dateFormat
    setting backgroundColor

If you do it, saveSettings will also save settings which have not been modified, which are still at their default value in the configuration file, in a commented form, as a documentation to the user who may open the configuration file. So for instance if you declare this default configuration and have set the font size to 16 but left the other settings untouched, the configuration file which will be saved will be:

fontSize=16
# dateFormat="%x"
# backcolor=(255,0,0)

If you did not specify the list of settings, only the first line would be present in the configuration file.

Once we declared the settings, we can read the configuration from disk (and your settings module should export your wrapper around the function offered by this library):

readResult <- try $ readSettings (AutoFromAppName "test")
case readResult of
	Right (conf, GetSetting getSetting) -> do
		let textSize = getSetting textSizeFromWidth
		saveSettings getDefaultConfig (AutoFromAppName "test") conf
	Left (x :: SomeException) -> error "Error reading the config file!"

AutoFromAppName specifies where to save the configuration file. And we've already covered the getSetting in this snippet, see the readSettings documentation for further information.

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.2.0.0, 0.2.0.1, 0.2.0.2, 0.2.0.3, 0.2.0.4, 0.2.0.5, 0.2.0.6, 0.2.0.7, 0.2.0.8, 0.2.0.9, 0.2.0.10, 0.2.0.11, 0.2.0.12 (info)
Dependencies base (>=4.6 && <4.7), containers (>=0.5 && <0.6), directory (>=1.2 && <1.3), mtl (>=2.1 && <2.2), parsec (>=3.1 && <3.2), text (>=0.10) [details]
License BSD-3-Clause
Author Emmanuel Touzery
Maintainer etouzery@gmail.com
Category Configuration
Home page https://github.com/emmanueltouzery/app-settings
Uploaded by EmmanuelTouzery at 2014-04-20T20:09:57Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 13523 total (46 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Successful builds reported [all 1 reports]