-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supporting live changes to the config is going to get increasingly complicated, and doesn't provide much value. The file is a necessary long-term solution anyway, for things like configurable theme and keybindings. Closes #89
- Loading branch information
1 parent
4ddb106
commit 7b32791
Showing
18 changed files
with
111 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use crate::util::{parse_yaml, Directory, ResultExt}; | ||
use anyhow::Context; | ||
use serde::Deserialize; | ||
use std::fs; | ||
use tracing::info; | ||
|
||
/// TODO | ||
#[derive(Debug, Deserialize)] | ||
#[serde(default)] | ||
pub struct Config { | ||
/// Should templates be rendered inline in the UI, or should we show the | ||
/// raw text? | ||
pub preview_templates: bool, | ||
} | ||
|
||
impl Config { | ||
const FILE: &'static str = "config.yml"; | ||
|
||
/// Load configuration from the file, if present. If not, just return a | ||
/// default value. This only returns an error if the file could be read, but | ||
/// deserialization failed. This is *not* async because it's only run during | ||
/// startup, when all operations are synchronous. | ||
pub fn load() -> anyhow::Result<Self> { | ||
let path = Directory::root().create()?.join(Self::FILE); | ||
info!(?path, "Loading configuration file"); | ||
|
||
match fs::read(&path) { | ||
Ok(bytes) => parse_yaml::<Self>(&bytes) | ||
.context(format!("Error loading configuration from {path:?}")) | ||
.traced(), | ||
// An error here is probably just the file missing, so don't make | ||
// a big stink about it | ||
Err(error) => { | ||
info!( | ||
?path, | ||
error = &error as &dyn std::error::Error, | ||
"Error reading configuration file" | ||
); | ||
Ok(Self::default()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl Default for Config { | ||
fn default() -> Self { | ||
Self { | ||
preview_templates: true, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
mod cli; | ||
mod collection; | ||
mod config; | ||
mod db; | ||
#[cfg(test)] | ||
mod factory; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ mod recipe_list; | |
mod request; | ||
mod response; | ||
mod root; | ||
mod settings; | ||
|
||
pub use root::Root; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.