Skip to content

Commit

Permalink
make configuration handling a lot better (#141)
Browse files Browse the repository at this point in the history
* add preliminary support for more advanced configuration options in odilia

this is currently using figment as the configuration library, other options include config and simply serde-toml
this is not yet complete, as huge refactorings are about to take place

* refactor state a bit, to create config.toml from scratch based on default values

* refactor State::new to use figment directly

* make configuration be working from main, instead of state::new and make state::new accept the configuration structure as a parameter

this makes it easier to make, for example, speech have the desired rate from startup, logging be initialised from the config with the desired filter and perhaps a path location, stuff like that

* fix: screenreader applies configuration properly

the method join replaced the previously used merge. Apparently, with merge, when conflicts are encountered, it preferes keeping the current value, instead of replacing it. So, config was taken from the default values supplied with the modules, but the values in there were never replaced by those who should have a greatter priority.
as a consequence, user defined configuration files wouldn't be applied, and the user would understandably be confused by the results

* honor configuration when setting the speech rate

up to now, configuration was read, but never actually used. This begins a series of changes, perhaps across multiple fronts, to do so.
This makes `state::new` send a message on the ssip channel, with the request to set the rate to a user defined value
warning: if somehow the ssip task isn't initialized by the point we get there, the change will be lost in the channel, or may be picked up later than intended

* env: attempt to parse nested configuration

we use nested toml tables in our configuration, one table per what we think to be a logical section. However, because we want to add environment variables as configuration sources, we have to be able to parse nested dictionaries.
In order to do that, beside just using .prefix to filter out variables which don't concern us, we must also split the string of the variable name in keys, and for that we try to use the .split method

* refactor: move loading of configuration in its own function

Cargo format

* remove environment variable configuration, as it's not working with our composite configuration keys

* fix clippy warning

* fix configuration again not joining properly

* make logging subsystem use the logging level provided in the configuration file and make the configuration struct easier to use

* allow odilia to accept a log file and use it to log information, same for the system journal and tty

* specify tty in the config file for logs to be sent to your terminal
* use the file option to send it to a file
* use syslog for writing to the journal, for systemd equipped distros

* add pitch to the configuration

* add volume configuration

* make output module configurable and run the formatter a bit

* add language and voice to the configuration

* make punctuation reporting configurable

* fix formatting
  • Loading branch information
albertotirla authored Apr 26, 2024
1 parent 472044d commit 7a91a84
Show file tree
Hide file tree
Showing 11 changed files with 366 additions and 147 deletions.
176 changes: 165 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ bitflags = "1.3.2"
serde = "1.0.147"
smartstring = "1.0.1"
thiserror = "1.0.37"
tini = "^1.3.0"
zbus.workspace = true
serde_plain.workspace = true
figment = "0.10.15"
10 changes: 5 additions & 5 deletions common/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ pub enum OdiliaError {
}
#[derive(Debug)]
pub enum ConfigError {
Tini(tini::Error),
Figment(figment::Error),
ValueNotFound,
PathNotFound,
}
impl From<tini::Error> for ConfigError {
fn from(t_err: tini::Error) -> Self {
Self::Tini(t_err)
impl From<figment::Error> for ConfigError {
fn from(t_err: figment::Error) -> Self {
Self::Figment(t_err)
}
}
impl std::fmt::Display for ConfigError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Tini(t) => t.fmt(f),
Self::Figment(t) => t.fmt(f),
Self::ValueNotFound => f.write_str("Vlaue not found in config file."),
Self::PathNotFound => {
f.write_str("The path for the config file was not found.")
Expand Down
Loading

0 comments on commit 7a91a84

Please sign in to comment.