Skip to content

Commit 096a37a

Browse files
committed
fix: address findings from 22-agent audit
- terminal.lua: Konsole detection changed from KONSOLE_VERSION (not an env var in modern Konsole) to KONSOLE_DBUS_SESSION, protocol changed from kitty to sixel (Konsole's kitty support is partial — no file transmission mode which image.nvim requires) - chafa.lua: ANSI escape stripping pattern expanded to include repeat- char sequence (\e[Nb) used on vte/ctx terminals - config.lua: added range clamping for zindex (>= 1), debounce_ms (>= 0), render_timeout_ms (>= 100), max_file_size_mb (> 0); added NaN/infinity/non-positive guard for chafa.max_output_bytes - renderer.lua: stabilized priority sort with name tiebreaker to ensure deterministic renderer selection when priorities are equal - preview.lua: replaced two vim.fn calls (line/col) with single vim.api.nvim_win_get_cursor() call in _create_anchor() - docs: added mini.files to README requirements and CHANGELOG - vimdoc: updated Konsole detection info in terminal table
1 parent 6eb2e56 commit 096a37a

8 files changed

Lines changed: 34 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- LRU render cache for instant re-hover
1010
- Content swap for flicker-free image browsing
1111
- image.nvim (pixel-perfect) and chafa (universal fallback) renderers
12-
- Neo-tree, nvim-tree, oil, snacks source adapters
12+
- Neo-tree, nvim-tree, oil, snacks, mini.files source adapters
1313
- Runtime toggle (:FocalEnable/:FocalDisable/:FocalToggle)
1414
- Manual preview (:FocalShow [path])
1515
- Configurable border, winblend, zindex, title

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ focal.nvim is an extensible preview framework with dual backends (pixel-perfect
3333
- **At least one rendering backend:**
3434
- [image.nvim](https://github.com/3rd/image.nvim) — pixel-perfect graphics (Kitty, WezTerm, Ghostty, iTerm2, foot, Konsole)
3535
- [chafa](https://hpjansson.org/chafa/) — universal Unicode/ANSI fallback (any terminal with 256-color or truecolor)
36-
- **A file explorer:** neo-tree, nvim-tree, oil.nvim, or snacks.nvim
36+
- **A file explorer:** neo-tree, nvim-tree, oil.nvim, snacks.nvim, or mini.files
3737

3838
## Installation
3939

doc/focal.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Terminals with graphics protocol support (image.nvim):
167167
Rio kitty TERM_PROGRAM
168168
iTerm2 sixel TERM_PROGRAM
169169
alacritty (none) ALACRITTY_SOCKET / TERM_PROGRAM
170-
Konsole kitty KONSOLE_VERSION
170+
Konsole sixel KONSOLE_DBUS_SESSION
171171
foot sixel TERM (prefix match)
172172
Windows Terminal sixel WT_SESSION
173173
Contour sixel TERMINAL_EMULATOR

lua/focal/config.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,21 @@ function M.merge(user_opts)
255255
if cfg.max_height_percent then
256256
cfg.max_height_percent = math.max(1, math.min(100, cfg.max_height_percent))
257257
end
258+
if cfg.zindex and cfg.zindex < 1 then
259+
warn("[focal] config.zindex must be >= 1, using default")
260+
cfg.zindex = M.defaults.zindex
261+
end
262+
if cfg.debounce_ms and cfg.debounce_ms < 0 then
263+
cfg.debounce_ms = 0
264+
end
265+
if cfg.render_timeout_ms and cfg.render_timeout_ms < 100 then
266+
warn("[focal] config.render_timeout_ms must be >= 100, using default")
267+
cfg.render_timeout_ms = M.defaults.render_timeout_ms
268+
end
269+
if cfg.max_file_size_mb and cfg.max_file_size_mb <= 0 then
270+
warn("[focal] config.max_file_size_mb must be > 0, using default")
271+
cfg.max_file_size_mb = M.defaults.max_file_size_mb
272+
end
258273

259274
-- Warn about unknown chafa sub-keys.
260275
if type(user_opts.chafa) == "table" then
@@ -292,6 +307,14 @@ function M.merge(user_opts)
292307
if type(cfg.chafa.max_output_bytes) ~= "number" then
293308
warn("[focal] config.chafa.max_output_bytes must be number, using default")
294309
cfg.chafa.max_output_bytes = M.defaults.chafa.max_output_bytes
310+
elseif
311+
cfg.chafa.max_output_bytes ~= cfg.chafa.max_output_bytes
312+
or cfg.chafa.max_output_bytes == math.huge
313+
or cfg.chafa.max_output_bytes == -math.huge
314+
or cfg.chafa.max_output_bytes <= 0
315+
then
316+
warn("[focal] config.chafa.max_output_bytes is invalid, using default")
317+
cfg.chafa.max_output_bytes = M.defaults.chafa.max_output_bytes
295318
end
296319
if cfg.chafa.color_space ~= nil and type(cfg.chafa.color_space) ~= "string" then
297320
warn("[focal] config.chafa.color_space must be string or nil, using default")

lua/focal/preview.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ end
7474
---Uses vim.fn.screenpos() which works for both splits and floating windows.
7575
---@return FocalCursorAnchor
7676
function PM:_create_anchor()
77-
local pos = vim.fn.screenpos(0, vim.fn.line("."), vim.fn.col("."))
77+
local cursor = vim.api.nvim_win_get_cursor(0)
78+
local pos = vim.fn.screenpos(0, cursor[1], cursor[2] + 1)
7879
return {
7980
screen_row = pos.row,
8081
screen_col = pos.col,

lua/focal/renderer.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ local function rebuild_ext_map()
3030
-- Sort each extension's renderer list by priority descending
3131
for _, list in pairs(ext_map) do
3232
table.sort(list, function(a, b)
33-
return a.priority > b.priority
33+
if a.priority ~= b.priority then
34+
return a.priority > b.priority
35+
end
36+
return a.name < b.name
3437
end)
3538
end
3639
end

lua/focal/renderers/chafa.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function M.render(ctx, done)
110110
if line_count <= 2 then
111111
-- Strip ANSI escape sequences to get visible character count.
112112
-- Each chafa "pixel" is one character wide.
113-
local visible = line:gsub("\27%[[%d;]*m", "")
113+
local visible = line:gsub("\27%[[%d;]*[mB]", "")
114114
local w = vim.fn.strdisplaywidth(visible)
115115
if w > max_visible_width then
116116
max_visible_width = w

lua/focal/terminal.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ local terminals = {
1717
{ env_key = "TERM_PROGRAM", value = "iTerm.app", terminal = "iTerm2", protocol = "sixel" },
1818
{ env_key = "ALACRITTY_SOCKET", terminal = "alacritty", protocol = nil },
1919
{ env_key = "TERM_PROGRAM", value = "Alacritty", terminal = "alacritty", protocol = nil },
20-
{ env_key = "KONSOLE_VERSION", terminal = "Konsole", protocol = "kitty" },
20+
{ env_key = "KONSOLE_DBUS_SESSION", terminal = "Konsole", protocol = "sixel" },
2121
{ env_key = "TERM", prefix = "foot", terminal = "foot", protocol = "sixel" },
2222
{ env_key = "WT_SESSION", terminal = "Windows Terminal", protocol = "sixel" },
2323
{ env_key = "TERM_PROGRAM", value = "rio", terminal = "Rio", protocol = "kitty" },

0 commit comments

Comments
 (0)