[NeoVim] Display PNGs directly in floating windows
This commit is contained in:
@@ -32,8 +32,10 @@
|
|||||||
:nvim-telescope/telescope.nvim
|
:nvim-telescope/telescope.nvim
|
||||||
:kyazdani42/nvim-web-devicons
|
:kyazdani42/nvim-web-devicons
|
||||||
:MunifTanjim/nui.nvim
|
:MunifTanjim/nui.nvim
|
||||||
:s1n7ax/nvim-window-picker]
|
:s1n7ax/nvim-window-picker
|
||||||
:after [:nvim-window-picker]
|
:edluffy/hologram.nvim]
|
||||||
|
:after [:nvim-window-picker
|
||||||
|
:hologram.nvim]
|
||||||
:module :settings.neo-tree)
|
:module :settings.neo-tree)
|
||||||
|
|
||||||
(use! :mrjones2014/smart-splits.nvim
|
(use! :mrjones2014/smart-splits.nvim
|
||||||
|
|||||||
@@ -21,10 +21,34 @@
|
|||||||
:<S-Left> (fn [])}}
|
:<S-Left> (fn [])}}
|
||||||
:commands {:custom_open (fn [state]
|
:commands {:custom_open (fn [state]
|
||||||
(let [node (state.tree:get_node)
|
(let [node (state.tree:get_node)
|
||||||
quoted_path (.. "'" (.. (node:get_id) "'"))]
|
path (node:get_id)
|
||||||
(exec [[:silent "!file -bL --mime" quoted_path "| grep -qv '^text\\|^inode' && xdg-open" quoted_path "&"]])
|
quoted_path (.. "'" (.. path "'"))]
|
||||||
(if (= vim.v.shell_error 1)
|
(match (path:match "^.+%.(.+)$")
|
||||||
((. (require :neo-tree.sources.filesystem.commands) :open) state))))}}
|
"png" (let [bufnr (vim.api.nvim_create_buf false true)
|
||||||
|
image (: (require :hologram.image) :new path {})
|
||||||
|
max_width (- vim.o.columns 4)
|
||||||
|
max_height (- vim.o.lines 2)
|
||||||
|
tmp_width (math.min image.cols max_width)
|
||||||
|
tmp_height (* image.rows (/ tmp_width image.cols))
|
||||||
|
height (math.min tmp_height max_height)
|
||||||
|
width (* image.cols (/ height image.rows))
|
||||||
|
winnr (vim.api.nvim_open_win bufnr true {:relative "editor"
|
||||||
|
:width (math.ceil width)
|
||||||
|
:height (+ (math.ceil height) 1)
|
||||||
|
:row 0
|
||||||
|
:col 2})]
|
||||||
|
(exec [[:setlocal "nonumber"]])
|
||||||
|
(vim.api.nvim_buf_attach bufnr false {:on_detach (fn [_ bufnr]
|
||||||
|
(image:delete bufnr {:free true}))})
|
||||||
|
(image:display 1 0 bufnr {}))
|
||||||
|
_ (do
|
||||||
|
(exec [[:silent
|
||||||
|
"!file -bL --mime" quoted_path
|
||||||
|
"| grep -qv '^text\\|^inode' "
|
||||||
|
"&& xdg-open" quoted_path
|
||||||
|
"&"]])
|
||||||
|
(if (= vim.v.shell_error 1)
|
||||||
|
((. (require :neo-tree.sources.filesystem.commands) :open) state))))))}}
|
||||||
:renderers {:directory [[:indent]
|
:renderers {:directory [[:indent]
|
||||||
[:icon]
|
[:icon]
|
||||||
[:current_filter]
|
[:current_filter]
|
||||||
|
|||||||
Reference in New Issue
Block a user