Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Oct 11, 2023
1 parent ebe6714 commit 35f4c73
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 63 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions app/src/header/layout.rs

This file was deleted.

3 changes: 0 additions & 3 deletions app/src/header/mod.rs

This file was deleted.

2 changes: 0 additions & 2 deletions app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

mod app;
mod executor;
mod header;
mod help;
mod input;
mod logs;
mod manager;
mod root;
mod select;
mod signals;
mod status;
mod tasks;
mod which;

Expand Down
18 changes: 5 additions & 13 deletions app/src/manager/folder.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget};
use tracing::info;
use tracing::error;

pub(super) struct Folder {
kind: FolderKind,
}

pub(super) enum FolderKind {
pub(super) enum Folder {
Parent = 0,
Current = 1,
Preview = 2,
}

impl Folder {
pub(super) fn new(kind: FolderKind) -> Self { Self { kind } }
}

impl Widget for Folder {
fn render(self, area: Rect, buf: &mut Buffer) {
let x = plugin::Folder { kind: self.kind as u8 }.render(area, buf);
if x.is_err() {
info!("{:?}", x);
let folder = plugin::Folder { kind: self as u8 };
if let Err(e) = folder.render(area, buf) {
error!("{:?}", e);
}
}
}
6 changes: 3 additions & 3 deletions app/src/manager/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::Ctx;
use config::MANAGER;
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> {
cx: &'a Ctx,
Expand All @@ -30,12 +30,12 @@ impl<'a> Widget for Layout<'a> {
// Parent
let block = Block::new().borders(Borders::RIGHT).padding(Padding::new(1, 0, 0, 0));
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);

// Current
Folder::new(FolderKind::Current).render(chunks[1], buf);
Folder::Current.render(chunks[1], buf);

// Preview
let block = Block::new().borders(Borders::LEFT).padding(Padding::new(0, 1, 0, 0));
Expand Down
4 changes: 2 additions & 2 deletions app/src/manager/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::{manager::PreviewData, Ctx};
use ansi_to_tui::IntoText;
use ratatui::{buffer::Buffer, layout::Rect, widgets::{Paragraph, Widget}};

use super::{folder::FolderKind, Folder};
use super::Folder;

pub(super) struct Preview<'a> {
cx: &'a Ctx,
Expand All @@ -27,7 +27,7 @@ impl<'a> Widget for Preview<'a> {

match &preview.lock.as_ref().unwrap().data {
PreviewData::Folder => {
Folder::new(FolderKind::Preview).render(area, buf);
Folder::Preview.render(area, buf);
}
PreviewData::Text(s) => {
let p = Paragraph::new(s.as_bytes().into_text().unwrap());
Expand Down
11 changes: 8 additions & 3 deletions app/src/root.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use core::Ctx;

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;

pub(super) struct Root<'a> {
Expand All @@ -20,9 +21,13 @@ impl<'a> Widget for Root<'a> {
.constraints([Constraint::Length(1), Constraint::Min(0), Constraint::Length(1)])
.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);
status::Layout.render(chunks[2], buf);
if let Err(e) = plugin::Status.render(chunks[2], buf) {
error!("{:?}", e);
}

if self.cx.tasks.visible {
tasks::Layout::new(self.cx).render(area, buf);
Expand Down
14 changes: 0 additions & 14 deletions app/src/status/layout.rs

This file was deleted.

3 changes: 0 additions & 3 deletions app/src/status/mod.rs

This file was deleted.

3 changes: 2 additions & 1 deletion config/preset/theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ progress_normal = { fg = "#FFA577", bg = "#484D66" }
progress_error = { fg = "#FF84A9", bg = "#484D66" }

# Permissions
permissions_t = { fg = "#6D738F" }
permissions_t = { fg = "#97DC8D" }
permissions_r = { fg = "#F3D398" }
permissions_w = { fg = "#FA7F94" }
permissions_x = { fg = "#7AD9E5" }
permissions_s = { fg = "#6D738F" }

[files]
hovered = { fg = "#1E2031", bg = "#80AEFA" }
Expand Down
3 changes: 3 additions & 0 deletions config/preset/yazi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,8 @@ micro_workers = 5
macro_workers = 10
bizarre_retry = 5

[plugins]
preload = []

[log]
enabled = false
Empty file removed config/src/bindings.rs
Empty file.
6 changes: 4 additions & 2 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

use shared::RoCell;

mod bindings;
mod boot;
pub mod keymap;
mod log;
pub mod manager;
pub mod open;
mod pattern;
pub mod plugins;
mod preset;
pub mod preview;
pub mod tasks;
mod tasks;
pub mod theme;
mod validation;
mod xdg;
Expand All @@ -28,6 +28,7 @@ pub static KEYMAP: RoCell<keymap::Keymap> = RoCell::new();
pub static LOG: RoCell<log::Log> = RoCell::new();
pub static MANAGER: RoCell<manager::Manager> = 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 TASKS: RoCell<tasks::Tasks> = RoCell::new();
pub static THEME: RoCell<theme::Theme> = RoCell::new();
Expand All @@ -43,6 +44,7 @@ pub fn init() {
LOG.with(Default::default);
MANAGER.with(Default::default);
OPEN.with(Default::default);
PLUGINS.with(Default::default);
PREVIEW.with(Default::default);
TASKS.with(Default::default);
THEME.with(Default::default);
Expand Down
3 changes: 3 additions & 0 deletions config/src/plugins/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod plugins;

pub use plugins::*;
29 changes: 29 additions & 0 deletions config/src/plugins/plugins.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
1 change: 1 addition & 0 deletions config/src/theme/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct Status {
pub permissions_r: Style,
pub permissions_w: Style,
pub permissions_x: Style,
pub permissions_s: Style,
}

#[derive(Deserialize, Serialize)]
Expand Down
4 changes: 3 additions & 1 deletion plugin/preset/components/status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ function Status:permissions()
for i = 1, #h.permissions do
local c = h.permissions:sub(i, i)
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
elseif c == "w" then
style = THEME.status.permissions_w
Expand Down
15 changes: 12 additions & 3 deletions plugin/src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Result;
use config::PLUGINS;
use mlua::{Lua, Table};
use shared::RoCell;

Expand All @@ -8,13 +9,13 @@ pub(crate) static LUA: RoCell<Lua> = RoCell::new();
pub(crate) static GLOBALS: RoCell<Table> = RoCell::new();

pub fn init() {
fn inner() -> Result<()> {
fn stage_1() -> Result<()> {
let lua = Lua::new();

// Base
lua.load(include_str!("../preset/inspect/inspect.lua")).exec()?;
lua.load(include_str!("../preset/ui.lua")).exec()?;
lua.load(include_str!("../preset/utils.lua")).exec()?;
lua.load(include_str!("../preset/inspect/inspect.lua")).exec()?;

// Components
lua.load(include_str!("../preset/components/folder.lua")).exec()?;
Expand Down Expand Up @@ -44,5 +45,13 @@ pub fn init() {
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();
}
1 change: 1 addition & 0 deletions shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ futures = "^0"
libc = "^0"
parking_lot = "^0"
ratatui = "^0"
regex = "^1"
tokio = { version = "^1", features = [ "parking_lot", "macros", "rt-multi-thread", "sync", "time", "fs" ] }

0 comments on commit 35f4c73

Please sign in to comment.