From 3783ea0feb98842c09bd6eb75c06f8ab814050e2 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Fri, 12 Jul 2024 21:36:17 +0800 Subject: [PATCH] feat: adapt to https://github.com/sxyazi/yazi/pull/1257 --- diff.yazi/README.md | 2 +- full-border.yazi/init.lua | 35 ++++++++++++++++++----------------- hide-preview.yazi/README.md | 2 +- hide-preview.yazi/init.lua | 12 +++++------- jump-to-char.yazi/README.md | 2 +- max-preview.yazi/README.md | 2 +- max-preview.yazi/init.lua | 12 +++++------- smart-filter.yazi/README.md | 2 +- 8 files changed, 33 insertions(+), 36 deletions(-) diff --git a/diff.yazi/README.md b/diff.yazi/README.md index e9bd8d2..cc21344 100644 --- a/diff.yazi/README.md +++ b/diff.yazi/README.md @@ -16,7 +16,7 @@ Add this to your `~/.config/yazi/keymap.toml`: ```toml [[manager.prepend_keymap]] -on = [ "" ] +on = "" run = "plugin diff" desc = "Diff the selected with the hovered file" ``` diff --git a/full-border.yazi/init.lua b/full-border.yazi/init.lua index 0597b9c..9c6cc5f 100644 --- a/full-border.yazi/init.lua +++ b/full-border.yazi/init.lua @@ -1,36 +1,37 @@ local function setup() - Manager.render = function(self, area) - local c = self:layout(area) + local old_build = Tab.build + Tab.build = function(self, ...) local bar = function(c, x, y) - if x <= 0 or x == area.w - 1 then - return {} + if x <= 0 or x == self._area.w - 1 then + return ui.Bar(ui.Rect.default, ui.Bar.TOP) end return ui.Bar( - ui.Rect { x = x, y = math.max(0, y), w = ya.clamp(0, area.w - x, 1), h = math.min(1, area.h) }, + ui.Rect { x = x, y = math.max(0, y), w = ya.clamp(0, self._area.w - x, 1), h = math.min(1, self._area.h) }, ui.Bar.TOP ):symbol(c) end + local c = self._chunks + self._chunks = { + c[1]:padding(ui.Padding.y(1)), + c[2]:padding(c[1].w > 0 and ui.Padding.y(1) or ui.Padding(1, 0, 1, 1)), + c[3]:padding(ui.Padding.y(1)), + } + local style = THEME.manager.border_style - return ya.flat { - -- Borders - ui.Border(area, ui.Border.ALL):type(ui.Border.ROUNDED):style(style), - ui.Bar(c[1]:padding(ui.Padding.y(1)), ui.Bar.RIGHT):style(style), - ui.Bar(c[3]:padding(ui.Padding.y(1)), ui.Bar.LEFT):style(style), + self._base = ya.list_merge(self._base or {}, { + ui.Border(self._area, ui.Border.ALL):type(ui.Border.ROUNDED):style(style), + ui.Bar(self._chunks[1], ui.Bar.RIGHT):style(style), + ui.Bar(self._chunks[3], ui.Bar.LEFT):style(style), bar("┬", c[1].right - 1, c[1].y), bar("┴", c[1].right - 1, c[1].bottom - 1), bar("┬", c[2].right, c[2].y), bar("┴", c[2].right, c[2].bottom - 1), + }) - -- Parent - Parent:render(c[1]:padding(ui.Padding.xy(1))), - -- Current - Current:render(c[2]:padding(c[1].w > 0 and ui.Padding.y(1) or ui.Padding(1, 0, 1, 1))), - -- Preview - Preview:render(c[3]:padding(ui.Padding.xy(1))), - } + old_build(self, ...) end end diff --git a/hide-preview.yazi/README.md b/hide-preview.yazi/README.md index ed8b7ac..999db11 100644 --- a/hide-preview.yazi/README.md +++ b/hide-preview.yazi/README.md @@ -16,7 +16,7 @@ Add this to your `~/.config/yazi/keymap.toml`: ```toml [[manager.prepend_keymap]] -on = [ "T" ] +on = "T" run = "plugin --sync hide-preview" desc = "Hide or show preview" ``` diff --git a/hide-preview.yazi/init.lua b/hide-preview.yazi/init.lua index 2644f34..5040321 100644 --- a/hide-preview.yazi/init.lua +++ b/hide-preview.yazi/init.lua @@ -1,20 +1,18 @@ local function entry(st) if st.old then - Manager.layout, st.old = st.old, nil + Tab.layout, st.old = st.old, nil else - st.old = Manager.layout - Manager.layout = function(self, area) - self.area = area - + st.old = Tab.layout + Tab.layout = function(self) local all = MANAGER.ratio.parent + MANAGER.ratio.current - return ui.Layout() + self._chunks = ui.Layout() :direction(ui.Layout.HORIZONTAL) :constraints({ ui.Constraint.Ratio(MANAGER.ratio.parent, all), ui.Constraint.Ratio(MANAGER.ratio.current, all), ui.Constraint.Length(1), }) - :split(area) + :split(self._area) end end ya.app_emit("resize", {}) diff --git a/jump-to-char.yazi/README.md b/jump-to-char.yazi/README.md index 62d3d9f..9f50f7a 100644 --- a/jump-to-char.yazi/README.md +++ b/jump-to-char.yazi/README.md @@ -16,7 +16,7 @@ Add this to your `~/.config/yazi/keymap.toml`: ```toml [[manager.prepend_keymap]] -on = [ "f" ] +on = "f" run = "plugin jump-to-char" desc = "Jump to char" ``` diff --git a/max-preview.yazi/README.md b/max-preview.yazi/README.md index 8766e64..ba11df1 100644 --- a/max-preview.yazi/README.md +++ b/max-preview.yazi/README.md @@ -16,7 +16,7 @@ Add this to your `~/.config/yazi/keymap.toml`: ```toml [[manager.prepend_keymap]] -on = [ "T" ] +on = "T" run = "plugin --sync max-preview" desc = "Maximize or restore preview" ``` diff --git a/max-preview.yazi/init.lua b/max-preview.yazi/init.lua index c324f8a..d3d6083 100644 --- a/max-preview.yazi/init.lua +++ b/max-preview.yazi/init.lua @@ -1,19 +1,17 @@ local function entry(st) if st.old then - Manager.layout, st.old = st.old, nil + Tab.layout, st.old = st.old, nil else - st.old = Manager.layout - Manager.layout = function(self, area) - self.area = area - - return ui.Layout() + st.old = Tab.layout + Tab.layout = function(self) + self._chunks = ui.Layout() :direction(ui.Layout.HORIZONTAL) :constraints({ ui.Constraint.Percentage(0), ui.Constraint.Percentage(0), ui.Constraint.Percentage(100), }) - :split(area) + :split(self._area) end end ya.app_emit("resize", {}) diff --git a/smart-filter.yazi/README.md b/smart-filter.yazi/README.md index 7424ca4..382852d 100644 --- a/smart-filter.yazi/README.md +++ b/smart-filter.yazi/README.md @@ -16,7 +16,7 @@ Add this to your `~/.config/yazi/keymap.toml`: ```toml [[manager.prepend_keymap]] -on = [ "F" ] +on = "F" run = "plugin smart-filter" desc = "Smart filter" ```