mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
ebe6714ef6
commit
35f4c73ede
20 changed files with 77 additions and 63 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1649,6 +1649,7 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"ratatui",
|
"ratatui",
|
||||||
|
"regex",
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
use ratatui::{prelude::{Buffer, Rect}, widgets::Widget};
|
|
||||||
use tracing::info;
|
|
||||||
|
|
||||||
pub(crate) struct Layout;
|
|
||||||
|
|
||||||
impl Widget for Layout {
|
|
||||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
|
||||||
let x = plugin::Header.render(area, buf);
|
|
||||||
if x.is_err() {
|
|
||||||
info!("{:?}", x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
mod layout;
|
|
||||||
|
|
||||||
pub(super) use layout::*;
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
mod executor;
|
mod executor;
|
||||||
mod header;
|
|
||||||
mod help;
|
mod help;
|
||||||
mod input;
|
mod input;
|
||||||
mod logs;
|
mod logs;
|
||||||
|
|
@ -10,7 +9,6 @@ mod manager;
|
||||||
mod root;
|
mod root;
|
||||||
mod select;
|
mod select;
|
||||||
mod signals;
|
mod signals;
|
||||||
mod status;
|
|
||||||
mod tasks;
|
mod tasks;
|
||||||
mod which;
|
mod which;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,17 @@
|
||||||
use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget};
|
use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget};
|
||||||
use tracing::info;
|
use tracing::error;
|
||||||
|
|
||||||
pub(super) struct Folder {
|
pub(super) enum Folder {
|
||||||
kind: FolderKind,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(super) enum FolderKind {
|
|
||||||
Parent = 0,
|
Parent = 0,
|
||||||
Current = 1,
|
Current = 1,
|
||||||
Preview = 2,
|
Preview = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Folder {
|
|
||||||
pub(super) fn new(kind: FolderKind) -> Self { Self { kind } }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Widget for Folder {
|
impl Widget for Folder {
|
||||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||||
let x = plugin::Folder { kind: self.kind as u8 }.render(area, buf);
|
let folder = plugin::Folder { kind: self as u8 };
|
||||||
if x.is_err() {
|
if let Err(e) = folder.render(area, buf) {
|
||||||
info!("{:?}", x);
|
error!("{:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use core::Ctx;
|
||||||
use config::MANAGER;
|
use config::MANAGER;
|
||||||
use ratatui::{buffer::Buffer, layout::{self, Constraint, Direction, Rect}, widgets::{Block, Borders, Padding, Widget}};
|
use ratatui::{buffer::Buffer, layout::{self, Constraint, Direction, Rect}, widgets::{Block, Borders, Padding, Widget}};
|
||||||
|
|
||||||
use super::{folder::FolderKind, Folder, Preview};
|
use super::{Folder, Preview};
|
||||||
|
|
||||||
pub(crate) struct Layout<'a> {
|
pub(crate) struct Layout<'a> {
|
||||||
cx: &'a Ctx,
|
cx: &'a Ctx,
|
||||||
|
|
@ -30,12 +30,12 @@ impl<'a> Widget for Layout<'a> {
|
||||||
// Parent
|
// Parent
|
||||||
let block = Block::new().borders(Borders::RIGHT).padding(Padding::new(1, 0, 0, 0));
|
let block = Block::new().borders(Borders::RIGHT).padding(Padding::new(1, 0, 0, 0));
|
||||||
if manager.parent().is_some() {
|
if manager.parent().is_some() {
|
||||||
Folder::new(FolderKind::Parent).render(block.inner(chunks[0]), buf);
|
Folder::Parent.render(block.inner(chunks[0]), buf);
|
||||||
}
|
}
|
||||||
block.render(chunks[0], buf);
|
block.render(chunks[0], buf);
|
||||||
|
|
||||||
// Current
|
// Current
|
||||||
Folder::new(FolderKind::Current).render(chunks[1], buf);
|
Folder::Current.render(chunks[1], buf);
|
||||||
|
|
||||||
// Preview
|
// Preview
|
||||||
let block = Block::new().borders(Borders::LEFT).padding(Padding::new(0, 1, 0, 0));
|
let block = Block::new().borders(Borders::LEFT).padding(Padding::new(0, 1, 0, 0));
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use core::{manager::PreviewData, Ctx};
|
||||||
use ansi_to_tui::IntoText;
|
use ansi_to_tui::IntoText;
|
||||||
use ratatui::{buffer::Buffer, layout::Rect, widgets::{Paragraph, Widget}};
|
use ratatui::{buffer::Buffer, layout::Rect, widgets::{Paragraph, Widget}};
|
||||||
|
|
||||||
use super::{folder::FolderKind, Folder};
|
use super::Folder;
|
||||||
|
|
||||||
pub(super) struct Preview<'a> {
|
pub(super) struct Preview<'a> {
|
||||||
cx: &'a Ctx,
|
cx: &'a Ctx,
|
||||||
|
|
@ -27,7 +27,7 @@ impl<'a> Widget for Preview<'a> {
|
||||||
|
|
||||||
match &preview.lock.as_ref().unwrap().data {
|
match &preview.lock.as_ref().unwrap().data {
|
||||||
PreviewData::Folder => {
|
PreviewData::Folder => {
|
||||||
Folder::new(FolderKind::Preview).render(area, buf);
|
Folder::Preview.render(area, buf);
|
||||||
}
|
}
|
||||||
PreviewData::Text(s) => {
|
PreviewData::Text(s) => {
|
||||||
let p = Paragraph::new(s.as_bytes().into_text().unwrap());
|
let p = Paragraph::new(s.as_bytes().into_text().unwrap());
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
use core::Ctx;
|
use core::Ctx;
|
||||||
|
|
||||||
use ratatui::{buffer::Buffer, layout::{Constraint, Direction, Layout, Rect}, widgets::Widget};
|
use ratatui::{buffer::Buffer, layout::{Constraint, Direction, Layout, Rect}, widgets::Widget};
|
||||||
|
use tracing::error;
|
||||||
|
|
||||||
use super::{header, input, manager, select, status, tasks, which};
|
use super::{input, manager, select, tasks, which};
|
||||||
use crate::help;
|
use crate::help;
|
||||||
|
|
||||||
pub(super) struct Root<'a> {
|
pub(super) struct Root<'a> {
|
||||||
|
|
@ -20,9 +21,13 @@ impl<'a> Widget for Root<'a> {
|
||||||
.constraints([Constraint::Length(1), Constraint::Min(0), Constraint::Length(1)])
|
.constraints([Constraint::Length(1), Constraint::Min(0), Constraint::Length(1)])
|
||||||
.split(area);
|
.split(area);
|
||||||
|
|
||||||
header::Layout.render(chunks[0], buf);
|
if let Err(e) = plugin::Header.render(chunks[0], buf) {
|
||||||
|
error!("{:?}", e);
|
||||||
|
}
|
||||||
manager::Layout::new(self.cx).render(chunks[1], buf);
|
manager::Layout::new(self.cx).render(chunks[1], buf);
|
||||||
status::Layout.render(chunks[2], buf);
|
if let Err(e) = plugin::Status.render(chunks[2], buf) {
|
||||||
|
error!("{:?}", e);
|
||||||
|
}
|
||||||
|
|
||||||
if self.cx.tasks.visible {
|
if self.cx.tasks.visible {
|
||||||
tasks::Layout::new(self.cx).render(area, buf);
|
tasks::Layout::new(self.cx).render(area, buf);
|
||||||
|
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
use ratatui::{buffer::Buffer, prelude::Rect, widgets::Widget};
|
|
||||||
use tracing::info;
|
|
||||||
|
|
||||||
pub(crate) struct Layout;
|
|
||||||
|
|
||||||
impl Widget for Layout {
|
|
||||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
|
||||||
let x = plugin::Status.render(area, buf);
|
|
||||||
if x.is_err() {
|
|
||||||
info!("{:?}", x);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
mod layout;
|
|
||||||
|
|
||||||
pub(super) use layout::*;
|
|
||||||
|
|
@ -19,10 +19,11 @@ progress_normal = { fg = "#FFA577", bg = "#484D66" }
|
||||||
progress_error = { fg = "#FF84A9", bg = "#484D66" }
|
progress_error = { fg = "#FF84A9", bg = "#484D66" }
|
||||||
|
|
||||||
# Permissions
|
# Permissions
|
||||||
permissions_t = { fg = "#6D738F" }
|
permissions_t = { fg = "#97DC8D" }
|
||||||
permissions_r = { fg = "#F3D398" }
|
permissions_r = { fg = "#F3D398" }
|
||||||
permissions_w = { fg = "#FA7F94" }
|
permissions_w = { fg = "#FA7F94" }
|
||||||
permissions_x = { fg = "#7AD9E5" }
|
permissions_x = { fg = "#7AD9E5" }
|
||||||
|
permissions_s = { fg = "#6D738F" }
|
||||||
|
|
||||||
[files]
|
[files]
|
||||||
hovered = { fg = "#1E2031", bg = "#80AEFA" }
|
hovered = { fg = "#1E2031", bg = "#80AEFA" }
|
||||||
|
|
|
||||||
|
|
@ -70,5 +70,8 @@ micro_workers = 5
|
||||||
macro_workers = 10
|
macro_workers = 10
|
||||||
bizarre_retry = 5
|
bizarre_retry = 5
|
||||||
|
|
||||||
|
[plugins]
|
||||||
|
preload = []
|
||||||
|
|
||||||
[log]
|
[log]
|
||||||
enabled = false
|
enabled = false
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,16 @@
|
||||||
|
|
||||||
use shared::RoCell;
|
use shared::RoCell;
|
||||||
|
|
||||||
mod bindings;
|
|
||||||
mod boot;
|
mod boot;
|
||||||
pub mod keymap;
|
pub mod keymap;
|
||||||
mod log;
|
mod log;
|
||||||
pub mod manager;
|
pub mod manager;
|
||||||
pub mod open;
|
pub mod open;
|
||||||
mod pattern;
|
mod pattern;
|
||||||
|
pub mod plugins;
|
||||||
mod preset;
|
mod preset;
|
||||||
pub mod preview;
|
pub mod preview;
|
||||||
pub mod tasks;
|
mod tasks;
|
||||||
pub mod theme;
|
pub mod theme;
|
||||||
mod validation;
|
mod validation;
|
||||||
mod xdg;
|
mod xdg;
|
||||||
|
|
@ -28,6 +28,7 @@ pub static KEYMAP: RoCell<keymap::Keymap> = RoCell::new();
|
||||||
pub static LOG: RoCell<log::Log> = RoCell::new();
|
pub static LOG: RoCell<log::Log> = RoCell::new();
|
||||||
pub static MANAGER: RoCell<manager::Manager> = RoCell::new();
|
pub static MANAGER: RoCell<manager::Manager> = RoCell::new();
|
||||||
pub static OPEN: RoCell<open::Open> = RoCell::new();
|
pub static OPEN: RoCell<open::Open> = RoCell::new();
|
||||||
|
pub static PLUGINS: RoCell<plugins::Plugins> = RoCell::new();
|
||||||
pub static PREVIEW: RoCell<preview::Preview> = RoCell::new();
|
pub static PREVIEW: RoCell<preview::Preview> = RoCell::new();
|
||||||
pub static TASKS: RoCell<tasks::Tasks> = RoCell::new();
|
pub static TASKS: RoCell<tasks::Tasks> = RoCell::new();
|
||||||
pub static THEME: RoCell<theme::Theme> = RoCell::new();
|
pub static THEME: RoCell<theme::Theme> = RoCell::new();
|
||||||
|
|
@ -43,6 +44,7 @@ pub fn init() {
|
||||||
LOG.with(Default::default);
|
LOG.with(Default::default);
|
||||||
MANAGER.with(Default::default);
|
MANAGER.with(Default::default);
|
||||||
OPEN.with(Default::default);
|
OPEN.with(Default::default);
|
||||||
|
PLUGINS.with(Default::default);
|
||||||
PREVIEW.with(Default::default);
|
PREVIEW.with(Default::default);
|
||||||
TASKS.with(Default::default);
|
TASKS.with(Default::default);
|
||||||
THEME.with(Default::default);
|
THEME.with(Default::default);
|
||||||
|
|
|
||||||
3
config/src/plugins/mod.rs
Normal file
3
config/src/plugins/mod.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
mod plugins;
|
||||||
|
|
||||||
|
pub use plugins::*;
|
||||||
29
config/src/plugins/plugins.rs
Normal file
29
config/src/plugins/plugins.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use serde::Deserialize;
|
||||||
|
use shared::expand_path;
|
||||||
|
use validator::Validate;
|
||||||
|
|
||||||
|
use crate::MERGED_YAZI;
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Validate)]
|
||||||
|
pub struct Plugins {
|
||||||
|
pub preload: Vec<PathBuf>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Plugins {
|
||||||
|
fn default() -> Self {
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct Outer {
|
||||||
|
plugins: Plugins,
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut plugins = toml::from_str::<Outer>(&MERGED_YAZI).unwrap().plugins;
|
||||||
|
|
||||||
|
plugins.preload.iter_mut().for_each(|p| {
|
||||||
|
*p = expand_path(&p);
|
||||||
|
});
|
||||||
|
|
||||||
|
plugins
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -23,6 +23,7 @@ pub struct Status {
|
||||||
pub permissions_r: Style,
|
pub permissions_r: Style,
|
||||||
pub permissions_w: Style,
|
pub permissions_w: Style,
|
||||||
pub permissions_x: Style,
|
pub permissions_x: Style,
|
||||||
|
pub permissions_s: Style,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,9 @@ function Status:permissions()
|
||||||
for i = 1, #h.permissions do
|
for i = 1, #h.permissions do
|
||||||
local c = h.permissions:sub(i, i)
|
local c = h.permissions:sub(i, i)
|
||||||
local style = THEME.status.permissions_t
|
local style = THEME.status.permissions_t
|
||||||
if c == "r" then
|
if c == "-" then
|
||||||
|
style = THEME.status.permissions_s
|
||||||
|
elseif c == "r" then
|
||||||
style = THEME.status.permissions_r
|
style = THEME.status.permissions_r
|
||||||
elseif c == "w" then
|
elseif c == "w" then
|
||||||
style = THEME.status.permissions_w
|
style = THEME.status.permissions_w
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use config::PLUGINS;
|
||||||
use mlua::{Lua, Table};
|
use mlua::{Lua, Table};
|
||||||
use shared::RoCell;
|
use shared::RoCell;
|
||||||
|
|
||||||
|
|
@ -8,13 +9,13 @@ pub(crate) static LUA: RoCell<Lua> = RoCell::new();
|
||||||
pub(crate) static GLOBALS: RoCell<Table> = RoCell::new();
|
pub(crate) static GLOBALS: RoCell<Table> = RoCell::new();
|
||||||
|
|
||||||
pub fn init() {
|
pub fn init() {
|
||||||
fn inner() -> Result<()> {
|
fn stage_1() -> Result<()> {
|
||||||
let lua = Lua::new();
|
let lua = Lua::new();
|
||||||
|
|
||||||
// Base
|
// Base
|
||||||
|
lua.load(include_str!("../preset/inspect/inspect.lua")).exec()?;
|
||||||
lua.load(include_str!("../preset/ui.lua")).exec()?;
|
lua.load(include_str!("../preset/ui.lua")).exec()?;
|
||||||
lua.load(include_str!("../preset/utils.lua")).exec()?;
|
lua.load(include_str!("../preset/utils.lua")).exec()?;
|
||||||
lua.load(include_str!("../preset/inspect/inspect.lua")).exec()?;
|
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
lua.load(include_str!("../preset/components/folder.lua")).exec()?;
|
lua.load(include_str!("../preset/components/folder.lua")).exec()?;
|
||||||
|
|
@ -44,5 +45,13 @@ pub fn init() {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
inner().expect("failed to initialize Lua");
|
fn stage_2() {
|
||||||
|
PLUGINS.preload.iter().for_each(|p| {
|
||||||
|
let b = std::fs::read(p).unwrap_or_else(|_| panic!("failed to read plugin: {p:?}"));
|
||||||
|
LUA.load(&b).exec().unwrap_or_else(|_| panic!("failed to load plugin: {p:?}"));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
stage_1().expect("failed to initialize Lua");
|
||||||
|
stage_2();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,4 +10,5 @@ futures = "^0"
|
||||||
libc = "^0"
|
libc = "^0"
|
||||||
parking_lot = "^0"
|
parking_lot = "^0"
|
||||||
ratatui = "^0"
|
ratatui = "^0"
|
||||||
|
regex = "^1"
|
||||||
tokio = { version = "^1", features = [ "parking_lot", "macros", "rt-multi-thread", "sync", "time", "fs" ] }
|
tokio = { version = "^1", features = [ "parking_lot", "macros", "rt-multi-thread", "sync", "time", "fs" ] }
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue