From 3bd625a8af05c191dfddcbab03688d4d22fd6594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Sat, 7 Dec 2024 02:24:47 +0800 Subject: [PATCH] docs: add README for default configuration files (#2005) --- yazi-adapter/src/emulator.rs | 2 +- yazi-config/preset/README.md | 40 +++++++++++++++++++ .../{keymap.toml => keymap-default.toml} | 0 .../preset/{yazi.toml => yazi-default.toml} | 0 yazi-macro/src/asset.rs | 11 +++-- 5 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 yazi-config/preset/README.md rename yazi-config/preset/{keymap.toml => keymap-default.toml} (100%) rename yazi-config/preset/{yazi.toml => yazi-default.toml} (100%) diff --git a/yazi-adapter/src/emulator.rs b/yazi-adapter/src/emulator.rs index 1db370d21..faea3aa97 100644 --- a/yazi-adapter/src/emulator.rs +++ b/yazi-adapter/src/emulator.rs @@ -150,7 +150,7 @@ impl Emulator { } fn cell_size(resp: &str) -> Option<(u16, u16)> { - let b = resp.split_at(resp.find("\x1b[6;")? + 4).1.as_bytes(); + let b = resp.split_once("\x1b[6;")?.1.as_bytes(); let h: Vec<_> = b.iter().copied().take_while(|&c| c.is_ascii_digit()).collect(); b.get(h.len()).filter(|&&c| c == b';')?; diff --git a/yazi-config/preset/README.md b/yazi-config/preset/README.md new file mode 100644 index 000000000..93b742d30 --- /dev/null +++ b/yazi-config/preset/README.md @@ -0,0 +1,40 @@ +# Default Configuration + +> [!IMPORTANT] +> If you're using a stable release of Yazi instead of the latest nightly build, make sure you're checking these files from [the shipped tag][shipped], not the latest main branch. + +This directory contains the default configuration files for Yazi: + +- [`yazi-default.toml`][yazi-default]: General configuration +- [`keymap-default.toml`][keymap-default]: Keybindings configuration +- [`theme-dark.toml`][theme-dark]: Dark color scheme (loaded when your terminal is in dark mode) +- [`theme-light.toml`][theme-light]: Light color scheme (loaded when your terminal is in light mode) + +These files are already included with Yazi when you install the release, so you don't need to manually download or copy them to your Yazi configuration directory. + +However, if you want to customize certain configurations: + +- Create a `yazi.toml` in your config directory to override the settings in [`yazi-default.toml`][yazi-default], so either: + - `~/.config/yazi/yazi.toml` on Unix-like systems + - `C:\Users\USERNAME\AppData\Roaming\yazi\config\yazi.toml` on Windows +- Create a `keymap.toml` in your config directory to override the settings in [`keymap-default.toml`][keymap-default], so either: + - `~/.config/yazi/keymap.toml` on Unix-like systems + - `C:\Users\USERNAME\AppData\Roaming\yazi\config\keymap.toml` on Windows +- Create a `theme.toml` in your config directory to override the settings in [`theme-light.toml`][theme-light] and [`theme-dark.toml`][theme-dark], so either: + - `~/.config/yazi/theme.toml` on Unix-like systems + - `C:\Users\USERNAME\AppData\Roaming\yazi\config\theme.toml` on Windows + +For the user's `theme.toml` file, you can only apply the same color scheme to both the light and dark themes. + +If you want more granular control over colors, specify two different flavors for light and dark modes under the `[flavor]` section of your `theme.toml`, and override them in your respective flavor instead. + +[shipped]: https://github.com/sxyazi/yazi/tree/shipped +[yazi-default]: yazi-default.toml +[keymap-default]: keymap-default.toml +[theme-dark]: theme-dark.toml +[theme-light]: theme-light.toml + +## Learn more + +- [Configuration documentation](https://yazi-rs.github.io/docs/configuration/overview) +- [Flavors documentation](https://yazi-rs.github.io/docs/flavors/overview) diff --git a/yazi-config/preset/keymap.toml b/yazi-config/preset/keymap-default.toml similarity index 100% rename from yazi-config/preset/keymap.toml rename to yazi-config/preset/keymap-default.toml diff --git a/yazi-config/preset/yazi.toml b/yazi-config/preset/yazi-default.toml similarity index 100% rename from yazi-config/preset/yazi.toml rename to yazi-config/preset/yazi-default.toml diff --git a/yazi-macro/src/asset.rs b/yazi-macro/src/asset.rs index 6d5e1f7d4..4058f8bcc 100644 --- a/yazi-macro/src/asset.rs +++ b/yazi-macro/src/asset.rs @@ -4,8 +4,13 @@ macro_rules! config_preset { #[cfg(debug_assertions)] { std::borrow::Cow::from( - std::fs::read_to_string(concat!(env!("CARGO_MANIFEST_DIR"), "/preset/", $name, ".toml")) - .expect(concat!("Failed to read 'yazi-config/preset/", $name, ".toml'")), + std::fs::read_to_string(concat!( + env!("CARGO_MANIFEST_DIR"), + "/preset/", + $name, + "-default.toml" + )) + .expect(concat!("Failed to read 'yazi-config/preset/", $name, "-default.toml'")), ) } #[cfg(not(debug_assertions))] @@ -14,7 +19,7 @@ macro_rules! config_preset { env!("CARGO_MANIFEST_DIR"), "/preset/", $name, - ".toml" + "-default.toml" ))) } }};