Skip to content

Commit

Permalink
Merge pull request #1 from dharmx/fix-ueberzug
Browse files Browse the repository at this point in the history
feat: fixed #28
  • Loading branch information
dharmx authored Dec 27, 2022
2 parents ba396de + f88e30f commit c4916ad
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
27 changes: 18 additions & 9 deletions lua/telescope/_extensions/media_files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ local pickers = require("telescope.pickers")
local previewers = require("telescope.previewers")
local config = require("telescope.config")

local Job = require("plenary.job")
local defaulter = utils.make_default_callable
local action_state = require("telescope.actions.state")

Expand Down Expand Up @@ -45,22 +46,30 @@ end

local base_directory = ""

local PIDS = {}
local media_preview = defaulter(function(options)
return previewers.new_termopen_previewer({
get_command = function(entry)
local filepath = vim.trim(entry.value)
local preview = options.get_preview_window()
if filepath:len() == 0 then
return { "echo", "" }
return previewers.new({
preview_fn = function(self, entry, status)
for _, PID in pairs(PIDS) do
vim.loop.kill(PID, 9)
end
return {

local preview = options.get_preview_window()
local ueberzug = Job:new({
base_directory .. "/scripts/view.py",
filepath,
vim.trim(entry.value),
preview.col + options.geometry.x,
preview.line + options.geometry.y,
preview.width + options.geometry.width,
preview.height + options.geometry.height,
}
})
ueberzug:start()
table.insert(PIDS, ueberzug.pid)
end,
teardown = function(self)
for _, pid in pairs(PIDS) do
vim.loop.kill(pid, 9)
end
end,
})
end, {})
Expand Down
43 changes: 18 additions & 25 deletions scripts/view.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
#!/usr/bin/env python

import sys
import time
from sys import argv
from time import sleep

import ueberzug.lib.v0 as ueberzug
from ueberzug.lib.v0 import Canvas, ScalerOption, Visibility

if __name__ == "__main__":
with ueberzug.Canvas() as canvas:
path = sys.argv[1]
x = int(sys.argv[2])
y = int(sys.argv[3])
width = int(sys.argv[4])
height = int(sys.argv[5])
with Canvas() as canv:
place = canv.create_placement(
identifier="tele.media.files",
path=argv[1],
x=argv[2],
y=argv[3],
width=argv[4],
height=argv[5],
scaler=ScalerOption.CONTAIN.value,
visibility=Visibility.VISIBLE
)

placement = canvas.create_placement(
identifier="telescope-media-files.nvim",
width=width,
height=height,
x=x,
y=y,
scaler=ueberzug.ScalerOption.CONTAIN.value,
visibility=ueberzug.Visibility.VISIBLE,
path=path
)

while True:
with canvas.lazy_drawing:
pass
time.sleep(1)
while True:
with canv.lazy_drawing:
pass
sleep(1)

# vim:filetype=python

0 comments on commit c4916ad

Please sign in to comment.