edluffy / hologram.nvim

๐Ÿ‘ป A cross platform terminal image viewer for Neovim. Extensible and fast, written in Lua and C. Works on macOS and Linux.
MIT License
1.28k stars 31 forks source link

Examples in README does not works #16

Closed kawarimidoll closed 2 years ago

kawarimidoll commented 2 years ago

I tried examples in README, but they caused error and cannot process images.

example in Usage section, require('hologram').add_image(0, img_path, 0, 0) โ†’ E5108: Error executing lua [string ":lua"]:1: attempt to call field 'add_image' (a nil value)

example in image.lua API section, require('hologram.image'):new({ source = img_path, row = 0, col = 0, }) โ†’ E5113: Error while calling lua chunk: ...config/nvim/plugged/hologram.nvim/lua/hologram/image.lua:32: Image source is not a valid string

jotamudo commented 2 years ago

You should try doing require('hologram').setup() before executing the example code, it should work

kawarimidoll commented 2 years ago

You should try doing require('hologram').setup() before executing the example code, it should work

It still raises same error ๐Ÿ˜ข

็”ป้ขๅŽ้Œฒ 2022-08-11 7 56 09

In GIF above,

  1. start Neovim by this setting (using vim-plug):
    
    call plug#begin(stdpath('config') .. '/plugged')
    Plug 'edluffy/hologram.nvim'
    call plug#end()

lua require('hologram').setup({})


2. check `hologram.nvim` is loaded by `:PlugStatus`

3. run `require('hologram').add_image(0, '~/hologram-test/sample.png', 0, 0)`, then โ†“

E5108: Error executing lua [string ":lua"]:1: attempt to call field 'add_image' (a nil value) stack traceback: [string ":lua"]:1: in main chunk

OmeletWithoutEgg commented 2 years ago

The README document seems a little outdated (quite different from the main branch). Currently, the following code works for me.

function Test()
    local Image = require('hologram.image')
    local source = '/home/user/Pictures/unknown.png'
    local img = Image:new(source, {})
    local buf = vim.api.nvim_get_current_buf()
    img:display(1, 1, buf, {})
end

BTW the autocmd of automatic displaying images in a markdown file is working correctly, just add the auto_display = true option.

require('hologram').setup { auto_display = true }

You'll need to launch neovim in a terminal emulator like kitty, as the README mentioned that hologram.nvim only supports Kitty Graphics Protocol at present.

kawarimidoll commented 2 years ago

Thank you for detailed answer, but the code does not work for me... ๐Ÿ˜ญ

็”ป้ขๅŽ้Œฒ 2022-08-15 17 16 23

In GIF above,

  1. start Neovim by this setting (function HologramTest is from @OmeletWithoutEgg 's answer, sample.png is my icon):
    
    call plug#begin(stdpath('config') .. '/plugged')
    Plug 'edluffy/hologram.nvim'
    call plug#end()

lua << EOF require('hologram').setup({auto_display = true}) function HologramTest() local Image = require('hologram.image') local source = vim.fn.expand('~/hologram-test/sample.png') local img = Image:new(source, {}) local buf = vim.api.nvim_get_current_buf() img:display(1, 1, buf, {}) end EOF


2. run `:lua HologramTest()` โ†’ image is not displayed 
3. open markdown file that contains `![img](./sample.png)` โ†’ image is not displayed, cursor flickers after entered visual mode

I'm using:

โฏ kitty --version kitty 0.25.2 created by Kovid Goyal

โฏ nvim --version NVIM v0.8.0-dev-853-g9a3877ff9 Build type: Release LuaJIT 2.1.0-beta3 Compiled by kawarimidoll@kawarimidoll-mba

Features: +acl +iconv +tui See ":help feature-compile"

  ใ‚ทใ‚นใƒ†ใƒ  vimrc: "$VIM/sysinit.vim"
   ็œ็•ฅๆ™‚ใฎ $VIM: "/opt/homebrew/Cellar/neovim/HEAD-9a3877f_1/share/nvim"

Run :checkhealth for more info

edluffy commented 2 years ago

@OmeletWithoutEgg This is correct - after adding inline image display I must have forgotten to change the example in the README - I have updated the docs now.

@kawarimidoll If I am correct in thinking this is an issue with macOS (just tested using a mac now and it seems to be) then the latest commit should fix your problem.

kawarimidoll commented 2 years ago

@edluffy The latest example in README shows image but that is narrow than I expected.

image

source image is square โ†“ sample

edluffy commented 2 years ago

Image should be full size with latest commit now. Although there might still be some scaling issues when scrolling...

kawarimidoll commented 2 years ago

The problem is fixed, nice work ๐Ÿฅฐ Thank you!

SCR-20220816-iyd