better theme file handling (#2077)

* better theme file handling
* print all possible err of loading theme

closes #2007
This commit is contained in:
extrawurst 2024-02-20 18:52:35 +01:00 committed by GitHub
parent 2b39c6465a
commit 762b889b48
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 10 additions and 16 deletions

View file

@ -35,6 +35,7 @@ These defaults require some adoption from existing users but feel more natural t
### Fixes
* stash window empty after file history popup closes ([#1986](https://github.com/extrawurst/gitui/issues/1986))
* allow push to empty remote ([#1919](https://github.com/extrawurst/gitui/issues/1919))
* better diagnostics for theme file loading ([#2007](https://github.com/extrawurst/gitui/issues/2007))
## [0.24.3] - 2023-09-09

View file

@ -121,7 +121,6 @@ pub fn tag_commit(
#[cfg(test)]
mod tests {
use crate::error::Result;
use crate::sync::tags::Tag;
use crate::sync::RepoPath;

View file

@ -48,11 +48,7 @@ pub fn process_cmdline() -> Result<CliArgs> {
.get_one::<String>("theme")
.map_or_else(|| PathBuf::from("theme.ron"), PathBuf::from);
let theme = if get_app_config_path()?.join(&arg_theme).is_file() {
get_app_config_path()?.join(arg_theme)
} else {
get_app_config_path()?.join("theme.ron")
};
let theme = get_app_config_path()?.join(arg_theme);
let notify_watcher: bool =
*arg_matches.get_one("watcher").unwrap_or(&false);
@ -82,10 +78,11 @@ fn app() -> ClapApp {
)
.arg(
Arg::new("theme")
.help("Set the color theme (defaults to theme.ron)")
.help("Set color theme filename loaded from config directory")
.short('t')
.long("theme")
.value_name("THEME")
.value_name("THEME_FILE")
.default_value("theme.ron")
.num_args(1),
)
.arg(

View file

@ -274,13 +274,7 @@ impl Theme {
fn load_patch(theme_path: &PathBuf) -> Result<ThemePatch> {
let file = File::open(theme_path)?;
let load_result = ron::de::from_reader(file);
if let Err(e) = &load_result {
log::error!("theme error [{:?}]: {e}", theme_path);
}
Ok(load_result?)
Ok(ron::de::from_reader(file)?)
}
fn load_old_theme(theme_path: &PathBuf) -> Result<Self> {
@ -303,7 +297,10 @@ impl Theme {
pub fn init(theme_path: &PathBuf) -> Self {
let mut theme = Self::default();
if let Ok(patch) = Self::load_patch(theme_path) {
if let Ok(patch) = Self::load_patch(theme_path).map_err(|e| {
log::error!("theme error [{:?}]: {e}", theme_path);
e
}) {
theme.apply(patch);
} else if let Ok(old_theme) = Self::load_old_theme(theme_path)
{