lucc / nvimpager

Use nvim as a pager to view manpages, diffs, etc with nvim's syntax highlighting

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`cat` mode stopped colorising syntax

kaliberr44 opened this issue · comments

I'm pretty sure it worked before, but right now cat mode is not colorising output (neither nvimpager "$1").
nvimpager -p "$1" works correctly with all the syntax colouring.

❯ uname -a
Darwin kaliberr44-mbp.private.net 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000 arm64 arm Darwin

❯ nvimpager -v                                               
nvimpager 0.13.0

❯ nvim -v                                               
NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1716656478

nvimpager config:

-- This file is automatically loaded by plugins.core
vim.g.mapleader = " "
vim.g.maplocalleader = "\\"

vim.opt.clipboard = vim.env.SSH_TTY and "" or "unnamedplus" -- Sync with system clipboard
vim.opt.number = true -- Make line numbers default
-- Case-insensitive searching UNLESS \C or one or more capital letters in the search term
vim.opt.ignorecase = true
vim.opt.smartcase = true
vim.opt.termguicolors = true

vim.opt.shiftround = true -- Round indent
vim.opt.shiftwidth = 2 -- Size of an indent
vim.opt.tabstop = 2 -- Number of spaces tabs count for
vim.opt.scrolloff = 4 -- Lines of context
vim.opt.sidescrolloff = 8 -- Columns of context
vim.opt.linebreak = true -- Wrap lines at convenient points
vim.opt.laststatus = 3 -- global statusline
vim.opt.showmode = false -- Dont show mode since we have a statusline
vim.opt.showcmd = false -- Dont show command or size of selected area

vim.opt.runtimepath:append(",~/.local/share/nvim/lazy/github-nvim-theme")
vim.cmd("colorscheme github_dark_dimmed")

Sample file for syntax color check:

local M = {}

function M:peek()
	local child = Command("nvimpager")
		:args({
			"-c",
			tostring(self.file.url),
		})
		:stdout(Command.PIPED)
		:stderr(Command.PIPED)
		:spawn()

	if not child then
		return self:fallback_to_builtin()
	end

	local limit = self.area.h
	local i, lines = 0, ""
	repeat
		local next, event = child:read_line()
		if event == 1 then
			return self:fallback_to_builtin()
		elseif event ~= 0 then
			break
		end

		i = i + 1
		if i > self.skip then
			lines = lines .. next
		end
	until i >= self.skip + limit

	child:start_kill()
	if self.skip > 0 and i < self.skip + limit then
		ya.manager_emit("peek", { math.max(0, i - limit), only_if = self.file.url, upper_bound = true })
	else
		lines = lines:gsub("\t", string.rep(" ", PREVIEW.tab_size))
		ya.preview_widgets(self, { ui.Paragraph.parse(self.area, lines) })
	end
end

function M:seek(units)
	local h = cx.active.current.hovered
	if h and h.url == self.file.url then
		local step = math.floor(units * self.area.h / 10)
		ya.manager_emit("peek", {
			math.max(0, cx.active.preview.skip + step),
			only_if = self.file.url,
		})
	end
end

function M:fallback_to_builtin()
	local _, bound = ya.preview_code(self)
	if bound then
		ya.manager_emit("peek", { bound, only_if = self.file.url, upper_bound = true })
	end
end

return M

As a side note in cat mode these also seem not to work:

vim.opt.shiftwidth = 2 -- Size of an indent
vim.opt.tabstop = 2 -- Number of spaces tabs count for

nvimpager -c
image
nvimpager -p
image

So maybe it is a problem of not loading config in cat mode?

Shiftwidth is a setting that only has an effect when editing, so it is not relevant for nvimpager (any mode). Tabstop is not yet supported in cat mode, this is tracked in #35.

You can check if the config file is loaded in cat mode by just adding some debug statement to the config file:

print("config loaded")
vim.cmd.quitall()

Are you sure you want to append to rtp with the comma? I think it should be (the docs say it works like :set rtp+=

vim.opt.runtimepath:append("~/.local/share/nvim/lazy/github-nvim-theme")

Can you minimize your config to the smallest version that produces the error?

You can debug the bash part of nvimpager with bash -x nvimpager $args. Does the pager mode do something different than the cat mode at this point?

You can check if the config file is loaded in cat mode by just adding some debug statement to the config file:

print("config loaded")
vim.cmd.quitall()

This works for both cat and pager mode, thank you.

Are you sure you want to append to rtp with the comma? I think it should be (the docs say it works like :set rtp+=

vim.opt.runtimepath:append("~/.local/share/nvim/lazy/github-nvim-theme")

I did remove the comma, but that did not help.

Here is the minimal config with chosen syntax colouring:

vim.opt.runtimepath:append("~/.local/share/nvim/lazy/github-nvim-theme")
vim.cmd("colorscheme github_dark_dimmed")

Still the same issue:

❯ bash -x nvimpager -p ~/.config/yazi/plugins/nvimpager.yazi/init.lua
+ RUNTIME=/opt/homebrew/Cellar/nvimpager/0.13.0/share/nvimpager/runtime
+ PARENT=782
+ TMPFILE=
+ export RUNTIME
+ export PARENT
+ export TMPFILE
+ export NVIM_APPNAME=nvimpager
+ NVIM_APPNAME=nvimpager
+ mode=auto
+ nvim=nvim
+ getopts achpv flag
+ case $flag in
+ mode=pager
+ getopts achpv flag
+ shift 1
+ [[ 1 -eq 0 ]]
+ [[ ! -t 1 ]]
+ files=()
+ [[ 1 -gt 0 ]]
+ [[ -f /Users/kaliberr44/.config/yazi/plugins/nvimpager.yazi/init.lua ]]
+ files+=("$1")
+ shift
+ [[ 0 -gt 0 ]]
+ [[ -z '' ]]
+ [[ 1 -eq 0 ]]
+ [[ -n '' ]]
+ args=(-R --cmd 'set rtp+=$RUNTIME | lua nvimpager = require("nvimpager"); nvimpager.stage1()' -c 'lua nvimpager.stage2()')
+ [[ pager = cat ]]
+ [[ pager = auto ]]
+ exec -a nvimpager nvim -R --cmd 'set rtp+=$RUNTIME | lua nvimpager = require("nvimpager"); nvimpager.stage1()' -c 'lua nvimpager.stage2()' /Users/kaliberr44/.config/yazi/plugins/nvimpager.yazi/init.lua
❯ bash -x nvimpager -c ~/.config/yazi/plugins/nvimpager.yazi/init.lua
+ RUNTIME=/opt/homebrew/Cellar/nvimpager/0.13.0/share/nvimpager/runtime
+ PARENT=782
+ TMPFILE=
+ export RUNTIME
+ export PARENT
+ export TMPFILE
+ export NVIM_APPNAME=nvimpager
+ NVIM_APPNAME=nvimpager
+ mode=auto
+ nvim=nvim
+ getopts achpv flag
+ case $flag in
+ mode=cat
+ getopts achpv flag
+ shift 1
+ [[ 1 -eq 0 ]]
+ [[ ! -t 1 ]]
+ files=()
+ [[ 1 -gt 0 ]]
+ [[ -f /Users/kaliberr44/.config/yazi/plugins/nvimpager.yazi/init.lua ]]
+ files+=("$1")
+ shift
+ [[ 0 -gt 0 ]]
+ [[ -z '' ]]
+ [[ 1 -eq 0 ]]
+ [[ -n '' ]]
+ args=(-R --cmd 'set rtp+=$RUNTIME | lua nvimpager = require("nvimpager"); nvimpager.stage1()' -c 'lua nvimpager.stage2()')
+ [[ cat = cat ]]
+ args+=(--headless)
+ exec -a nvimpager nvim -R --cmd 'set rtp+=$RUNTIME | lua nvimpager = require("nvimpager"); nvimpager.stage1()' -c 'lua nvimpager.stage2()' --headless /Users/kaliberr44/.config/yazi/plugins/nvimpager.yazi/init.lua

This looks all good. You will have to debug what is actually going on inside nvimpager/neovim.

Some ideas:

  • check what is in the directory ~/.local/share/nvim/lazy/github-nvim-theme
  • check :scriptnames inside nvimpager, is your colorscheme loaded?
  • Is your colorscheme https://github.com/projekt0n/github-nvim-theme? Did you run :GithubThemeCompile?
  • Try another (builtin) colorscheme to see if you get any highlighting in cat mode
  • Bisect your config file (comment and uncomment some lines) to find the minimal version that exhibits the problem, maybe there is one setting that makes a difference

:scriptnames shows that is loaded.

Even with minimal config (1 line):

vim.cmd("colorscheme retrobox")

something is off. In pager mode it looks OK:
image

in cat mode there is colour change but it is completely wrong:
image

With no config at all - it is the same. No colouring in cat mode and in pager it is fine.

I can see the same problem with the background color but for me the foreground color seems to work:

2024-07-17-065806_453x175_scrot

I'm 99% sure that it did work like a month ago, without any config change. So maybe an update of nvimpager or nvim or kitty did that.