No description
Find a file
2023-10-23 18:08:07 -05:00
.github/workflows Removed i386 tests 2022-06-09 10:01:08 -05:00
src v0.3.5: typo 2023-08-23 22:45:09 -05:00
tests added commnet 2023-08-23 22:47:10 -05:00
.gitignore Removed i386 tests 2022-06-09 10:01:08 -05:00
CHANGELOG.md v0.3.4 2022-06-19 16:03:54 -05:00
niprefs.nimble v0.3.5: typo 2023-08-23 22:45:09 -05:00
README.md Update README.md 2023-10-23 18:08:07 -05:00

niprefs

A Nim library to manage preferences in a TOML file.

This project is archived! Check out kdl-nim

Installation

You can install niprefs with nimble:

nimble install niprefs

Or directly from this repo:

nimble install https://github.com/Patitotective/niprefs

Usage

A Prefs object requires a path and a default preferences. A TOML file is created at path with default whenever it's not found, if it exists it will read it.
To access the actual preferences (not the default) you may want to use Prefs.content and at the end of your program call Prefs.save() to update the preferences file.

toToml is a helpful macro to define your default preferences.
Instead of having to write:

{"a": [1.newTInt(), 2.newTInt()].newTArray()}.newTTable()

Using the toToml it's just as easy as writing:

toToml {a: [1, 2]}
import niprefs

# Default preferences are used the first time you run the program or whenever the file gets deleted.
var prefs = initPrefs(
  path = "prefs.toml", 
  default = toToml {
  "lang": "en", # Keys do not require quotes when using toToml macro
  dark: true,
  keybindings: {:},
  scheme: {
    background: "#000000",
    font: {
      size: 15,
      family: "UbuntuMono",
      color: "#73D216"
    }
  }
})

prefs["lang"] = "es"
assert prefs["lang"] == "es"

prefs.delete("lang")

assert "lang" notin prefs

prefs.save()

Check the docs for more.


About

Contact me:

Tested in Linux and Windows.