diff --git a/yazi-plugin/preset/components/entity.lua b/yazi-plugin/preset/components/entity.lua index dd31c67e..2faada58 100644 --- a/yazi-plugin/preset/components/entity.lua +++ b/yazi-plugin/preset/components/entity.lua @@ -1,5 +1,12 @@ Entity = { _inc = 1000, + _children = { + { "icon", id = 1, order = 1000 }, + { "prefix", id = 2, order = 2000 }, + { "highlights", id = 3, order = 3000 }, + { "found", id = 4, order = 4000 }, + { "symlink", id = 5, order = 5000 }, + }, } function Entity:new(file) return setmetatable({ _file = file }, { __index = self }) end @@ -68,8 +75,8 @@ end function Entity:render() local lines = {} - for _, child in ipairs(self._children) do - lines[#lines + 1] = child[1](self) + for _, c in ipairs(self._children) do + lines[#lines + 1] = (type(c[1]) == "string" and self[c[1]] or c[1])(self) end return ui.Line(lines) end @@ -85,15 +92,7 @@ function Entity:style() end end --- Initialize children -Entity._children = { - { Entity.icon, id = 1, order = 1000 }, - { Entity.prefix, id = 2, order = 2000 }, - { Entity.highlights, id = 3, order = 3000 }, - { Entity.found, id = 4, order = 4000 }, - { Entity.symlink, id = 5, order = 5000 }, -} - +-- Children function Entity:children_add(fn, order) self._inc = self._inc + 1 self._children[#self._children + 1] = { fn, id = self._inc, order = order } diff --git a/yazi-plugin/preset/components/header.lua b/yazi-plugin/preset/components/header.lua index f24f08de..246c2ca9 100644 --- a/yazi-plugin/preset/components/header.lua +++ b/yazi-plugin/preset/components/header.lua @@ -4,6 +4,13 @@ Header = { _id = "header", _inc = 1000, + _left = { + { "cwd", id = 1, order = 1000 }, + }, + _right = { + { "count", id = 1, order = 1000 }, + { "tabs", id = 2, order = 2000 }, + }, } function Header:new(area, tab) @@ -101,15 +108,6 @@ function Header:scroll(event, step) end function Header:touch(event, step) end --- Initialize children -Header._left = { - { Header.cwd, id = 1, order = 1000 }, -} -Header._right = { - { Header.count, id = 1, order = 1000 }, - { Header.tabs, id = 2, order = 2000 }, -} - function Header:children_add(fn, order, side) self._inc = self._inc + 1 local children = side == self.RIGHT and self._right or self._left @@ -132,8 +130,8 @@ end function Header:children_render(side) local lines = {} - for _, child in ipairs(side == self.RIGHT and self._right or self._left) do - lines[#lines + 1] = child[1](self) + for _, c in ipairs(side == self.RIGHT and self._right or self._left) do + lines[#lines + 1] = (type(c[1]) == "string" and self[c[1]] or c[1])(self) end return ui.Line(lines) end diff --git a/yazi-plugin/preset/components/linemode.lua b/yazi-plugin/preset/components/linemode.lua index 1658d724..2a02a8c2 100644 --- a/yazi-plugin/preset/components/linemode.lua +++ b/yazi-plugin/preset/components/linemode.lua @@ -1,5 +1,8 @@ Linemode = { _inc = 1000, + _children = { + { "solo", id = 1, order = 1000 }, + }, } function Linemode:new(file) return setmetatable({ _file = file }, { __index = self }) end @@ -58,17 +61,13 @@ end function Linemode:render() local lines = {} - for _, child in ipairs(self._children) do - lines[#lines + 1] = child[1](self) + for _, c in ipairs(self._children) do + lines[#lines + 1] = (type(c[1]) == "string" and self[c[1]] or c[1])(self) end return ui.Line(lines) end --- Initialize children -Linemode._children = { - { Linemode.solo, id = 1, order = 1000 }, -} - +-- Children function Linemode:children_add(fn, order) self._inc = self._inc + 1 self._children[#self._children + 1] = { fn, id = self._inc, order = order } diff --git a/yazi-plugin/preset/components/status.lua b/yazi-plugin/preset/components/status.lua index c755f21e..71cb7889 100644 --- a/yazi-plugin/preset/components/status.lua +++ b/yazi-plugin/preset/components/status.lua @@ -4,6 +4,16 @@ Status = { _id = "status", _inc = 1000, + _left = { + { "mode", id = 1, order = 1000 }, + { "size", id = 2, order = 2000 }, + { "name", id = 3, order = 3000 }, + }, + _right = { + { "permissions", id = 4, order = 1000 }, + { "percentage", id = 5, order = 2000 }, + { "position", id = 6, order = 3000 }, + }, } function Status:new(area, tab) @@ -138,18 +148,7 @@ function Status:scroll(event, step) end function Status:touch(event, step) end --- Initialize children -Status._left = { - { Status.mode, id = 1, order = 1000 }, - { Status.size, id = 2, order = 2000 }, - { Status.name, id = 3, order = 3000 }, -} -Status._right = { - { Status.permissions, id = 4, order = 1000 }, - { Status.percentage, id = 5, order = 2000 }, - { Status.position, id = 6, order = 3000 }, -} - +-- Children function Status:children_add(fn, order, side) self._inc = self._inc + 1 local children = side == self.RIGHT and self._right or self._left @@ -172,8 +171,8 @@ end function Status:children_render(side) local lines = {} - for _, child in ipairs(side == self.RIGHT and self._right or self._left) do - lines[#lines + 1] = child[1](self) + for _, c in ipairs(side == self.RIGHT and self._right or self._left) do + lines[#lines + 1] = (type(c[1]) == "string" and self[c[1]] or c[1])(self) end return ui.Line(lines) end