Config: persisted settings
lib/config/tui_config.sh - the small key/value store for framework settings, applied at tui.init. ← API index for the full module list and a task-oriented tour with examples.
Persisted config
Settings live in ~/.config/DABT/apps/<TUI_APP_NAME>/dabt.conf as key=value lines (set TUI_CONFIG_FILE before sourcing tui.sh to use another file). Any key can be stored; apps may keep their own keys here too. The framework reads these:
| Key | Values | Read |
|---|---|---|
theme |
path to a .css overlay |
at start (the Settings page writes it; tui.theme.set alone does not) |
defaults.off |
space-separated default-bind groups | at start |
input.retain |
1 / 0 |
at start |
input.coalesce |
1 / 0 |
at start |
notify.position |
see tui.notify.position |
at start |
notify.seconds |
seconds, 0 = sticky |
at start |
confirm.quit |
1 / 0 |
at every quit |
plugin.NAME.enabled, plugin.NAME.KEY |
plugin state and settings | by the plugin system |
Functions return 0 unless stated.
| Function | Summary |
|---|---|
tui.config.get |
Prints the saved value of a setting. |
tui.config.set |
Stores a setting and writes the config file immediately. |
tui.config.unset |
Removes a setting and writes the config file immediately. |
tui.config.keys |
Prints every stored key, sorted, one per line. |
tui.config.load |
Replaces the in-memory store with the contents of the config file. |
tui.config.save |
Writes the in-memory store to the config file. |
tui.config.apply |
Applies the stored framework settings to the running framework. |
tui.config.get
tui.config.get KEY [DEFAULT]
Prints the saved value of a setting.
Parameters
KEY: setting name, e.g.themeormy.option.DEFAULT: printed whenKEYis not stored. Default: empty.
Output: the value, without a trailing newline.
Notes
- A key stored with an empty value prints the empty value, not
DEFAULT. - Reads the in-memory store. The file is read once when the library is sourced; call
tui.config.loadto pick up outside edits.
Example
if [[ "$(tui.config.get my.autosave 1)" == 1 ]]; then save_now; fi
See also: tui.config.set, tui.config.keys
tui.config.set
tui.config.set KEY VALUE
Stores a setting and writes the config file immediately.
Parameters
KEY: setting name. Any key is accepted; see the module intro for the ones the framework reads.VALUE: the value. Must not contain a newline.
Returns: 1 when the config directory cannot be created, else 0.
Notes
- Does not apply the change to the running app. Framework keys read at start (
theme,defaults.off,input.*,notify.*) take effect on the next start or aftertui.config.apply;confirm.quitis read at quit time and takes effect at once. - Rewrites the whole file on every call. Don’t call it from a timer or tick function.
Example
tui.config.set confirm.quit 1
See also: tui.config.get, tui.config.unset
tui.config.unset
tui.config.unset KEY
Removes a setting and writes the config file immediately.
Parameters
KEY: setting name.
Notes
- When the last key is removed the config file is deleted.
See also: tui.config.set
tui.config.keys
tui.config.keys
Prints every stored key, sorted, one per line.
Output: one key per line; nothing when the store is empty.
See also: tui.config.get
tui.config.load
tui.config.load
Replaces the in-memory store with the contents of the config file.
Notes
- Runs automatically when the library is sourced. Call it again only to pick up changes made outside the running app.
- Lines starting with
#and lines without=are skipped. The value is everything after the first=. - A missing file gives an empty store and returns
0.
See also: tui.config.save, tui.config.apply
tui.config.save
tui.config.save
Writes the in-memory store to the config file.
Returns: 1 when the config directory cannot be created, else 0.
Notes
- Keys are written sorted, as
key=valuelines under a comment header. The write goes to a temporary file that is then moved into place, so a crash never leaves a half-written file. - An empty store deletes the file instead.
tui.config.setandtui.config.unsetalready call it.
See also: tui.config.load
tui.config.apply
tui.config.apply
Applies the stored framework settings to the running framework.
Notes
- Called by
tui.init. Readstheme,defaults.off,notify.position,notify.seconds,input.retainandinput.coalesce; other keys are ignored. themeis applied only when the file it names is readable.defaults.offonly turns groups off. A group missing from the list is not turned back on; usetui.defaults.on.
See also: tui.config.set
