telescope-media-files.nvim icon indicating copy to clipboard operation
telescope-media-files.nvim copied to clipboard

[feature] Macos support.

Open singlexyz opened this issue 4 years ago • 20 comments

Überzug doesn't support MacOs, Then I found a Plugin: https://github.com/edluffy/hologram.nvim Maybe use its method to achieve image preview in Telescope.

115054101-c0848680-9ed7-11eb-9980-a3bc2d691fc2

singlexyz avatar Sep 26 '21 18:09 singlexyz

Any updates on this? I'd love to get this working on mac

protiumx avatar Dec 28 '21 00:12 protiumx

Any updates on this?

cpuccino avatar Dec 29 '21 14:12 cpuccino

Macos support +1.

AGou-ops avatar Jan 04 '22 02:01 AGou-ops

Hey guys! FYI, if anyone is looking for how to install ueberzug on macOS ... I found: creating or adding

[build_ext]
include_dirs=/opt/X11/include
library_dirs=/opt/X11/lib

to ~/.pydistutils.cfg as per this article, plus addtionally installing xquartz as downloadable on their website ... I finally am able to successfully install uberzug on my macOS Monterey v12.1 ... via pip3 install --user ueberzug

I'm not sure yet if that makes it work alltogether, I've only just successfully installed ueberzug ...

joehannes avatar Jan 30 '22 02:01 joehannes

Hey guys! FYI, if anyone is looking for how to install ueberzug on macOS ... I found: creating or adding

[build_ext]
include_dirs=/opt/X11/include
library_dirs=/opt/X11/lib

to ~/.pydistutils.cfg as per this article, plus addtionally installing xquartz as downloadable on their website ... I finally am able to successfully install uberzug on my macOS Monterey v12.1 ... via pip3 install --user ueberzug

I'm not sure yet if that makes it work alltogether, I've only just successfully installed ueberzug ...

so, after adapting this very plugin - which initially forcefully bails out on darwin/macOS (just deleting this portion of the plugin script) - and installing my fork in my nvim-cfg ... I found I didn't get the simple bailout msg ... but some error msg ...

image

If anyone has some knowledge of ueberzug and its usage, or if the author or somebody could have a look if this is fixable with reasonable efforts ... I'd love to use this plugin on my mac :-)

BTW, I'm using zsh and I found this to be a bash-script or so ... maybe the syntax error is to be overcome in a very few simple steps, but I lack knowledge and am out of time/energy ...

joehannes avatar Jan 30 '22 03:01 joehannes

please support macos

howarddo2208 avatar Jul 19 '22 16:07 howarddo2208

Does anyone have a high-level idea of what a solution for MacOS would look like? What are the current blockers?

Happy to collaborate and take a stab at it.

brodia10 avatar Jul 20 '22 22:07 brodia10

Would also be happy to lend a hand if people so desire, at this point I feel it might be easier to build a new Telescope extension from the ground up specifically for macos.

jswent avatar Jul 22 '22 15:07 jswent

What about using imgcat? we can display images in iterm2

jugarpeupv avatar Jul 23 '22 15:07 jugarpeupv

I feel like this is probably the best option. @jswent you want to start collaborating on this? I can start a slack channel or discord or something

brodia10 avatar Jul 23 '22 19:07 brodia10

What about using imgcat? we can display images in iterm2

imgcat looks awesome thanks. Probably a good starting point. I was able to get it working no problem on macOS with Alacritty terminal.

brodia10 avatar Jul 23 '22 20:07 brodia10

I found a way to use viu with this plugin. Here is the config I found

require("telescope").setup({
	defaults = {
		preview = {
			mime_hook = function(filepath, bufnr, opts)
				local is_image = function(filepath)
					local image_extensions = { "png", "jpg", "jpeg", "gif" } -- Supported image formats
					local split_path = vim.split(filepath:lower(), ".", { plain = true })
					local extension = split_path[#split_path]
					return vim.tbl_contains(image_extensions, extension)
				end
				if is_image(filepath) then
					local term = vim.api.nvim_open_term(bufnr, {})
					local function send_output(_, data, _)
						for _, d in ipairs(data) do
							vim.api.nvim_chan_send(term, d .. "\r\n")
						end
					end
					vim.fn.jobstart({
						"viu",
						filepath,
					}, {
						on_stdout = send_output,
						stdout_buffered = true,
					})
				else
					require("telescope.previewers.utils").set_preview_message(
						bufnr,
						opts.winid,
						"Binary cannot be previewed"
					)
				end
			end,
		},
	},
})
require("telescope").load_extension("media_files")

I use Alacritty and the image quality is pretty shit but at least I got a peek of what the images look like, maybe iterm2 and kitty would be better.

howarddo2208 avatar Aug 29 '22 05:08 howarddo2208

hey guys! Just saw this interesting option in the last comment by @howarddo2208 :-) It didn't work for me, as the media_files plugin didn't seem to pick up that hook and I didn't know where to go from there ...

So anyway, I found a way that might be of interest to other guys on MacOS or on any platform that supports the viu cli image viewer :-) And this time it's really easy ...

All one has to do, is tinker a bit with a fork of this repo and replace the line in the plugin where it calls the ueberzug script with a simple string viu ... that's it.

Basically like that:

M.media_preview = defaulter(function(opts)
  return previewers.new_termopen_previewer {
    get_command = function(entry)
      local tmp_table = vim.split(entry.value, "\t");
      local preview = opts.get_preview_window()
      opts.cwd = opts.cwd and vim.fn.expand(opts.cwd) or vim.loop.cwd()
      if vim.tbl_isempty(tmp_table) then
        return { "echo", "" }
      end
      return {
        'viu',
        string.format([[%s/%s]], opts.cwd, tmp_table[1]),
        preview.col,
        preview.line + 1,
        preview.width,
        preview.height
      }
    end
  }
end, {})

Also, I did fork that already, so, if you just wanna give it a shot if it works for you, you might want to temporarily try my unmaintained fork here: github.com/joehannes-os/telescope-media-files.nvim ...

Cheers 🥳

joehannes avatar Dec 31 '22 20:12 joehannes

ohh, and an example of what that looks like, also including my unfinished cleanup ... img

joehannes avatar Dec 31 '22 20:12 joehannes

@joehannes nice job, but you're a monster, use dark theme right now!

howarddo2208 avatar Jan 01 '23 04:01 howarddo2208

There is also a PR that replaces Ueberzug with viu https://github.com/nvim-telescope/telescope-media-files.nvim/pull/35

which looked pretty good, i only had one nit otherwise it would have been merged already

Conni2461 avatar Jan 01 '23 08:01 Conni2461

jep been working on this for a while. sad that I didn't see this comment before, Pull request has its kinks fixed now. should be good to merge.

Feel free to use it as a base-point for hologram or other better non pixelated solutions. My next stop after getting this merged is going to be svg preview

HendrikPetertje avatar Jan 02 '23 11:01 HendrikPetertje

I would love to see this feature merged. Wondering whether this issue could receive more attention if the title would be changed to me less generic. (@singlexyz)

quadruple-output avatar Aug 02 '23 11:08 quadruple-output

that pull request i mentioned was actually merged in. it switched out ueberzeug with "Chafa", which uses text symbols to draw pictures with extreme ascii art https://github.com/nvim-telescope/telescope-media-files.nvim/pull/35

HendrikPetertje avatar Aug 09 '23 06:08 HendrikPetertje

Any update on macos support?

MDSADABWASIM avatar May 06 '24 06:05 MDSADABWASIM