Skip to content

Commit

Permalink
Merge pull request #6 from tzachar/main
Browse files Browse the repository at this point in the history
Fix: misc fixes
  • Loading branch information
edluffy authored Nov 12, 2021
2 parents 5598fea + 83060a3 commit 7cd1db7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
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

0 comments on commit 7cd1db7

Please sign in to comment.