Hardcode default config, and document how config works

This commit is contained in:
Val Lorentz 2023-11-18 11:27:32 +01:00
parent fec449b933
commit 2856dd0504
5 changed files with 35 additions and 10 deletions

View File

@ -3,15 +3,7 @@
{
"user_id": "@alice:example.org",
"password": "hunter2",
// Optional: "device_name": "ratatrix on <hostname>",
},
],
"keybindings": {
"Home": {
"<Ctrl-d>": "/quit",
"<Ctrl-c>": "/quit",
"<Ctrl-z>": "/suspend",
"<Alt-left>": "/previous",
"<Alt-right>": "/next",
},
}
}

4
.config/config.toml Normal file
View File

@ -0,0 +1,4 @@
[[accounts]]
user_id = "@alice:example.com"
password = "hunter2"
# Optional: device_name = "ratatrix on <hostname>"

View File

@ -1,2 +1,18 @@
# ratatrix
## Setup
1. Create an account on [any Matrix homeserver](https://servers.joinmatrix.org/)
2. Install Rust
3. Copy `.config/config.toml` or `.config/config.json5` to `~/.config/ratatrix/`
and fill the placeholders with your credentials
4. `cargo run`
## Configuration
Ratatrix supports multiple configuration format: TOML, JSON/JSON5, YAML, and INI,
you may choose whichever you prefer. If you don't have a preference, pick TOML.
Example configurations for TOML and JSON5 are provided in `.config`.
Default values for all settings, and their documentation, can be found in
`src/default_config.toml`.

View File

@ -13,6 +13,8 @@ use serde_json::Value as JsonValue;
use crate::{action::Action, mode::Mode};
const DEFAULT_CONFIG: &str = include_str!("default_config.toml");
#[derive(Clone, Debug, Deserialize, Default)]
pub struct AppConfig {
#[serde(default)]
@ -55,7 +57,11 @@ impl Config {
let config_dir = crate::utils::get_config_dir();
let mut builder = config::Config::builder()
.set_default("_data_dir", data_dir.to_str().unwrap())?
.set_default("_config_dir", config_dir.to_str().unwrap())?;
.set_default("_config_dir", config_dir.to_str().unwrap())?
.add_source(config::File::from_str(
DEFAULT_CONFIG,
config::FileFormat::Toml,
));
let config_files = [
("config.json5", config::FileFormat::Json5),

7
src/default_config.toml Normal file
View File

@ -0,0 +1,7 @@
# Key bindings in the main "Home" mode
[keybindings.Home]
"<Ctrl-d>" = "/quit"
"<Ctrl-c>" = "/quit"
"<Ctrl-z>" = "/suspend"
"<Alt-left>" = "/previous"
"<Alt-right>" = "/next"