-
-
Notifications
You must be signed in to change notification settings - Fork 20
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. Also deleted DrawContext since it's just one field now. Closes #89
- Loading branch information
1 parent
4ddb106
commit 71776cf
Showing
29 changed files
with
280 additions
and
354 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Configuration | ||
|
||
Configuration provides _application_-level settings, as opposed to collection-level settings. | ||
|
||
## Location & Creation | ||
|
||
Configuration is stored in the Slumber root directory, under the file `config.yml`. To find the root directory, you can run: | ||
|
||
```sh | ||
slumber show dir | ||
``` | ||
|
||
To quickly create and edit the file: | ||
|
||
```sh | ||
# Replace vim with your favorite text editor | ||
vim $(slumber show dir)/config.yml | ||
``` | ||
|
||
If the root directory doesn't exist yet, you can create it yourself or have Slumber create it by simply starting the TUI. | ||
|
||
## Fields | ||
|
||
| Field | Type | Description | Default | | ||
| ------------------- | --------- | ---------------------------------------------------------------------------- | ------- | | ||
| `preview_templates` | `boolean` | Render template values in the TUI? If false, the raw template will be shown. | `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
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,70 @@ | ||
use crate::util::{parse_yaml, Directory, ResultExt}; | ||
use anyhow::Context; | ||
use serde::Deserialize; | ||
use std::{ | ||
fs, | ||
path::{Path, PathBuf}, | ||
}; | ||
use tracing::info; | ||
|
||
/// App-level configuration, which is global across all sessions and | ||
/// collections. This is *not* meant to modifiable during a session. If changes | ||
/// are made to the config file while a session is running, they won't be | ||
/// picked up until the app restarts. | ||
#[derive(Debug, Deserialize)] | ||
#[serde(default)] | ||
pub struct Config { | ||
/// The path that the config was loaded from, or tried to be loaded from if | ||
/// the file didn't exist | ||
#[serde(skip)] | ||
path: PathBuf, | ||
/// 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"); | ||
|
||
let mut config = 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()) | ||
} | ||
}?; | ||
|
||
config.path = path; | ||
Ok(config) | ||
} | ||
|
||
/// The path where configuration is stored | ||
pub fn path(&self) -> &Path { | ||
&self.path | ||
} | ||
} | ||
|
||
impl Default for Config { | ||
fn default() -> Self { | ||
Self { | ||
path: PathBuf::default(), | ||
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
Oops, something went wrong.