diff --git a/yazi-plugin/preset/plugins/archive.lua b/yazi-plugin/preset/plugins/archive.lua index a199a9b7..93cd6325 100644 --- a/yazi-plugin/preset/plugins/archive.lua +++ b/yazi-plugin/preset/plugins/archive.lua @@ -6,12 +6,11 @@ function M:peek(job) local files, bound, code = self.list_files({ "-p", tostring(job.file.url) }, job.skip, limit) if code ~= 0 then - return ya.preview_widgets(job, { - ui.Text( - code == 2 and "File list in this archive is encrypted" - or "Failed to start both `7z` and `7zz`. Do you have 7-zip installed?" - ):area(job.area), - }) + return require("empty").msg( + job, + code == 2 and "File list in this archive is encrypted" + or "Failed to start both `7z` and `7zz`. Do you have 7-zip installed?" + ) end for _, f in ipairs(files) do diff --git a/yazi-plugin/preset/plugins/code.lua b/yazi-plugin/preset/plugins/code.lua index 6c4509d4..056ea458 100644 --- a/yazi-plugin/preset/plugins/code.lua +++ b/yazi-plugin/preset/plugins/code.lua @@ -5,9 +5,7 @@ function M:peek(job) if bound then ya.manager_emit("peek", { bound, only_if = job.file.url, upper_bound = true }) elseif err and not err:find("cancelled", 1, true) then - ya.preview_widgets(job, { - ui.Text(err):area(job.area):reverse(), - }) + require("empty").msg(job, err) end end diff --git a/yazi-plugin/preset/plugins/empty.lua b/yazi-plugin/preset/plugins/empty.lua index c797732f..fae655e8 100644 --- a/yazi-plugin/preset/plugins/empty.lua +++ b/yazi-plugin/preset/plugins/empty.lua @@ -1,11 +1,15 @@ local M = {} -function M:msg(job, s) ya.preview_widgets(job, { ui.Text(s):area(job.area):reverse():wrap(ui.Text.WRAP) }) end +function M.msg(job, s) + ya.preview_widgets(job, { + ui.Text(ui.Line(s):reverse()):area(job.area):wrap(ui.Text.WRAP), + }) +end function M:peek(job) local path = tostring(job.file.url) if path:sub(1, 6) ~= "/proc/" then - return self:msg(job, "Empty file") + return self.msg(job, "Empty file") end local limit = job.area.h @@ -22,7 +26,7 @@ function M:peek(job) end) if not ok then - self:msg(job, err) + self.msg(job, err) elseif job.skip > 0 and i < job.skip + limit then ya.manager_emit("peek", { math.max(0, i - limit), only_if = job.file.url, upper_bound = true }) else