Replies: 1 comment 2 replies
-
Preview only re-render when the content has actually changed, use
`ya.mgr_emit("peek", { force = true })` to force a preview re-render
…On Sat, Mar 1, 2025 at 1:07 PM PFiS ***@***.***> wrote:
What system are you running Yazi on?
Linux Wayland
What terminal are you running Yazi in?
kitty 0.39.1
yazi --debug output
Yazi
Version: 25.2.26 (Arch Linux 2025-02-27)
Debug : false
Triple : x86_64-unknown-linux-gnu (linux-x86_64)
Rustc : 1.85.0 (4d91de4e 2025-02-17)
Ya
Version: 25.2.26 (Arch Linux 2025-02-27)
Emulator
TERM : Some("xterm-kitty")
TERM_PROGRAM : None
TERM_PROGRAM_VERSION: None
Brand.from_env : Some(Kitty)
Emulator.detect : Emulator { kind: Left(Kitty), light: false, cell_size: Some((14, 31)) }
Adapter
Adapter.matches: Kgp
Desktop
XDG_SESSION_TYPE : Some("wayland")
WAYLAND_DISPLAY : Some("wayland-0")
DISPLAY : Some(":0")
SWAYSOCK : None
HYPRLAND_INSTANCE_SIGNATURE: None
WAYFIRE_SOCKET : None
SSH
shared.in_ssh_connection: false
WSL
WSL: false
Variables
SHELL : Some("/bin/fish")
EDITOR : Some("nvim")
VISUAL : None
YAZI_FILE_ONE : None
YAZI_CONFIG_HOME: None
YAZI_ZOXIDE_OPTS: None
FZF_DEFAULT_OPTS: Some("\n --ansi\n --reverse\n --height 60%\n --border rounded\n --info hidden\n --prompt \'\u{f002} \'\n --pointer \'\u{f054} \'\n --marker \'\u{f4a7} \'\n --bind \'ctrl-a:toggle-all\'\n --preview \'_fzf_preview {}\'\n\t--preview-window \'up,60%,border-bottom\' \n --color fg:-1\n --color fg+:-1\n --color bg:-1\n --color bg+:gray\n --color hl:red\n --color hl+:red\n --color info:blue\n --color prompt:cyan\n --color pointer:red\n --color marker:green\n --color spinner:green\n --color header:green\n --color gutter:-1")
Text Opener
default : Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
block-create: Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
block-rename: Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
Multiplexers
TMUX : false
tmux version : tmux 3.5a
tmux build flags : enable-sixel=Unknown
ZELLIJ_SESSION_NAME: None
Zellij version : 0.41.2
Dependencies
file : 5.46
ueberzugpp : No such file or directory (os error 2)
ffmpeg/ffprobe: 7.1 / 7.1
pdftoppm : 25.02.0
magick : 7.1.1-44
fzf : 0.60.2
fd/fdfind : 10.2.0 / No such file or directory (os error 2)
rg : 14.1.1
chafa : 1.14.5
zoxide : 0.9.7
7zz/7z : No such file or directory (os error 2) / 24.09
jq : 1.7.1
Clipboard
wl-copy/paste: 2.2.1 / 2.2.1
xclip : No such file or directory (os error 2)
xsel : No such file or directory (os error 2)
Describe the question
Note: my question is at the last line.
I have recently been working on yazi-rs/plugins#75
<yazi-rs/plugins#75>. After implementing the
intended feature, I wanted to enhance the user experience:
- allowing git status-based highlighting to be visible in the preview
and parent tab without having to enter a folder.
Here is my code (I will reintroduce the options and Windows support once
everything is completed):
*click to see all*
***@***.*** ***@***.*** disable: ***@***.*** disable: duplicate-set-field
local KINDS = {
ignored = 7,
untracked = 6,
added = 5,
renamed = 4,
modified = 3,
deleted = 2,
updated = 1,
unkonwn = 0,
}
local CHARS = {
{ "!$", KINDS.ignored },
{ "?$", KINDS.untracked },
{ "A", KINDS.added },
{ "[RC]", KINDS.renamed },
{ "[MT]", KINDS.modified },
{ "D", KINDS.deleted },
{ "U", KINDS.updated },
{ "[AD][AD]", KINDS.updated },
}
local STYLES = {
[KINDS.ignored] = { fg = "darkgray" },
[KINDS.untracked] = { fg = "magenta" },
[KINDS.added] = { fg = "green" },
[KINDS.renamed] = { fg = "yellow" },
[KINDS.modified] = { fg = "yellow" },
[KINDS.deleted] = { fg = "red" },
[KINDS.updated] = { fg = "yellow" },
}
local ICONS = {
[KINDS.ignored] = "",
[KINDS.untracked] = "?",
[KINDS.added] = "",
[KINDS.renamed] = "",
[KINDS.modified] = "",
[KINDS.deleted] = "",
[KINDS.updated] = "",
}
local function is_worktree(url)
local file, head = io.open(tostring(url)), nil
if file then
head = file:read(8)
file:close()
end
return head == "gitdir: "end
local function root(cwd)
cwd = Url(cwd)
repeat
local next = cwd:join(".git")
local cha = fs.cha(next)
if cha and (cha.is_dir or is_worktree(next)) then
return tostring(cwd)
end
cwd = cwd:parent()
until not cwdend
local function bubble_up(changed)
local new, empty = {}, Url("")
for path, kind in pairs(changed) do
if kind ~= KINDS.ignored then
local url = Url(path):parent()
while url and url ~= empty do
local s = tostring(url)
new[s] = (new[s] or KINDS.unkonwn) > kind and new[s] or kind
url = url:parent()
end
end
end
return newend
local function match(line)
local sign = line:sub(1, 2)
for _, p in ipairs(CHARS) do -- to keep the order
local char, kind = p[1], p[2]
local path
if sign:find(char) then
if kind == KINDS.renamed then
path = line:match("^.+-> (.+)$")
path = path:sub(1, 1) == '"' and path:sub(2, -2) or path
else
path = line:sub(4, 4) == '"' and line:sub(5, -2) or line:sub(4)
end
end
if path then
return kind, path:find("/$") and path:sub(1, -2) or path
end
endend
local add = ya.sync(function(st, cwd, repo, changes)
st.dirs_to_repo[cwd] = repo
if changes then
st.repos[repo] = st.repos[repo] or {}
for path, kind in pairs(changes) do
st.repos[repo][path] = kind
end
end
ya.render()end)
return {
setup = function(st)
st.dirs_to_repo = {}
st.repos = {}
local function get_kind(self)
local url = self._file.url
local repo = st.dirs_to_repo[tostring(url:parent())]
if repo then
local ret = st.repos[repo][tostring(url):sub(#repo + 2)]
if not ret then
local repo_url = Url(repo)
local path = url:parent()
while path and path ~= repo_url do
if st.repos[repo][tostring(path):sub(#repo + 2)] == KINDS.ignored then
return KINDS.ignored
end
path = path:parent()
end
else
return ret
end
end
end
function Linemode:git()
local kind = get_kind(self)
if not kind or ICONS[kind] == "" then
return ""
elseif self._file:is_hovered() then
return ui.Line({ " ", ICONS[kind] })
else
return ui.Line({ " ", ui.Span(ICONS[kind]):style(STYLES[kind]) })
end
end
Linemode:children_add("git", 1500)
local entity_icon = Entity.icon
function Entity:icon()
local kind = get_kind(self)
local icon = self._file:icon()
return kind == KINDS.ignored and icon.text .. " " or entity_icon(self)
end
local entity_style = Entity.style
function Entity:style()
local ret = ui.Style(entity_style(self))
local kind = get_kind(self)
if not kind then
return ret
else
return ret:patch(STYLES[kind])
end
end
end,
fetch = function(_, job)
local cwd = tostring(job.files[1].url:parent())
local repo = root(cwd)
if not repo then
return true
end
local output, err = Command("git")
:cwd(repo)
:args({
"status",
"--porcelain",
"-unormal",
"--ignored=matching",
})
:stdout(Command.PIPED)
:output()
if not output then
return true, Err("Cannot spawn `git` command, error: %s", err)
end
local changes = {}
for line in output.stdout:gmatch("[^\r\n]+") do
local kind, path = match(line)
changes[path] = kind
end
ya.dict_merge(changes, bubble_up(changes))
add(cwd, repo, changes)
for _, file in ipairs(job.files) do
if file.cha.is_dir then
add(tostring(file.url), repo)
end
end
if cwd ~= repo and cwd:find(repo) then
add(tostring(Url(cwd):parent()), repo)
end
return false
end,
}
Note the following code:
for _, file in ipairs(job.files) do
if file.cha.is_dir then
add(tostring(file.url), repo)
endend
if cwd ~= repo and cwd:sub(1, #repo) == repo then
add(tostring(Url(cwd):parent()), repo)end
This achieves the enhancement by adding both subfolders and the parent
folder of cwd to st.dirs_to_repo (formerly called st.dirs).
They work correctly in most cases, except when the first entry we open
yazi is a folder and it's involves this highlight. In this case, the
preview tab wouldn't have the highlight (moving the cursor or resize the
windows to make the preview tab to reload can resolve this issue).
Here is a video demonstrating this issue.
https://github.com/user-attachments/assets/541ba639-67f9-46de-b935-f53242cc3e7f
I have tried many methods but could not resolve this issue. *I would like
to ask how to truly redraw these tabs. Is it possible to achieve this with
the current plugin API?*
Anything else?
*No response*
Checklist
- I have read all the documentation
- I have searched the existing discussions/issues
—
Reply to this email directly, view it on GitHub
<#2419>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEFWFIHFZP64MMNTUKAQEKD2SE6AXAVCNFSM6AAAAABYDV4S5OVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZYGAZDOMJVGE>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
PFiS1737
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What system are you running Yazi on?
Linux Wayland
What terminal are you running Yazi in?
kitty 0.39.1
yazi --debug
outputDescribe the question
I have recently been working on yazi-rs/plugins#75. After implementing the intended feature, I wanted to enhance the user experience:
Here is my code (I will reintroduce the options and Windows support once everything is completed):
click to see all
Note the following code:
This achieves the enhancement by adding both subfolders and the parent folder of
cwd
tost.dirs_to_repo
(formerly calledst.dirs
).They work correctly in most cases, except when the first entry we open yazi is a folder and it's involves this highlight. In this case, the preview tab wouldn't have the highlight (moving the cursor or resize the windows to make the preview tab to reload can resolve this issue).
Here is a video demonstrating this issue.
default.mp4
I have tried many methods but could not resolve this issue. I would like to ask how to truly redraw these tabs. Is it possible to achieve this with the current plugin API?
Anything else?
No response
Checklist
Beta Was this translation helpful? Give feedback.
All reactions