refactoring

This commit is contained in:
Matt Nish-Lapidus 2025-03-21 16:50:54 -04:00
parent 74ae1150a3
commit 69400c1aa3
142 changed files with 11 additions and 70 deletions

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 dawsers
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,32 @@
# toggle-view.yazi
Toggle the different views: parent, current and preview.
## Requirements
- [Yazi](https://github.com/sxyazi/yazi/) v0.4 or later.
## Installation
```sh
ya pack -a dawsers/toggle-view
```
## Usage
Add this to your `~/.config/yazi/keymap.toml`:
``` toml
[manager]
prepend_keymap = [
{ on = "<C-1>", run = "plugin toggle-view --args=parent", desc = "Toggle parent" },
{ on = "<C-2>", run = "plugin toggle-view --args=current", desc = "Toggle current" },
{ on = "<C-3>", run = "plugin toggle-view --args=preview", desc = "Toggle preview" },
]
```
Now each key will toggle on/off one of the three panels: `Ctrl+1` for
*parent*, `Ctrl+2` for *current* and `Ctrl+3` for *preview*.
You can set your own key bindings.

View file

@ -0,0 +1,63 @@
--- @sync entry
-- Toggle different views on/off: parent, current, preview
local function entry(st, job)
local args = job.args or job
local action = args[1]
if not action then
return
end
if st.view == nil then
st.old_parent = MANAGER.ratio.parent
st.old_current = MANAGER.ratio.current
st.old_preview = MANAGER.ratio.preview
-- Get current tab ratios
local all_old = st.old_parent + st.old_current + st.old_preview
local area = ui.Rect { x= 0, y = 0, w = all_old, h = 10 }
local tab = Tab:new(area, cx.active)
st.parent = tab._chunks[1].w
st.current = tab._chunks[2].w
st.preview = tab._chunks[3].w
st.layout = Tab.layout
st.view = true -- initialized
end
if action == "parent" then
if st.parent > 0 then
st.parent = 0
else
st.parent = st.old_parent
end
elseif action == "current" then
if st.current > 0 then
st.current = 0
else
st.current = st.old_current
end
elseif action == "preview" then
if st.preview > 0 then
st.preview = 0
else
st.preview = st.old_preview
end
else
return
end
Tab.layout = function(self)
local all = st.parent + st.current + st.preview
self._chunks = ui.Layout()
:direction(ui.Layout.HORIZONTAL)
:constraints({
ui.Constraint.Ratio(st.parent, all),
ui.Constraint.Ratio(st.current, all),
ui.Constraint.Ratio(st.preview, all),
})
:split(self._area)
end
ya.app_emit("resize", {})
end
local function enabled(st) return st.view ~= nil end
return { entry = entry, enabled = enabled }