mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: Made TOML parse error message that omits the config file path
This commit is contained in:
parent
9accf929f4
commit
de29f8292a
6 changed files with 45 additions and 25 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use std::sync::Arc;
|
use std::{path::PathBuf, sync::Arc};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
@ -49,9 +49,10 @@ impl Keymap {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Keymap {
|
impl Keymap {
|
||||||
pub(crate) fn read() -> Result<String> {
|
pub(crate) fn read() -> Result<(PathBuf, String)> {
|
||||||
let p = Xdg::config_dir().join("keymap.toml");
|
let p = Xdg::config_dir().join("keymap.toml");
|
||||||
ok_or_not_found(std::fs::read_to_string(&p))
|
let s = ok_or_not_found(std::fs::read_to_string(&p))
|
||||||
.with_context(|| format!("Failed to read keymap {p:?}"))
|
.with_context(|| format!("Failed to read keymap {p:?}"))?;
|
||||||
|
Ok((p, s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ yazi_macro::mod_flat!(icon inject layout mixing pattern platform preset priority
|
||||||
|
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
|
use anyhow::Context;
|
||||||
use yazi_macro::writef;
|
use yazi_macro::writef;
|
||||||
use yazi_shim::{cell::{RoCell, SyncCell}, toml::{DeserializeOver, DeserializeOverWith}};
|
use yazi_shim::{cell::{RoCell, SyncCell}, toml::{DeserializeOver, DeserializeOverWith}};
|
||||||
use yazi_tty::{TTY, sequence::SetSgr};
|
use yazi_tty::{TTY, sequence::SetSgr};
|
||||||
|
|
@ -28,9 +29,14 @@ fn try_init(merge: bool) -> anyhow::Result<()> {
|
||||||
let mut vfs = Preset::vfs()?;
|
let mut vfs = Preset::vfs()?;
|
||||||
|
|
||||||
if merge {
|
if merge {
|
||||||
yazi = yazi.deserialize_over(&yazi::Yazi::read()?)?;
|
let (p, s) = yazi::Yazi::read()?;
|
||||||
keymap = keymap.deserialize_over(&keymap::Keymap::read()?)?;
|
yazi = yazi.deserialize_over(&s).with_context(|| format!("TOML parse error in {p:?}"))?;
|
||||||
vfs = vfs.deserialize_over(&vfs::Vfs::read()?)?;
|
|
||||||
|
let (p, s) = keymap::Keymap::read()?;
|
||||||
|
keymap = keymap.deserialize_over(&s).with_context(|| format!("TOML parse error in {p:?}"))?;
|
||||||
|
|
||||||
|
let (p, s) = vfs::Vfs::read()?;
|
||||||
|
vfs = vfs.deserialize_over(&s).with_context(|| format!("TOML parse error in {p:?}"))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
YAZI.init(yazi);
|
YAZI.init(yazi);
|
||||||
|
|
@ -56,16 +62,22 @@ pub fn build_flavor(light: bool, merge: bool) -> anyhow::Result<theme::Theme> {
|
||||||
let mut preset = Preset::theme(light)?;
|
let mut preset = Preset::theme(light)?;
|
||||||
|
|
||||||
if merge {
|
if merge {
|
||||||
let theme_str = theme::Theme::read()?;
|
let (theme_p, theme_str) = theme::Theme::read()?;
|
||||||
let theme = toml::de::DeTable::parse(&theme_str)?;
|
let theme = toml::de::DeTable::parse(&theme_str)
|
||||||
|
.with_context(|| format!("TOML parse error in {theme_p:?}"))?;
|
||||||
|
|
||||||
let flavor_str = theme::Flavor::from_theme(&theme, &theme_str)?.read(light)?;
|
let (flavor_p, flavor_str) = theme::Flavor::from_theme(&theme, &theme_str)
|
||||||
|
.with_context(|| format!("TOML parse error in {theme_p:?}"))?
|
||||||
|
.read(light)?;
|
||||||
|
|
||||||
preset = preset.deserialize_over(&flavor_str)?;
|
preset = preset.deserialize_over(&flavor_str).with_context(|| {
|
||||||
|
format!("TOML parse error in {:?}", flavor_p.unwrap_or_else(|| theme_p.clone()))
|
||||||
|
})?;
|
||||||
preset = error_with_input(
|
preset = error_with_input(
|
||||||
preset.deserialize_over_with(toml::de::Deserializer::from(theme)),
|
preset.deserialize_over_with(toml::de::Deserializer::from(theme)),
|
||||||
&theme_str,
|
&theme_str,
|
||||||
)?;
|
)
|
||||||
|
.with_context(|| format!("TOML parse error in {theme_p:?}"))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
preset.reshape(light)
|
preset.reshape(light)
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,14 @@ impl Flavor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn read(&self, light: bool) -> Result<String> {
|
pub(crate) fn read(&self, light: bool) -> Result<(Option<PathBuf>, String)> {
|
||||||
Ok(match if light { self.light.load() } else { self.dark.load() }.as_str() {
|
Ok(match if light { self.light.load() } else { self.dark.load() }.as_str() {
|
||||||
"" => String::new(),
|
"" => (None, String::new()),
|
||||||
name => {
|
name => {
|
||||||
let p = Xdg::config_dir().join(format!("flavors/{name}.yazi/flavor.toml"));
|
let p = Xdg::config_dir().join(format!("flavors/{name}.yazi/flavor.toml"));
|
||||||
std::fs::read_to_string(&p).with_context(|| format!("Failed to read flavor {p:?}"))?
|
let s =
|
||||||
|
std::fs::read_to_string(&p).with_context(|| format!("Failed to read flavor {p:?}"))?;
|
||||||
|
(Some(p), s)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,11 @@ pub struct Theme {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Theme {
|
impl Theme {
|
||||||
pub(crate) fn read() -> Result<String> {
|
pub(crate) fn read() -> Result<(PathBuf, String)> {
|
||||||
let p = Xdg::config_dir().join("theme.toml");
|
let p = Xdg::config_dir().join("theme.toml");
|
||||||
ok_or_not_found(std::fs::read_to_string(&p))
|
let s = ok_or_not_found(std::fs::read_to_string(&p))
|
||||||
.with_context(|| format!("Failed to read theme {p:?}"))
|
.with_context(|| format!("Failed to read theme {p:?}"))?;
|
||||||
|
Ok((p, s))
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: remove
|
// FIXME: remove
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use std::io;
|
use std::{io, path::PathBuf};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
|
|
@ -31,10 +31,11 @@ impl Vfs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn read() -> Result<String> {
|
pub(crate) fn read() -> Result<(PathBuf, String)> {
|
||||||
let p = Xdg::config_dir().join("vfs.toml");
|
let p = Xdg::config_dir().join("vfs.toml");
|
||||||
ok_or_not_found(std::fs::read_to_string(&p))
|
let s = ok_or_not_found(std::fs::read_to_string(&p))
|
||||||
.with_context(|| format!("Failed to read config {p:?}"))
|
.with_context(|| format!("Failed to read config {p:?}"))?;
|
||||||
|
Ok((p, s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use yazi_codegen::{DeserializeOver, DeserializeOver1};
|
use yazi_codegen::{DeserializeOver, DeserializeOver1};
|
||||||
|
|
@ -20,9 +22,10 @@ pub struct Yazi {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Yazi {
|
impl Yazi {
|
||||||
pub(super) fn read() -> Result<String> {
|
pub(super) fn read() -> Result<(PathBuf, String)> {
|
||||||
let p = Xdg::config_dir().join("yazi.toml");
|
let p = Xdg::config_dir().join("yazi.toml");
|
||||||
ok_or_not_found(std::fs::read_to_string(&p))
|
let s = ok_or_not_found(std::fs::read_to_string(&p))
|
||||||
.with_context(|| format!("Failed to read config {p:?}"))
|
.with_context(|| format!("Failed to read config {p:?}"))?;
|
||||||
|
Ok((p, s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue