bjoernQ / rconfig

2 stars 0 forks source link

rconfig

Known Issues

Open Questions

Idea

In your crate's build.rs you need this

    rconfig::apply_config(&PathBuf::from("./config/rconfig.toml"));

A config-definition can looks like this

# something without a type is just a menu item
[psram]
description = "PSRAM"
# dependencies are actually Rhai script expressions which evaluate to bool
depends = 'feature("esp32") || feature("esp32s2") || feature("esp32s3")'

# something with a type is something which can be configured
[psram.options.enable]
description = "Enable PSRAM"
type = "bool"
default = false

[psram.options.size]
description = "PSRAM Size"
depends = 'enabled("psram.enable")'
type = "enum"
values = [
    { description = "1MB", value = "1" },
    { description = "2MB", value = "2" },
    { description = "4MB", value = "4" },
]
default = "2"

[psram.options.type]
description = "PSRAM Type"
depends = 'feature("esp32s3") && enabled("psram.enable")'

[psram.options.type.options.type]
description = "PSRAM Type"
depends = 'feature("esp32s3")'
type = "enum"
values = [
    { description = "Quad", value = "quad" },
    { description = "Octal", value = "octal" },
]
default = "quad"

[heap]
description = "Heapsize"

[heap.options.size]
description = "Bytes to allocate"
type = "u32"
# validations are actually Rhai script expressions which evaluate to bool
valid = 'value >= 0 && value <= 80000'

Note an option can depend on features and/or other options.

The values are available as

The config.toml in the binary crate looks like this

[fake-hal]
heap.size=30000
psram.enable=true
psram.size="4"
psram.type.type="octal"
[fake-wifi]
options.ble=false

TUI

Build ./rconfig-tui and run it in the example crate's folder (i.e. example/example). Probably it shouldn't be it's own crate but contained in the rconfig crate.

It will run a build of the binary crate to learn about the used crates supporting rconfig and how their config-definitions look like.

ESC will exit without saving the changes. S will save and exit the TUI.

Currently support for changing numeric and string values isn't great.

TUI

Options

While Ratatui is a really nice crate maybe having a GUI instead of a TUI is easier. (e.g. both eGui and Iced are both nice and come with a lot of useful widgets).