diff --git a/lua/hologram/image.lua b/lua/hologram/image.lua index 519e37e..8739a11 100644 --- a/lua/hologram/image.lua +++ b/lua/hologram/image.lua @@ -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, @@ -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 @@ -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 diff --git a/lua/hologram/init.lua b/lua/hologram/init.lua index 3697350..04226bc 100644 --- a/lua/hologram/init.lua +++ b/lua/hologram/init.lua @@ -3,7 +3,7 @@ local Job = require('hologram.job') local hologram = {} -config = require('hologram.config') +local config = require('hologram.config') local global_images = {} @@ -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 @@ -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},