enigma-bbs/docs/_docs/configuration/config-files.md

128 lines
4.6 KiB
Markdown
Raw Permalink Normal View History

2020-06-18 01:46:18 +00:00
---
layout: page
title: Configuration Files
---
## General Information
ENiGMA½ configuration files such as the [system config](config-hjson.md), [menus](menu-hjson.md) and [themes](../art/themes.md) are formatted in the [HJSON format](hjson.md).
## Hot-Reload
Nearly all of ENiGMA½'s configuration can be hot-reloaded. That is, a live system can have it's configuration modified and it will be loaded in place.
2022-07-16 18:35:39 +00:00
> :bulb: [Monitoring live logs](../troubleshooting/monitoring-logs.md) is useful when making live changes. The system will complain if something is wrong!
2020-11-21 19:19:18 +00:00
2020-06-18 01:46:18 +00:00
## Common Directives
### Includes
Most configuration files offer an `includes` directive that allows users to break up large configuration files into smaller and organized parts. For example, consider a system with many menus/screens. Instead of a single `menu.hjson`, the SysOp may break this into `message-base.hjson`, `file-base.hjson`, etc.
The `includes` directive may be used the top-level scope of a configuration file:
```hjson
2020-06-18 04:04:30 +00:00
// menu.hjson
2020-06-18 01:46:18 +00:00
{
includes: [
message-base.hjson
file-base.hjson
]
menus: {
2020-06-18 04:04:30 +00:00
someOtherMenu: {
// ...
}
}
}
```
```hjson
// message-base.hjson
{
menus: {
someMessageMenu: {
2020-06-18 01:46:18 +00:00
// ...
}
}
}
```
### References
Often times in a configuration you will find that you're repeating yourself quite a bit. ENiGMA½ provides an `@reference` that can help with this in the form of `@reference:dot.path.to.section`.
2020-06-18 04:04:30 +00:00
Consider `actionKeys` in a menu. Often times you may show a screen and the user presses `Q` or `ESC` to fall back to the previous. Instead of repeating this in many menus, a generic block can be referenced:
2020-06-18 01:46:18 +00:00
```hjson
{
// note that 'recycle' here is arbitrary;
// only 'menus' and 'prompts' is reserved at this level.
recycle: {
2020-06-18 01:49:35 +00:00
prevMenu: [
{
keys: [ "escape" ]
action: @systemMethod:prevMenu
}
]
}
2020-06-18 01:46:18 +00:00
menus: {
someMenu: {
form: {
0: {
actionKeys: @reference:recycle.prevMenu
}
}
}
}
}
```
2022-07-16 18:35:39 +00:00
> :information_source: An unresolved `@reference` will be left intact.
2020-06-18 01:46:18 +00:00
### Environment Variables
2020-11-22 20:53:47 +00:00
Especially in a container environment such as [Docker](../installation/docker.md), environment variable access in configuration files can become very handy. ENiGMA½ provides a flexible way to access variables using the `@environment` directive. The most basic form of `@environment:VAR_NAME` produces a string value. Additionally a `:type` suffix can be supplied to coerece the value to a particular type. Variables pointing to a comma separated list can be turned to arrays using an additional `:array` suffix.
2020-06-18 01:46:18 +00:00
Below is a table of the various forms:
2020-11-21 19:04:37 +00:00
2020-06-18 01:46:18 +00:00
| Form | Variable Value | Produces |
|------|----------------|----------|
| `@environment:SOME_VAR` | "Foo" | `"Foo"` (without quotes) |
| `@environment:SOME_VAR` | "123" | `"123"` (without quotes) |
| `@environment:SOME_VAR:string` | "Bar" | `"Bar"` (without quotes) |
| `@environment:SOME_VAR:string:array` | "Foo,Bar" | `[ 'Foo', 'Bar' ]` |
| `@environment:SOME_VAR:boolean` | "1" | `true` |
| `@environment:SOME_VAR:boolean` | "True" | `true` |
| `@environment:SOME_VAR:boolean` | "false" | `false` |
| `@environment:SOME_VAR:boolean` | "cat" | `false` |
| `@environment:SOME_VAR:boolean:array` | "True,false,TRUE" | `[ true, false, true ]` |
| `@environment:SOME_VAR:number` | "123" | `123` |
| `@environment:SOME_VAR:number:array` | "123,456" | `[ 123, 456 ]` |
| `@environment:SOME_VAR:number` | "kitten" | (invalid) |
| `@environment:SOME_VAR:object` | '{"a":"b"}' | `{ 'a' : 'b' }` |
| `@environment:SOME_VAR:object:array` | '{"a":"b"},{"c":"d"}' | `[ { 'a' : 'b' }, { 'c' : 'd' } ]` |
| `@environment:SOME_VAR:timestamp` | "2020-01-05" | A [moment](https://momentjs.com/) object representing 2020-01-05 |
| `@environment:SOME_VAR:timestamp:array` | "2020-01-05,2016-05-16T01:15:37'" | An array of [moment](https://momentjs.com/) objects representing 2020-01-05 and 2016-05-16T01:15:37 |
2022-07-16 18:35:39 +00:00
> :bulb: `bool` may be used as an alias to `boolean`.
2020-06-18 01:46:18 +00:00
2022-07-16 18:35:39 +00:00
> :bulb: `timestamp` values can be in any form that [moment can parse](https://momentjs.com/docs/#/parsing/).
2020-06-18 01:46:18 +00:00
2022-07-16 18:35:39 +00:00
> :information_source: An unresolved or invalid `@environment` will be left intact.
2020-06-18 01:46:18 +00:00
2020-06-18 01:53:23 +00:00
Consider the following fragment:
```hjson
{
foo: {
bar: @environment:BAR_VAR:number
}
}
```
If the environment has `BAR_VAR=1337`, this would produce:
```hjson
{
foo: {
bar: 1337
}
}
```
2020-06-18 01:46:18 +00:00
## See Also
* [System Configuration](config-hjson.md)
* [Menu Configuration](menu-hjson.md)
* [The HJSON Format](hjson.md)