This commit is contained in:
sxyazi 2024-07-06 07:16:12 +08:00
parent 903336d4a2
commit 78bb28f9c7
No known key found for this signature in database
9 changed files with 37 additions and 54 deletions

View File

@ -122,7 +122,7 @@ previewers = [
]
[input]
cursor_blink = true
cursor_blink = false
# cd
cd_title = "Change directory:"

View File

@ -4,17 +4,16 @@ function Current:new(area, tab)
return setmetatable({
_area = area,
_tab = tab,
_folder = tab.current,
}, { __index = self })
end
function Current:empty()
local folder = Folder:by_kind(Folder.CURRENT)
local line
if folder.files.filter then
if self._folder.files.filter then
line = ui.Line("No filter results")
else
line = ui.Line(folder.stage == "loading" and "Loading..." or "No items")
line = ui.Line(self._folder.stage == "loading" and "Loading..." or "No items")
end
return {
@ -23,7 +22,7 @@ function Current:empty()
end
function Current:render()
local files = Folder:by_kind(Folder.CURRENT).window
local files = self._folder.window
if #files == 0 then
return self:empty()
end
@ -51,7 +50,7 @@ function Current:click(event, up)
return
end
local f = Folder:by_kind(Folder.CURRENT)
local f = self._folder
if event.y > #f.window or not f.hovered then
return
end

View File

@ -1,8 +1,4 @@
Folder = {
PARENT = 0,
CURRENT = 1,
PREVIEW = 2,
}
Folder = {}
function Folder:linemode(area, files)
local mode = cx.active.conf.linemode
@ -75,18 +71,3 @@ function Folder:markers(area, markers)
append(last)
return elements
end
function Folder:by_kind(kind)
if kind == self.PARENT then
return cx.active.parent
elseif kind == self.CURRENT then
return cx.active.current
elseif kind == self.PREVIEW then
return cx.active.preview.folder
end
end
function Folder:window(kind)
local folder = self:by_kind(kind)
return folder and folder.window
end

View File

@ -1,19 +1,20 @@
Header = {}
function Header:new(area)
function Header:new(area, tab)
return setmetatable({
_area = area,
_tab = tab,
}, { __index = self })
end
function Header:cwd(max)
local s = ya.readable_path(tostring(cx.active.current.cwd)) .. self:flags()
local s = ya.readable_path(tostring(self._tab.current.cwd)) .. self:flags()
return ui.Span(ya.truncate(s, { max = max, rtl = true })):style(THEME.manager.cwd)
end
function Header:flags()
local cwd = cx.active.current.cwd
local filter = cx.active.current.files.filter
local cwd = self._tab.current.cwd
local filter = self._tab.current.files.filter
local s = cwd.is_search and string.format(" (search: %s", cwd:frag()) or ""
if not filter then
@ -30,7 +31,7 @@ function Header:count()
local count, style
if yanked == 0 then
count = #cx.active.selected
count = #self._tab.selected
style = THEME.manager.count_selected
elseif cx.yanked.is_cut then
count = yanked

View File

@ -4,17 +4,17 @@ function Parent:new(area, tab)
return setmetatable({
_area = area,
_tab = tab,
_folder = tab.parent,
}, { __index = self })
end
function Parent:render()
local folder = Folder:by_kind(Folder.PARENT)
if not folder then
if not self._folder then
return {}
end
local items, markers = {}, {}
for i, f in ipairs(folder.window) do
for i, f in ipairs(self._folder.window) do
items[#items + 1] = ui.ListItem(File:children_render(f)):style(File:style(f))
-- Yanked/marked/selected files
@ -35,7 +35,7 @@ function Parent:click(event, up)
return
end
local window = Folder:window(Folder.PARENT) or {}
local window = self._folder and self._folder.window or {}
if window[event.y] then
ya.manager_emit("reveal", { window[event.y].url })
else

View File

@ -4,6 +4,7 @@ function Preview:new(area, tab)
return setmetatable({
_area = area,
_tab = tab,
_folder = tab.preview.folder,
}, { __index = self })
end
@ -14,7 +15,7 @@ function Preview:click(event, up)
return
end
local window = Folder:window(Folder.PREVIEW) or {}
local window = self._folder and self._folder.window or {}
if window[event.y] then
ya.manager_emit("reveal", { window[event.y].url })
else

View File

@ -14,12 +14,12 @@ function Root:layout(area)
end
function Root:render(area)
local chunks = self:layout(area)
local c = self:layout(area)
return ya.flat {
ya.eval("Header:render", Header.render, Header:new(chunks[1])) or {},
ya.eval("Tab:render", Tab.render, Tab:new(chunks[2], cx.active)) or {},
ya.eval("Status:render", Status.render, Status:new(chunks[3])) or {},
ya.eval("Header:render", Header.render, Header:new(c[1], cx.active)) or {},
ya.eval("Tab:render", Tab.render, Tab:new(c[2], cx.active)) or {},
ya.eval("Status:render", Status.render, Status:new(c[3], cx.active)) or {},
}
end

View File

@ -5,16 +5,17 @@ Status = {
_inc = 1000,
}
function Status:new(area)
function Status:new(area, tab)
return setmetatable({
_area = area,
_tab = tab,
}, { __index = self })
end
function Status:style()
if cx.active.mode.is_select then
if self._tab.mode.is_select then
return THEME.status.mode_select
elseif cx.active.mode.is_unset then
elseif self._tab.mode.is_unset then
return THEME.status.mode_unset
else
return THEME.status.mode_normal
@ -22,7 +23,7 @@ function Status:style()
end
function Status:mode()
local mode = tostring(cx.active.mode):upper()
local mode = tostring(self._tab.mode):upper()
if mode == "UNSET" then
mode = "UN-SET"
end
@ -35,7 +36,7 @@ function Status:mode()
end
function Status:size()
local h = cx.active.current.hovered
local h = self._tab.current.hovered
if not h then
return ui.Line {}
end
@ -48,7 +49,7 @@ function Status:size()
end
function Status:name()
local h = cx.active.current.hovered
local h = self._tab.current.hovered
if not h then
return ui.Line {}
end
@ -57,7 +58,7 @@ function Status:name()
end
function Status:permissions()
local h = cx.active.current.hovered
local h = self._tab.current.hovered
if not h then
return ui.Line {}
end
@ -87,8 +88,8 @@ end
function Status:percentage()
local percent = 0
local cursor = cx.active.current.cursor
local length = #cx.active.current.files
local cursor = self._tab.current.cursor
local length = #self._tab.current.files
if cursor ~= 0 and length ~= 0 then
percent = math.floor((cursor + 1) * 100 / length)
end
@ -109,8 +110,8 @@ function Status:percentage()
end
function Status:position()
local cursor = cx.active.current.cursor
local length = #cx.active.current.files
local cursor = self._tab.current.cursor
local length = #self._tab.current.files
local style = self:style()
return ui.Line {

View File

@ -1,7 +1,7 @@
local M = {}
function M:peek()
local folder = Folder:by_kind(Folder.PREVIEW)
local folder = cx.active.preview.folder
if not folder or folder.cwd ~= self.file.url then
return
end
@ -39,7 +39,7 @@ function M:peek()
end
function M:seek(units)
local folder = Folder:by_kind(Folder.PREVIEW)
local folder = cx.active.preview.folder
if folder and folder.cwd == self.file.url then
local step = math.floor(units * self.area.h / 10)
local bound = math.max(0, #folder.files - self.area.h)