Skip to content

cat mode stopped colorising syntax  #101

@kaliberr44

Description

@kaliberr44

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    cat moderelated to the cat mode of nvimpager or the conversion of highlight groups to ansi escape sequences

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions