Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal for better rendering with unicode placeholders method #259

Open
HuntFeng opened this issue Dec 21, 2024 · 0 comments
Open

Proposal for better rendering with unicode placeholders method #259

HuntFeng opened this issue Dec 21, 2024 · 0 comments

Comments

@HuntFeng
Copy link

HuntFeng commented Dec 21, 2024

Thanks for the great work! This plugin benefits me a lot.

I noticed that you implemented the unicode placeholder method, but I'm not sure the implement here fully utilized the power of the unicode placeholder.

Instead of writing the unicode diacritics into tty (this creates flickering on my pc...), simply write them into neovim's buffer and then color their foreground with the hexcode of the image id.

local function render_image(image_id, x, y, width, height)
	local virt_lines = {}
	local hl_group = "image-nvim-image-id-" .. tostring(image_id)
        -- encode image_id into the foreground color
	vim.api.nvim_set_hl(0, hl_group, { fg = string.format("#%06X", image_id) })
	for i = 0, height - 1 do
		local line = ""
		for j = 0, width - 1 do
			line = line .. codes.placeholder .. codes.diacritics[i + 1] .. codes.diacritics[j + 1]
		end
		table.insert(virt_lines, { { line, hl_group } })
	end
        -- I put these diacritics into an extmark, you can try other ways too 
	vim.api.nvim_buf_set_extmark(0, ns_id, y, x, {
		virt_lines = virt_lines,
		virt_lines_above = false,
	})
end

With this slight change, we get a much better rendering.

Since unicode diacritics are just text, neovim can handle it well. This saves us tons of times

  • no need to crop the images when scrolling
  • no need to resize the images (kitty will fit the image into the rectangular diacritics)
  • no need to offset the images to avoid overlapping and other stuff
  • no need to clear and re-render images when switching windows/buffers (kitty handles this for us)

The only drawback is that other backends don't support unicode placeholders (yet).

unicode_placeholders.mp4

I wanted to create a PR for you, but it seems your code is structured for a more general use case (with support of other backends, love your efforts!) Maybe I will leave this headache to you.

Related issues:
#103
#123
#132
#116
#174
#245

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant