Update: 2024-10-17

This commit is contained in:
2024-10-17 12:43:48 +03:00
parent eae6ecaebb
commit e2c877478c
68 changed files with 3579 additions and 1056 deletions

View File

@@ -6,39 +6,14 @@ https://github.com/dedukun/relative-motions.yazi/assets/25795432/04fb186a-5efe-4
## Requirements
- [Yazi](https://github.com/sxyazi/yazi) v0.2.4+
- [Yazi](https://github.com/sxyazi/yazi) v0.3.0+
## Installation
<details>
<summary>Yazi v0.2.5 and before (manual installation)</summary>
```sh
# Linux/macOS
git clone https://github.com/dedukun/relative-motions.yazi.git ~/.config/yazi/plugins/relative-motions.yazi
# Windows
git clone https://github.com/dedukun/relative-motions.yazi.git %AppData%\yazi\config\plugins\relative-motions.yazi
```
</details>
<details>
<summary>Latest commit in Yazi (package manager)</summary>
```sh
# Add the plugin
ya pack -a dedukun/relative-motions
# Install plugin
ya pack -i
# Update plugin
ya pack -u
```
</details>
## Configuration
If you want to use the numbers directly to start a motion add this to your `keymap.toml`:
@@ -122,10 +97,10 @@ require("relative-motions"):setup({ show_numbers="relative", show_motion = true
```
> [!NOTE]
> The `show_numbers` and `show_motion` functionalities overwrite [`Current:render`](https://github.com/sxyazi/yazi/blob/e51e8ad789914b2ab4a9485da7aa7fbc7b3bb450/yazi-plugin/preset/components/current.lua#L5)
> and [`Status:render`](https://github.com/sxyazi/yazi/blob/e51e8ad789914b2ab4a9485da7aa7fbc7b3bb450/yazi-plugin/preset/components/status.lua#L111) respectively.
> The `show_numbers` and `show_motion` functionalities overwrite [`Current:render`](https://github.com/sxyazi/yazi/blob/43b5ae0e6cc5c8ee96462651f01d78a0d98077fc/yazi-plugin/preset/components/current.lua#L26)
> and [`Status:children_render`](https://github.com/sxyazi/yazi/blob/43b5ae0e6cc5c8ee96462651f01d78a0d98077fc/yazi-plugin/preset/components/status.lua#L172) respectively.
> If you have custom implementations for any of this functions
> you can add the provided `File:number` and `Status:motion` to your implementations, just check [here](https://github.com/dedukun/relative-motions.yazi/blob/main/init.lua#L39) how we are doing things.
> you can add the provided `Entity:number` and `Status:motion` to your implementations, just check [here](https://github.com/dedukun/relative-motions.yazi/blob/main/init.lua#L126) how we are doing things.
## Usage

View File

@@ -34,22 +34,24 @@ local SHOW_NUMBERS_RELATIVE_ABSOLUTE = 2
----------------- R E N D E R -----------------
-----------------------------------------------
local render_motion_setup = ya.sync(function()
local render_motion_setup = ya.sync(function(_)
ya.render()
Status.motion = function() return ui.Span("") end
Status.render = function(self, area)
self.area = area
local left = ui.Line { self:mode(), self:size(), self:name() }
local right = ui.Line { self:motion(), self:permissions(), self:percentage(), self:position() }
return {
ui.Paragraph(area, { left }),
ui.Paragraph(area, { right }):align(ui.Paragraph.RIGHT),
table.unpack(Progress:render(area, right:width())),
}
Status.children_render = function(self, side)
local lines = {}
if side == self.RIGHT then
lines[1] = self:motion(self)
end
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
-- TODO: check why it doesn't work line this
-- Status:children_add(Status.motion, 100, Status.RIGHT)
end)
local render_motion = ya.sync(function(_, motion_num, motion_cmd)
@@ -60,7 +62,7 @@ local render_motion = ya.sync(function(_, motion_num, motion_cmd)
return ui.Span("")
end
local style = self.style()
local style = self:style()
local motion_span
if not motion_cmd then
@@ -81,7 +83,7 @@ end)
local render_numbers = ya.sync(function(_, mode)
ya.render()
File.number = function(_, index, file, hovered)
Entity.number = function(_, index, file, hovered)
local idx
if mode == SHOW_NUMBERS_RELATIVE then
idx = math.abs(hovered - index)
@@ -105,12 +107,10 @@ local render_numbers = ya.sync(function(_, mode)
end
end
Current.render = function(self, area)
self.area = area
local files = Folder:by_kind(Folder.CURRENT).window
Current.render = function(self)
local files = self._folder.window
if #files == 0 then
return self:empty(area)
return self:empty()
end
local hovered_index
@@ -121,22 +121,17 @@ local render_numbers = ya.sync(function(_, mode)
end
end
local items, markers = {}, {}
local entities, linemodes = {}, {}
for i, f in ipairs(files) do
items[#items + 1] = ui.ListItem(ui.Line(ya.flat { File:number(i, f, hovered_index), File:full(f) }))
:style(File:style(f))
linemodes[#linemodes + 1] = Linemode:new(f):render()
-- Yanked/marked/selected files
local marker = File:marker(f)
if marker ~= 0 then
markers[#markers + 1] = { i, marker }
end
local entity = Entity:new(f)
entities[#entities + 1] = ui.Line({ Entity:number(i, f, hovered_index), entity:render() }):style(entity:style())
end
return ya.flat {
ui.List(area, items),
Folder:linemode(area, files),
Folder:markers(area, markers),
return {
ui.List(entities):area(self._area),
ui.Text(linemodes):area(self._area):align(ui.Text.RIGHT),
}
end
end)