Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
/ niprefs Public archive

A dynamic preferences-system with a table-like structure for Nim.

Notifications You must be signed in to change notification settings

Patitotective/niprefs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.