This commit is contained in:
Yahddyyp 2026-07-22 13:49:36 +00:00 committed by GitHub
commit 8d76b0835d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 45 additions and 25 deletions

View file

@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{path::PathBuf, sync::Arc};
use anyhow::{Context, Result};
use serde::Deserialize;
@ -49,9 +49,10 @@ 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");
ok_or_not_found(std::fs::read_to_string(&p))
.with_context(|| format!("Failed to read keymap {p:?}"))
let s = ok_or_not_found(std::fs::read_to_string(&p))
.with_context(|| format!("Failed to read keymap {p:?}"))?;
Ok((p, s))
}
}

View file

@ -4,6 +4,7 @@ yazi_macro::mod_flat!(icon inject layout mixing pattern platform preset priority
use std::io::{Read, Write};
use anyhow::Context;
use yazi_macro::writef;
use yazi_shim::{cell::{RoCell, SyncCell}, toml::{DeserializeOver, DeserializeOverWith}};
use yazi_tty::{TTY, sequence::SetSgr};
@ -28,9 +29,14 @@ fn try_init(merge: bool) -> anyhow::Result<()> {
let mut vfs = Preset::vfs()?;
if merge {
yazi = yazi.deserialize_over(&yazi::Yazi::read()?)?;
keymap = keymap.deserialize_over(&keymap::Keymap::read()?)?;
vfs = vfs.deserialize_over(&vfs::Vfs::read()?)?;
let (p, s) = yazi::Yazi::read()?;
yazi = yazi.deserialize_over(&s).with_context(|| format!("TOML parse error in {p:?}"))?;
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);
@ -56,16 +62,22 @@ pub fn build_flavor(light: bool, merge: bool) -> anyhow::Result<theme::Theme> {
let mut preset = Preset::theme(light)?;
if merge {
let theme_str = theme::Theme::read()?;
let theme = toml::de::DeTable::parse(&theme_str)?;
let (theme_p, theme_str) = theme::Theme::read()?;
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.deserialize_over_with(toml::de::Deserializer::from(theme)),
&theme_str,
)?;
)
.with_context(|| format!("TOML parse error in {theme_p:?}"))?;
}
preset.reshape(light)

View file

@ -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() {
"" => String::new(),
"" => (None, String::new()),
name => {
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)
}
})
}

View file

@ -40,10 +40,11 @@ pub struct Theme {
}
impl Theme {
pub(crate) fn read() -> Result<String> {
pub(crate) fn read() -> Result<(PathBuf, String)> {
let p = Xdg::config_dir().join("theme.toml");
ok_or_not_found(std::fs::read_to_string(&p))
.with_context(|| format!("Failed to read theme {p:?}"))
let s = ok_or_not_found(std::fs::read_to_string(&p))
.with_context(|| format!("Failed to read theme {p:?}"))?;
Ok((p, s))
}
// FIXME: remove

View file

@ -1,4 +1,4 @@
use std::io;
use std::{io, path::PathBuf};
use anyhow::{Context, Result};
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");
ok_or_not_found(std::fs::read_to_string(&p))
.with_context(|| format!("Failed to read config {p:?}"))
let s = ok_or_not_found(std::fs::read_to_string(&p))
.with_context(|| format!("Failed to read config {p:?}"))?;
Ok((p, s))
}
}

View file

@ -1,3 +1,5 @@
use std::path::PathBuf;
use anyhow::{Context, Result};
use serde::Deserialize;
use yazi_codegen::{DeserializeOver, DeserializeOver1};
@ -20,9 +22,10 @@ pub struct Yazi {
}
impl Yazi {
pub(super) fn read() -> Result<String> {
pub(super) fn read() -> Result<(PathBuf, String)> {
let p = Xdg::config_dir().join("yazi.toml");
ok_or_not_found(std::fs::read_to_string(&p))
.with_context(|| format!("Failed to read config {p:?}"))
let s = ok_or_not_found(std::fs::read_to_string(&p))
.with_context(|| format!("Failed to read config {p:?}"))?;
Ok((p, s))
}
}