feat: default config

This commit is contained in:
sxyazi 2023-07-18 00:34:58 +08:00
parent d798874492
commit 11c289229a
No known key found for this signature in database
13 changed files with 447 additions and 81 deletions

62
Cargo.lock generated
View File

@ -88,13 +88,13 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "axum"
version = "0.6.18"
version = "0.6.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8175979259124331c1d7bf6586ee7e0da434155e4b2d48ec2c8386281d8df39"
checksum = "a6a1de45611fdb535bfde7b7de4fd54f4fd2b17b1737c0a59b69bf9b92074b8c"
dependencies = [
"async-trait",
"axum-core",
"bitflags",
"bitflags 1.3.2",
"bytes",
"futures-util",
"http",
@ -179,6 +179,12 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42"
[[package]]
name = "bumpalo"
version = "3.13.0"
@ -348,7 +354,7 @@ version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a84cda67535339806297f1b331d6dd6320470d2a0fe65381e79ee9e156dd3d13"
dependencies = [
"bitflags",
"bitflags 1.3.2",
"crossterm_winapi",
"futures-core",
"libc",
@ -816,13 +822,19 @@ dependencies = [
"hashbrown 0.14.0",
]
[[package]]
name = "indoc"
version = "2.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c785eefb63ebd0e33416dfcb8d6da0bf27ce752843a45632a67bf10d4d4b5c4"
[[package]]
name = "inotify"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff"
dependencies = [
"bitflags",
"bitflags 1.3.2",
"inotify-sys",
"libc",
]
@ -885,7 +897,7 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8367585489f01bc55dd27404dcf56b95e6da061a256a666ab23be9ba96a2e587"
dependencies = [
"bitflags",
"bitflags 1.3.2",
"libc",
]
@ -1042,7 +1054,7 @@ version = "6.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5738a2795d57ea20abec2d6d76c6081186709c0024187cd5977265eda6598b51"
dependencies = [
"bitflags",
"bitflags 1.3.2",
"filetime",
"fsevent-sys",
"inotify",
@ -1133,7 +1145,7 @@ version = "6.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c4b31c8722ad9171c6d77d3557db078cab2bd50afcc9d09c8b315c59df8ca4f"
dependencies = [
"bitflags",
"bitflags 1.3.2",
"libc",
"once_cell",
"onig_sys",
@ -1178,6 +1190,12 @@ dependencies = [
"windows-targets 0.48.1",
]
[[package]]
name = "paste"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
[[package]]
name = "percent-encoding"
version = "2.3.0"
@ -1242,7 +1260,7 @@ version = "0.17.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59871cc5b6cce7eaccca5a802b4173377a1c2ba90654246789a8fa2334426d11"
dependencies = [
"bitflags",
"bitflags 1.3.2",
"crc32fast",
"fdeflate",
"flate2",
@ -1257,9 +1275,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
version = "1.0.65"
version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92de25114670a878b1261c79c9f8f729fb97e95bac93f6312f583c60dd6a1dfe"
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
dependencies = [
"unicode-ident",
]
@ -1316,9 +1334,9 @@ dependencies = [
[[package]]
name = "quote"
version = "1.0.30"
version = "1.0.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5907a1b7c277254a8b15170f6e7c97cfa60ee7872a3217663bb81151e48184bb"
checksum = "5fe8a65d69dd0808184ebb5f836ab526bb259db23c657efa38711b1072ee47f0"
dependencies = [
"proc-macro2",
]
@ -1355,13 +1373,15 @@ dependencies = [
[[package]]
name = "ratatui"
version = "0.21.0"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce841e0486e7c2412c3740168ede33adeba8e154a15107b879d8162d77c7174e"
checksum = "8285baa38bdc9f879d92c0e37cb562ef38aa3aeefca22b3200186bc39242d3d5"
dependencies = [
"bitflags",
"bitflags 2.3.3",
"cassowary",
"crossterm",
"indoc",
"paste",
"unicode-segmentation",
"unicode-width",
]
@ -1394,7 +1414,7 @@ version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [
"bitflags",
"bitflags 1.3.2",
]
[[package]]
@ -1403,7 +1423,7 @@ version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"
dependencies = [
"bitflags",
"bitflags 1.3.2",
]
[[package]]
@ -1485,9 +1505,9 @@ dependencies = [
[[package]]
name = "scopeguard"
version = "1.1.0"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "serde"
@ -1655,7 +1675,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6c454c27d9d7d9a84c7803aaa3c50cd088d2906fe3c6e42da3209aa623576a8"
dependencies = [
"bincode",
"bitflags",
"bitflags 1.3.2",
"flate2",
"fnv",
"lazy_static",

View File

@ -4,34 +4,34 @@ version = "0.1.0"
edition = "2021"
[dependencies]
ansi-to-tui = "3.0.0"
anyhow = "1.0.71"
async-channel = "1.8.0"
base64 = "0.21.2"
console-subscriber = "0.1.9"
crossterm = { version = "0.26.1", features = [ "event-stream" ] }
futures = "0.3.28"
glob = "0.3.1"
image = "0.24.6"
indexmap = "2.0.0"
libc = "0.2.146"
md5 = "0.7.0"
notify = { version = "6.0.1", default-features = false, features = [ "macos_fsevent" ] }
once_cell = "1.18.0"
parking_lot = "0.12.1"
ratatui = "0.21.0"
serde = { version = "1.0.164", features = [ "derive" ] }
serde_json = "1.0.103"
signal-hook-tokio = { version = "0.3.1", features = [ "futures-v0_3" ] }
syntect = "5.0.0"
tokio = { version = "1.28.2", features = [ "parking_lot", "macros", "rt-multi-thread", "sync", "fs", "process", "io-std", "io-util", "time" ] }
toml = "0.7.4"
tracing = "0.1.37"
tracing-appender = "0.2.2"
tracing-subscriber = "0.3.17"
trash = "3.0.3"
unicode-width = "0.1.10"
xdg = "2.5.0"
ansi-to-tui = "^3"
anyhow = "^1"
async-channel = "^1"
base64 = "^0"
console-subscriber = "^0"
crossterm = { version = "^0", features = [ "event-stream" ] }
futures = "^0"
glob = "^0"
image = "^0"
indexmap = "^2"
libc = "^0"
md5 = "^0"
notify = { version = "^6", default-features = false, features = [ "macos_fsevent" ] }
once_cell = "^1"
parking_lot = "^0"
ratatui = "^0"
serde = { version = "^1", features = [ "derive" ] }
serde_json = "^1"
signal-hook-tokio = { version = "^0", features = [ "futures-v0_3" ] }
syntect = "^5"
tokio = { version = "^1", features = [ "parking_lot", "macros", "rt-multi-thread", "sync", "fs", "process", "io-std", "io-util", "time" ] }
toml = "^0"
tracing = "^0"
tracing-appender = "^0"
tracing-subscriber = "^0"
trash = "^3"
unicode-width = "^0"
xdg = "^2"
# [profile.release]
# strip = true

View File

@ -42,7 +42,7 @@ cargo build --release
## TODO
- [ ] Add example config for general usage, currently please see my [another repo](https://github.com/sxyazi/dotfiles/tree/main/yazi) instead
- [x] Add example config for general usage, currently please see my [another repo](https://github.com/sxyazi/dotfiles/tree/main/yazi) instead
- [x] Integration with fzf, zoxide for fast directory navigation
- [x] Integration with fd, rg for fuzzy file searching
- [ ] Support for Überzug++ for image previews with X11/wayland environment

103
config/keymap.toml Normal file
View File

@ -0,0 +1,103 @@
[manager]
keymap = [
{ on = [ "<Esc>" ], exec = "escape" },
{ on = [ "q" ], exec = "quit" },
{ on = [ "<C-q>" ], exec = "close" },
# Navigation
{ on = [ "j" ], exec = "arrow 1" },
{ on = [ "k" ], exec = "arrow -1" },
{ on = [ "J" ], exec = "arrow 5" },
{ on = [ "K" ], exec = "arrow -5" },
{ on = [ "h" ], exec = "leave" },
{ on = [ "l" ], exec = "enter" },
{ on = [ "H" ], exec = "back" },
{ on = [ "L" ], exec = "forward" },
# Selection
{ on = [ "<Space>" ], exec = "select --state=none" },
{ on = [ "v" ], exec = "visual_mode" },
{ on = [ "V" ], exec = "visual_mode --unselect" },
{ on = [ "<C-a>" ], exec = "select_all --state=true" },
{ on = [ "<C-r>" ], exec = "select_all --state=none" },
# Operation
{ on = [ "y" ], exec = "yank" },
{ on = [ "x" ], exec = "yank --cut" },
{ on = [ "p" ], exec = "paste" },
{ on = [ "P" ], exec = "paste --force" },
{ on = [ "f" ], exec = "paste --follow" },
{ on = [ "F" ], exec = "paste --follow --force" },
{ on = [ "d" ], exec = "remove" },
{ on = [ "D" ], exec = "remove --permanently" },
{ on = [ "c" ], exec = "create" },
{ on = [ "r" ], exec = "rename" },
{ on = [ "." ], exec = "hidden toggle" },
{ on = [ "s" ], exec = "search fd" },
{ on = [ "S" ], exec = "search rg" },
{ on = [ "<C-s>" ], exec = "search none" },
{ on = [ "z" ], exec = "jump zoxide" },
{ on = [ "Z" ], exec = "jump fzf" },
# Tabs
{ on = [ "t" ], exec = "tab_create --current" },
{ on = [ "1" ], exec = "tab_switch 0" },
{ on = [ "2" ], exec = "tab_switch 1" },
{ on = [ "3" ], exec = "tab_switch 2" },
{ on = [ "4" ], exec = "tab_switch 3" },
{ on = [ "5" ], exec = "tab_switch 4" },
{ on = [ "[" ], exec = "tab_switch -1 --relative" },
{ on = [ "]" ], exec = "tab_switch 1 --relative" },
{ on = [ "{" ], exec = "tab_swap -1" },
{ on = [ "}" ], exec = "tab_swap 1" },
# Tasks
{ on = [ "w" ], exec = "tasks_show" },
]
[tasks]
keymap = [
{ on = [ "<Esc>" ], exec = "close" },
{ on = [ "w" ], exec = "close" },
{ on = [ "j" ], exec = "arrow 1" },
{ on = [ "k" ], exec = "arrow -1" },
{ on = [ "x" ], exec = "cancel" },
]
[input]
keymap = [
{ on = [ "<C-q>" ], exec = "close" },
{ on = [ "<Enter>" ], exec = "close --submit" },
{ on = [ "<Esc>" ], exec = "escape" },
{ on = [ "<Backspace>" ], exec = "backspace" },
# Mode
{ on = [ "i" ], exec = "insert" },
{ on = [ "a" ], exec = "insert --append" },
{ on = [ "v" ],exec = "visual" },
{ on = [ "h" ], exec = "move -1" },
{ on = [ "l" ], exec = "move 1" },
{ on = [ "H" ], exec = "move -999" },
{ on = [ "L" ], exec = "move 999" },
{ on = [ "b" ], exec = "backward" },
{ on = [ "w" ], exec = "forward" },
{ on = [ "e" ], exec = "forward --end-of-word" },
{ on = [ "d" ], exec = "delete" },
{ on = [ "c" ], exec = "delete --insert" },
{ on = [ "x" ], exec = [ "delete", "move 1" ] }
]

145
config/theme.toml Normal file
View File

@ -0,0 +1,145 @@
[tab]
active = { fg = "#1E2031", bg = "#80AEFA" }
inactive = { fg = "#C8D3F8", bg = "#484D66" }
[status]
primary = { normal = "#80AEFA", select = "#CD9EFC", unselect = "#FFA577" }
secondary = { normal = "#1E2031", select = "#23273B", unselect = "#23273B" }
tertiary = { normal = "#6D738F", select = "#6D738F", unselect = "#6D738F" }
body = { normal = "#484D66", select = "#484D66", unselect = "#484D66" }
emphasis = { normal = "#C8D3F8", select = "#C8D3F8", unselect = "#C8D3F8" }
info = { normal = "#7AD9E5", select = "#7AD9E5", unselect = "#7AD9E5" }
success = { normal = "#97DC8D", select = "#97DC8D", unselect = "#97DC8D" }
warning = { normal = "#F3D398", select = "#F3D398", unselect = "#F3D398" }
danger = { normal = "#FA7F94", select = "#FA7F94", unselect = "#FA7F94" }
[progress]
gauge = { fg = "#FFA577", bg = "#484D66" }
label = { fg = "#FFFFFF", bold = true }
[selection]
hovered = { fg = "#1E2031", bg = "#80AEFA" }
[marker]
selecting = { fg = "#97DC8D", bg = "#97DC8D" }
selected = { fg = "#F3D398", bg = "#F3D398" }
[preview]
hovered = { underline = true }
syntect_theme = "~/.config/bat/themes/Catppuccin-macchiato.tmTheme"
[filetype]
rules = [
# Images
{ mime = "image/*", fg = "#7AD9E5" },
# Videos
{ mime = "video/*", fg = "#F3D398" },
{ mime = "audio/*", fg = "#F3D398" },
# Archives
{ mime = "application/x-bzip", fg = "#CD9EFC" },
{ mime = "application/x-bzip2", fg = "#CD9EFC" },
{ mime = "application/gzip", fg = "#CD9EFC" },
{ mime = "application/vnd.rar", fg = "#CD9EFC" },
{ mime = "application/x-tar", fg = "#CD9EFC" },
{ mime = "application/zip", fg = "#CD9EFC" },
{ mime = "application/x-7z-compressed", fg = "#CD9EFC" },
# Fallback
{ name = "*", fg = "#C8D3F8" },
{ name = "*/", fg = "#80AEFA" }
]
[icons]
"Desktop/" = ""
"Documents/" = ""
"Downloads/" = ""
"Music/" = ""
"Pictures/" = ""
"Public/" = ""
"Videos/" = ""
".config/" = ""
# Git
".git/" = ""
".gitignore" = ""
".gitmodules" = ""
".gitattributes" = ""
# Dotfiles
".DS_Store" = ""
".bashrc" = ""
".bashprofile" = ""
".zshrc" = ""
".zshenv" = ""
".zprofile" = ""
".vimrc" = ""
# Text
"*.txt" = ""
"*.md" = ""
# Archives
"*.zip" = ""
"*.tar" = ""
"*.gz" = ""
"*.7z" = ""
# Audio
"*.mp3" = ""
"*.flac" = ""
"*.wav" = ""
# Movies
"*.mp4" = ""
"*.mkv" = ""
"*.avi" = ""
"*.mov" = ""
# Images
"*.jpg" = ""
"*.jpeg" = ""
"*.png" = ""
"*.gif" = ""
"*.webp" = ""
"*.avif" = ""
"*.bmp" = ""
"*.ico" = ""
"*.svg" = ""
# Programming
"*.c" = ""
"*.cpp" = ""
"*.h" = ""
"*.hpp" = ""
"*.rs" = ""
"*.go" = ""
"*.py" = ""
"*.js" = ""
"*.ts" = ""
"*.tsx" = ""
"*.jsx" = ""
"*.rb" = ""
"*.php" = ""
"*.java" = ""
"*.sh" = ""
"*.fish" = ""
"*.swift" = ""
"*.vim" = ""
"*.lua" = ""
"*.html" = ""
"*.css" = ""
"*.scss" = ""
"*.json" = ""
"*.toml" = ""
"*.yml" = ""
"*.yaml" = ""
"*.ini" = ""
"*.conf" = ""
# Default
"*" = ""
"*/" = ""

50
config/yazi.toml Normal file
View File

@ -0,0 +1,50 @@
[manager]
sort_by = "modified"
sort_reverse = true
show_hidden = false
[preview]
tab_size = 2
max_width = 600
max_height = 900
[opener]
archive = [
{ cmd = "unar", args = [ "$1" ] },
]
text = [
{ cmd = "vi", args = [ "$*" ], block = true },
]
image = [
{ cmd = "open", args = [ "$*" ] },
{ cmd = "exiftool", args = [ "$1" ], block = true },
]
video = [
{ cmd = "mpv", args = [ "$*" ] },
{ cmd = "mediainfo", args = [ "$1" ], block = true },
]
audio = [
{ cmd = "mpv", args = [ "$*" ] },
{ cmd = "mediainfo", args = [ "$1" ], block = true },
]
fallback = [
{ cmd = "open", args = [ "$*" ] },
]
[open]
rules = [
{ name = "*.html", use = "fallback" },
{ mime = "text/*", use = "text" },
{ mime = "image/*", use = "image" },
{ mime = "video/*", use = "video" },
{ mime = "audio/*", use = "audio" },
{ mime = "application/x-bzip", use = "archive" },
{ mime = "application/x-bzip2", use = "archive" },
{ mime = "application/gzip", use = "archive" },
{ mime = "application/vnd.rar", use = "archive" },
{ mime = "application/x-tar", use = "archive" },
{ mime = "application/zip", use = "archive" },
{ mime = "application/x-7z-compressed", use = "archive" },
]

View File

@ -1,9 +1,7 @@
use std::fs;
use serde::{Deserialize, Deserializer};
use xdg::BaseDirectories;
use super::{Exec, Key};
use crate::config::MERGED_KEYMAP;
#[derive(Debug, Deserialize)]
pub struct Single {
@ -45,8 +43,5 @@ impl<'de> Deserialize<'de> for Keymap {
}
impl Keymap {
pub fn new() -> Self {
let path = BaseDirectories::new().unwrap().get_config_file("yazi/keymap.toml");
toml::from_str(&fs::read_to_string(path).unwrap()).unwrap()
}
pub fn new() -> Self { toml::from_str(&MERGED_KEYMAP).unwrap() }
}

View File

@ -1,9 +1,9 @@
use std::{env, fs, path::PathBuf};
use serde::Deserialize;
use xdg::BaseDirectories;
use super::SortBy;
use crate::config::MERGED_YAZI;
#[derive(Debug, Deserialize)]
pub struct Manager {
@ -27,8 +27,7 @@ impl Manager {
manager: Manager,
}
let path = BaseDirectories::new().unwrap().get_config_file("yazi/yazi.toml");
let mut manager = toml::from_str::<Outer>(&fs::read_to_string(path).unwrap()).unwrap().manager;
let mut manager = toml::from_str::<Outer>(&MERGED_YAZI).unwrap().manager;
manager.cwd = env::current_dir().unwrap_or("/".into());
manager.cache = "/tmp/yazi".into();

View File

@ -4,10 +4,16 @@ pub mod keymap;
pub mod manager;
pub mod open;
mod pattern;
mod preset;
pub mod preview;
pub mod theme;
pub(crate) use pattern::*;
pub(crate) use preset::*;
static MERGED_KEYMAP: Lazy<String> = Lazy::new(|| Preset::keymap());
static MERGED_THEME: Lazy<String> = Lazy::new(|| Preset::theme());
static MERGED_YAZI: Lazy<String> = Lazy::new(|| Preset::yazi());
pub static KEYMAP: Lazy<keymap::Keymap> = Lazy::new(|| keymap::Keymap::new());
pub static MANAGER: Lazy<manager::Manager> = Lazy::new(|| manager::Manager::new());

View File

@ -1,10 +1,9 @@
use std::{collections::BTreeMap, fs, path::Path};
use std::{collections::BTreeMap, path::Path};
use serde::{Deserialize, Deserializer};
use xdg::BaseDirectories;
use super::Opener;
use crate::config::Pattern;
use crate::config::{Pattern, MERGED_YAZI};
#[derive(Debug)]
pub struct Open {
@ -21,10 +20,7 @@ struct OpenRule {
}
impl Open {
pub fn new() -> Self {
let path = BaseDirectories::new().unwrap().get_config_file("yazi/yazi.toml");
toml::from_str(&fs::read_to_string(path).unwrap()).unwrap()
}
pub fn new() -> Self { toml::from_str(&MERGED_YAZI).unwrap() }
pub fn opener(&self, path: &Path, mime: &str) -> Option<&Opener> {
self.rules.iter().find_map(|rule| {

57
src/config/preset.rs Normal file
View File

@ -0,0 +1,57 @@
use std::fs;
use toml::Table;
use xdg::BaseDirectories;
pub(crate) struct Preset;
impl Preset {
fn merge(a: &mut Table, b: &Table, max: u8) {
for (k, v) in b {
let a = if let Some(a) = a.get_mut(k) {
a
} else {
a.insert(k.clone(), v.clone());
continue;
};
if k == "icons" {
continue;
}
if max - 1 > 0 {
if let Some(b) = v.as_table() {
if let Some(a) = a.as_table_mut() {
Self::merge(a, b, max - 1);
continue;
}
}
}
*a = v.clone();
}
}
fn merge_str(base: &str, user: &str) -> String {
let path = BaseDirectories::new().unwrap().get_config_file(user);
let user = fs::read_to_string(path).unwrap_or("".to_string()).parse::<Table>().unwrap();
let mut base = base.parse::<Table>().unwrap();
Self::merge(&mut base, &user, 2);
base.to_string()
}
#[inline]
pub(crate) fn keymap() -> String {
Self::merge_str(include_str!("../../config/keymap.toml"), "yazi/keymap.toml")
}
#[inline]
pub(crate) fn theme() -> String {
Self::merge_str(include_str!("../../config/theme.toml"), "yazi/theme.toml")
}
#[inline]
pub(crate) fn yazi() -> String {
Self::merge_str(include_str!("../../config/yazi.toml"), "yazi/yazi.toml")
}
}

View File

@ -1,7 +1,6 @@
use std::fs;
use serde::Deserialize;
use xdg::BaseDirectories;
use crate::config::MERGED_YAZI;
#[derive(Debug, Deserialize)]
pub struct Preview {
@ -18,8 +17,7 @@ impl Preview {
preview: Preview,
}
let path = BaseDirectories::new().unwrap().get_config_file("yazi/yazi.toml");
let outer: Outer = toml::from_str(&fs::read_to_string(path).unwrap()).unwrap();
let outer: Outer = toml::from_str(&MERGED_YAZI).unwrap();
outer.preview
}
}

View File

@ -1,10 +1,9 @@
use std::{fs, path::PathBuf};
use std::path::PathBuf;
use serde::Deserialize;
use xdg::BaseDirectories;
use super::{ColorGroup, Filetype, Icon, Style};
use crate::misc::absolute_path;
use crate::{config::MERGED_THEME, misc::absolute_path};
#[derive(Deserialize)]
pub struct Tab {
@ -56,7 +55,7 @@ pub struct Theme {
pub selection: Selection,
pub marker: Marker,
pub preview: Preview,
#[serde(deserialize_with = "Filetype::deserialize")]
#[serde(rename = "filetype", deserialize_with = "Filetype::deserialize")]
pub filetypes: Vec<Filetype>,
#[serde(deserialize_with = "Icon::deserialize")]
pub icons: Vec<Icon>,
@ -64,10 +63,8 @@ pub struct Theme {
impl Theme {
pub fn new() -> Self {
let path = BaseDirectories::new().unwrap().get_config_file("yazi/theme.toml");
let mut parsed: Self = toml::from_str(&fs::read_to_string(path).unwrap()).unwrap();
parsed.preview.syntect_theme = absolute_path(&parsed.preview.syntect_theme);
parsed
let mut theme: Self = toml::from_str(&MERGED_THEME).unwrap();
theme.preview.syntect_theme = absolute_path(&theme.preview.syntect_theme);
theme
}
}