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

Fix: misc fixes #6

Merged
merged 2 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions lua/hologram/image.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ end
function Image:transmit(opts)
opts = opts or {}
opts.medium = opts.medium or 'direct'
local set_case = opts.hide and string.lower or string.upper

local keys = {
i = self.id,
Expand All @@ -53,9 +54,9 @@ function Image:transmit(opts)
v = opts.height or nil,
s = opts.width or nil,
p = 1,
a = set_case('t'),
}

local set_case = opts.hide and string.lower or string.upper

local cmd, args
if vim.fn.executable('base64') == 1 then
Expand All @@ -75,16 +76,16 @@ function Image:transmit(opts)
cmd = cmd,
args = args,
on_data = function(data) -- arrives in 8192 size chunks
data = data:gsub('%s', ''):gsub('\n', '')
local chunks = {}
chunks[1] = data:sub(0, 4096):gsub('%s+', '')
chunks[2] = data:sub(4097, -1):gsub('%s+', '')
for i=1,#data, 4096 do
chunks[#chunks + 1] = data:sub(i, i + 4096 - 1):gsub('%s', '')
end

for _, chunk in ipairs(chunks) do
for i, chunk in ipairs(chunks) do
if #chunk > 0 then
keys.m = (#chunk < 4096) and 0 or 1
keys.q = 2 -- suppress responses
out[#out+1] = '\x1b_Ga='.. set_case('t')
.. ',' .. image.keys_to_str(keys) .. ';' .. chunk .. '\x1b\\'
out[#out+1] = '\x1b_G' .. image.keys_to_str(keys) .. ';' .. chunk .. '\x1b\\'
keys = {}
end
end
Expand Down
8 changes: 6 additions & 2 deletions lua/hologram/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local Job = require('hologram.job')

local hologram = {}

config = require('hologram.config')
local config = require('hologram.config')

local global_images = {}

Expand Down Expand Up @@ -38,7 +38,7 @@ end
-- Returns {top, bot, left, right} area of image that can be displayed.
-- nil if completely hidden
function hologram.check_region(img)
if not (img.height and img.width) then
if not img or not (img.height and img.width) then
return nil
end

Expand Down Expand Up @@ -89,6 +89,10 @@ function hologram.update_images(buf)
local img = hologram.get_image(buf, ext)
local rg = hologram.check_region(img)

if not img then
return
end

if rg then
img:adjust({
edge = {rg.left, rg.top},
Expand Down