feat: add full-border.yazi plugin

This commit is contained in:
sxyazi
2024-06-18 17:01:13 +08:00
parent ab370f0696
commit a3a0ddcb64
4 changed files with 82 additions and 0 deletions

21
full-border.yazi/LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 yazi-rs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,20 @@
# full-border.yazi
Add a full border to Yazi to make it look fancier.
## Installation
```sh
ya pack -a yazi-rs/plugins#full-border
```
## Usage
Add this to your `init.lua` to enable the plugin:
```lua
require("full-border"):setup()
```
This plugin overrides the [`Manager.render`](https://github.com/sxyazi/yazi/blob/latest/yazi-plugin/preset/components/manager.lua) method,
you might need to check if any other plugins that also need to override it are enabled.

32
full-border.yazi/init.lua Normal file
View File

@@ -0,0 +1,32 @@
local function setup()
Manager.render = function(self, area)
local chunks = self:layout(area)
local bar = function(c, x, y)
x, y = math.max(0, x), math.max(0, y)
return ui.Bar(ui.Rect { x = x, y = y, w = ya.clamp(0, area.w - x, 1), h = math.min(1, area.h) }, ui.Bar.TOP)
:symbol(c)
end
return ya.flat {
-- Borders
ui.Border(area, ui.Border.ALL):type(ui.Border.ROUNDED),
ui.Bar(chunks[1], ui.Bar.RIGHT),
ui.Bar(chunks[3], ui.Bar.LEFT),
bar("", chunks[1].right - 1, chunks[1].y),
bar("", chunks[1].right - 1, chunks[1].bottom - 1),
bar("", chunks[2].right, chunks[2].y),
bar("", chunks[2].right, chunks[1].bottom - 1),
-- Parent
Parent:render(chunks[1]:padding(ui.Padding.xy(1))),
-- Current
Current:render(chunks[2]:padding(ui.Padding.y(1))),
-- Preview
Preview:render(chunks[3]:padding(ui.Padding.xy(1))),
}
end
end
return { setup = setup }