mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
29ae9e06dd
commit
f79ba67b53
5 changed files with 49 additions and 31 deletions
|
|
@ -1,17 +1,15 @@
|
||||||
Folder = {
|
Folder = {
|
||||||
Kind = {
|
PARENT = 0,
|
||||||
Parent = 0,
|
CURRENT = 1,
|
||||||
Current = 1,
|
PREVIEW = 2,
|
||||||
Preview = 2,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Folder:by_kind(kind)
|
function Folder:by_kind(kind)
|
||||||
if kind == self.Kind.Parent then
|
if kind == self.PARENT then
|
||||||
return cx.active.parent
|
return cx.active.parent
|
||||||
elseif kind == self.Kind.Current then
|
elseif kind == self.CURRENT then
|
||||||
return cx.active.current
|
return cx.active.current
|
||||||
elseif kind == self.Kind.Preview then
|
elseif kind == self.PREVIEW then
|
||||||
return cx.active.preview.folder
|
return cx.active.preview.folder
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -23,14 +21,14 @@ function Folder:markers(area, markers)
|
||||||
|
|
||||||
local elements = {}
|
local elements = {}
|
||||||
local append = function(last)
|
local append = function(last)
|
||||||
local p = ui.Paragraph(
|
local p = ui.Bar(
|
||||||
ui.Rect {
|
ui.Rect {
|
||||||
x = math.max(1, area.x) - 1,
|
x = math.max(1, area.x) - 1,
|
||||||
y = area.y + last[1] - 1,
|
y = area.y + last[1] - 1,
|
||||||
w = 1,
|
w = 1,
|
||||||
h = 1 + last[2] - last[1],
|
h = 1 + last[2] - last[1],
|
||||||
},
|
},
|
||||||
{}
|
ui.Position.LEFT
|
||||||
)
|
)
|
||||||
|
|
||||||
if last[3] == 1 then
|
if last[3] == 1 then
|
||||||
|
|
@ -86,7 +84,7 @@ function Folder:highlighted_name(file)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Folder:parent(area)
|
function Folder:parent(area)
|
||||||
local folder = self:by_kind(self.Kind.Parent)
|
local folder = self:by_kind(self.PARENT)
|
||||||
if folder == nil then
|
if folder == nil then
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|
@ -109,7 +107,7 @@ end
|
||||||
function Folder:current(area)
|
function Folder:current(area)
|
||||||
local markers = {}
|
local markers = {}
|
||||||
local items = {}
|
local items = {}
|
||||||
for i, f in ipairs(self:by_kind(self.Kind.Current).window) do
|
for i, f in ipairs(self:by_kind(self.CURRENT).window) do
|
||||||
local name = self:highlighted_name(f)
|
local name = self:highlighted_name(f)
|
||||||
|
|
||||||
-- Highlight hovered file
|
-- Highlight hovered file
|
||||||
|
|
@ -134,7 +132,7 @@ function Folder:current(area)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Folder:preview(area)
|
function Folder:preview(area)
|
||||||
local folder = self:by_kind(self.Kind.Preview)
|
local folder = self:by_kind(self.PREVIEW)
|
||||||
if folder == nil then
|
if folder == nil then
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|
@ -154,11 +152,11 @@ function Folder:preview(area)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Folder:render(area, args)
|
function Folder:render(area, args)
|
||||||
if args.kind == self.Kind.Parent then
|
if args.kind == self.PARENT then
|
||||||
return self:parent(area)
|
return self:parent(area)
|
||||||
elseif args.kind == self.Kind.Current then
|
elseif args.kind == self.CURRENT then
|
||||||
return self:current(area)
|
return self:current(area)
|
||||||
elseif args.kind == self.Kind.Preview then
|
elseif args.kind == self.PREVIEW then
|
||||||
return self:preview(area)
|
return self:preview(area)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,16 +10,16 @@ function Manager:render(area)
|
||||||
})
|
})
|
||||||
:split(area)
|
:split(area)
|
||||||
|
|
||||||
return {
|
return utils.flat {
|
||||||
-- Parent
|
|
||||||
table.unpack(Folder:render(chunks[1]:padding(ui.Padding.x(1)), { kind = Folder.Kind.Parent })),
|
|
||||||
-- Current
|
|
||||||
table.unpack(Folder:render(chunks[2], { kind = Folder.Kind.Current })),
|
|
||||||
-- Preview
|
|
||||||
ui.Base(chunks[3]:padding(ui.Padding.x(1)), "Preview"),
|
|
||||||
|
|
||||||
-- Borders
|
-- Borders
|
||||||
ui.Bar(chunks[1], ui.Position.RIGHT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style),
|
ui.Bar(chunks[1], ui.Position.RIGHT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style),
|
||||||
ui.Bar(chunks[3], ui.Position.LEFT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style),
|
ui.Bar(chunks[3], ui.Position.LEFT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style),
|
||||||
|
|
||||||
|
-- Parent
|
||||||
|
Folder:render(chunks[1]:padding(ui.Padding.x(1)), { kind = Folder.PARENT }),
|
||||||
|
-- Current
|
||||||
|
Folder:render(chunks[2], { kind = Folder.CURRENT }),
|
||||||
|
-- Preview
|
||||||
|
ui.Base(chunks[3]:padding(ui.Padding.x(1)), ui.Base.PREVIEW),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,11 @@ ui = {
|
||||||
LEFT = 4,
|
LEFT = 4,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Base = setmetatable({
|
||||||
|
PREVIEW = 0,
|
||||||
|
}, {
|
||||||
|
__call = function(_, ...) return ui.Base.new(...) end,
|
||||||
|
}),
|
||||||
Padding = setmetatable({
|
Padding = setmetatable({
|
||||||
left = function(left) return ui.Padding.new(left, 0, 0, 0) end,
|
left = function(left) return ui.Padding.new(left, 0, 0, 0) end,
|
||||||
right = function(right) return ui.Padding.new(0, right, 0, 0) end,
|
right = function(right) return ui.Padding.new(0, right, 0, 0) end,
|
||||||
|
|
@ -24,7 +29,7 @@ ui = {
|
||||||
x = function(x) return ui.Padding.new(x, x, 0, 0) end,
|
x = function(x) return ui.Padding.new(x, x, 0, 0) end,
|
||||||
y = function(y) return ui.Padding.new(0, 0, y, y) end,
|
y = function(y) return ui.Padding.new(0, 0, y, y) end,
|
||||||
}, {
|
}, {
|
||||||
__call = function(...) return ui.Padding.new(...) end,
|
__call = function(_, ...) return ui.Padding.new(...) end,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,19 @@
|
||||||
utils = utils or {}
|
utils = utils or {}
|
||||||
|
|
||||||
|
function utils.flat(t)
|
||||||
|
local r = {}
|
||||||
|
for _, v in ipairs(t) do
|
||||||
|
if type(v) == "table" then
|
||||||
|
for _, v2 in ipairs(utils.flat(v)) do
|
||||||
|
r[#r + 1] = v2
|
||||||
|
end
|
||||||
|
else
|
||||||
|
r[#r + 1] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return r
|
||||||
|
end
|
||||||
|
|
||||||
function utils.basename(str) return string.gsub(str, "(.*[/\\])(.*)", "%2") end
|
function utils.basename(str) return string.gsub(str, "(.*[/\\])(.*)", "%2") end
|
||||||
|
|
||||||
function utils.readable_size(size)
|
function utils.readable_size(size)
|
||||||
|
|
|
||||||
|
|
@ -7,21 +7,22 @@ use crate::{layout::Rect, GLOBALS, LUA};
|
||||||
pub struct Base {
|
pub struct Base {
|
||||||
area: ratatui::layout::Rect,
|
area: ratatui::layout::Rect,
|
||||||
|
|
||||||
name: String,
|
kind: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Base {
|
impl Base {
|
||||||
pub(crate) fn install() -> mlua::Result<()> {
|
pub(crate) fn install() -> mlua::Result<()> {
|
||||||
let ui: Table = GLOBALS.get("ui")?;
|
let ui: Table = GLOBALS.get("ui")?;
|
||||||
ui.set(
|
let base: Table = ui.get("Base")?;
|
||||||
"Base",
|
base.set(
|
||||||
LUA.create_function(|_, (area, name): (Rect, String)| Ok(Self { area: area.0, name }))?,
|
"new",
|
||||||
|
LUA.create_function(|_, (area, kind): (Rect, u8)| Ok(Self { area: area.0, kind }))?,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(self, cx: &core::Ctx, buf: &mut ratatui::buffer::Buffer) {
|
pub fn render(self, cx: &core::Ctx, buf: &mut ratatui::buffer::Buffer) {
|
||||||
match self.name.as_ref() {
|
match self.kind {
|
||||||
"Preview" => super::Preview::new(cx).render(self.area, buf),
|
0 => super::Preview::new(cx).render(self.area, buf),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue