Skip to content

Commit

Permalink
Merge branch 'master' of github_3rd:3rd/image.nvim
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd committed Nov 1, 2023
2 parents 8ff8abc + 5bf877c commit ec91b89
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
16 changes: 13 additions & 3 deletions lua/image/backends/kitty/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ local write = function(data, tty, escape)

local payload = data
if escape and utils.tmux.is_tmux then payload = utils.tmux.escape(data) end

-- utils.debug("write:", vim.inspect(payload), tty)

if tty then
local handle = io.open(tty, "w")
if not handle then error("failed to open tty") end
Expand All @@ -37,6 +35,12 @@ local write = function(data, tty, escape)
end

local move_cursor = function(x, y, save)
if utils.tmux.is_tmux then
-- When tmux is running over ssh, set-cursor sometimes doesn't actually get sent
-- I don't know why this fixes the issue...
local cx = utils.tmux.get_cursor_x()
local cy = utils.tmux.get_cursor_y()
end
if save then write("\x1b[s") end
write("\x1b[" .. y .. ";" .. x .. "H")
vim.loop.sleep(1)
Expand Down Expand Up @@ -71,8 +75,14 @@ local write_graphics = function(config, data)
control_payload = control_payload:sub(0, -2)

if data then
if config.transmit_medium ~= codes.control.transmit_medium.direct then data = utils.base64.encode(data) end
if config.transmit_medium == codes.control.transmit_medium.direct then
local file = io.open(data,"rb")
data = file:read("*all")
end
data = utils.base64.encode(data):gsub("%-","/")
local chunks = get_chunked(data)
local m = #chunks > 1 and 1 or 0
control_payload = control_payload .. ",m=" .. m
for i = 1, #chunks do
write("\x1b_G" .. control_payload .. ";" .. chunks[i] .. "\x1b\\", config.tty, true)
if i == #chunks - 1 then
Expand Down
8 changes: 7 additions & 1 deletion lua/image/backends/kitty/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,20 @@ end

backend.render = function(image, x, y, width, height)
local with_virtual_placeholders = backend.state.options.kitty_method == "unicode-placeholders"
local is_SSH = (vim.env.SSH_CLIENT ~= nil) or (vim.env.SSH_TTY ~= nil)
if is_SSH then
current_medium = codes.control.transmit_medium.direct
else
current_medium = codes.control.transmit_medium.file
end

-- transmit image
local transmit = function()
helpers.write_graphics({
action = codes.control.action.transmit,
image_id = image.internal_id,
transmit_format = codes.control.transmit_format.png,
transmit_medium = codes.control.transmit_medium.file,
transmit_medium = current_medium,
display_cursor_policy = codes.control.display_cursor_policy.do_not_move,
display_virtual_placeholder = with_virtual_placeholders and 1 or 0,
quiet = 2,
Expand Down
2 changes: 2 additions & 0 deletions lua/image/utils/tmux.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ return {
get_pane_id = create_dm_getter("pane_id"),
get_pane_pid = create_dm_getter("pane_pid"),
get_pane_tty = create_dm_getter("pane_tty"),
get_cursor_x = create_dm_getter("cursor_x"),
get_cursor_y = create_dm_getter("cursor_y"),
escape = escape,
}

0 comments on commit ec91b89

Please sign in to comment.