lucc / nvimpager

Use nvim as a pager to view manpages, diffs, etc with nvim's syntax highlighting
Other
395 stars 21 forks source link

Not coloring normal text #62

Closed ettom closed 2 years ago

ettom commented 2 years ago

Not sure if this is an issue on my part or intended behaviour, but nvimpager doesn't seem to set a color in cat mode for normal text.

init.vim:

syntax on
highlight Normal ctermfg=red

This still displays normal text with the colors set from Xresources. For the record, changing "Normal" to e.g. "Comment" correctly shows comments in red and everything also works as expected in pager mode.

lucc commented 2 years ago

This is dependent on the file you want to display. Nvimpager uses nvim to detect the file type. If nvim does not do any syntax highlighting for your file nvimpager can't either. Most filetype detection rules in nvim work with the filename so you might not get the correct syntax highlighting when piping text into nvimpager (for some well known programs nvimpager fixes that by detecting the parent process).

Can you provide a minimal example with your file and command line?

ettom commented 2 years ago

If nvim does not do any syntax highlighting for your file nvimpager can't either.

Do you mean that nvimpager is not able to change the color of "Normal" text in cat mode? Isn't "Normal" the default color, without any syntax highlighting?

With the init.vim I posted above:

test.txt:

Some text
nvimpager -c test.txt
*produces white (my default terminal foreground color) text*

nvimpager -p test.txt
*produces red text*
lucc commented 2 years ago

Thanks for the example, now I can reproduce it and it is indeed unintended. I will have to look at the code more thoroughly over the weekend to see what is going on here.

lucc commented 2 years ago

Can it be that you are using neovim <= 0.7? I added a similar test in 68c1c98f7671331431afe3489720c2778691b65b and that only passes for neovim >= 0.7.1. It seems they did some changes to the highlighting code in neovim and I was not able to come up with a test that works on both versions.

lucc commented 2 years ago

I was wrong: the neovim version is only the solution if the file has a filetype (see test "cat mode handles color schemes with a non trivial Normal group") but if the file has no filetype we hit this bug described here. There is a test in e5d80b325355eb174a5c6a2d6510114e2afaf3eb but I have no idea yet how to fix this.

lucc commented 2 years ago

@ettom can you by chance update to neovim 0.8.0 or 0.7.2? If your distro does not have it you could try to grab an appimage from the neovim release page and set the env varable NVIMPAGER_NVIM.

I have written some more tests in the branch issue-62 and found that these all pass when using neovim 0.8.0 or 0.7.2 but some fail when using neovim 0.7.0.

I tested it with the nix flake (typescript with terminal colors):

$ nix develop --check
NVIM v0.8.0
check flags: SHELL=/nix/store/2ispfz80kmwrsvwndxkxs56irn86h43p-bash-5.1-p16/bin/bash VERBOSE=y test
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
126 successes / 0 failures / 0 errors / 0 pending : 4.27932 seconds

$ nix develop --check --override-input nixpkgs github:nixos/nixpkgs/854fdc68881791812eddd33b2fed94b954979a8e
warning: not writing modified lock file of flake 'git+file:///home/luc/src/nvimpager':
• Updated input 'nixpkgs':
    'github:nixos/nixpkgs/598f83ebeb2235435189cf84d844b8b73e858e0f' (2022-10-06)
  → 'github:nixos/nixpkgs/854fdc68881791812eddd33b2fed94b954979a8e' (2022-09-28)
NVIM v0.7.2
check flags: SHELL=/nix/store/p7bpdnxqd3i5hwm92mrscf7mvxk66404-bash-5.1-p16/bin/bash VERBOSE=y test
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
126 successes / 0 failures / 0 errors / 0 pending : 4.788521 seconds

$ nix develop --check --override-input nixpkgs nixpkgs/nixos-22.05
warning: not writing modified lock file of flake 'git+file:///home/luc/src/nvimpager':
• Updated input 'nixpkgs':
    'github:nixos/nixpkgs/598f83ebeb2235435189cf84d844b8b73e858e0f' (2022-10-06)
  → 'github:NixOS/nixpkgs/9ecc270f02b09b2f6a76b98488554dd842797357' (2022-10-07)
NVIM v0.7.0
check flags: SHELL=/nix/store/9zm6br2ri10a0b71dll2wrim5bnhg6b6-bash-5.1-p16/bin/bash VERBOSE=y test
●●●●●◼●●●●●●●●●●◼◼◼◼●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
121 successes / 5 failures / 0 errors / 0 pending : 4.721634 seconds

Failure → test/nvimpager_spec.lua @ 79
cat mode handles color schemes with a non trivial Normal group
test/nvimpager_spec.lua:83: Expected objects to be equal.
Passed in:
(string) '\ss should be ß
'
Expected:
(string) '\ss should be ß
'

Failure → test/nvimpager_spec.lua @ 133
cat mode can change the default foreground color with --cmd, setting notermguicolors
test/nvimpager_spec.lua:139: Expected objects to be equal.
Passed in:
(string) 'some text
'
Expected:
(string) 'some text
'

Failure → test/nvimpager_spec.lua @ 133
cat mode can change the default foreground color with --cmd, setting notermguicolors input via stdin
test/nvimpager_spec.lua:139: Expected objects to be equal.
Passed in:
(string) 'some text
'
Expected:
(string) 'some text
'

Failure → test/nvimpager_spec.lua @ 133
cat mode can change the default foreground color with -c, setting notermguicolors
test/nvimpager_spec.lua:139: Expected objects to be equal.
Passed in:
(string) 'some text
'
Expected:
(string) 'some text
'

Failure → test/nvimpager_spec.lua @ 133
cat mode can change the default foreground color with -c, setting notermguicolors input via stdin
test/nvimpager_spec.lua:139: Expected objects to be equal.
Passed in:
(string) 'some text
'
Expected:
(string) 'some text
'
make: *** [makefile:29: test] Error 1
ettom commented 2 years ago

Working as expected with 0.8.0!