Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package nvimpager for openSUSE:Factory checked in at 2022-10-19 13:17:32 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/nvimpager (Old) and /work/SRC/openSUSE:Factory/.nvimpager.new.2275 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "nvimpager" Wed Oct 19 13:17:32 2022 rev:2 rq:1029730 version:0.11.0 Changes: -------- --- /work/SRC/openSUSE:Factory/nvimpager/nvimpager.changes 2022-08-18 16:49:49.829538576 +0200 +++ /work/SRC/openSUSE:Factory/.nvimpager.new.2275/nvimpager.changes 2022-10-19 13:17:58.137258406 +0200 @@ -1,0 +2,19 @@ +Tue Oct 18 11:56:47 UTC 2022 - Michael Vetter <mvet...@suse.com> + +- Update to 0.11.0: + Breaking changes: + * require neovim >= 0.7.2 + * Rename env var NVIM to NVIMPAGER_NVIM + * Improve version number format to better conform to SemVer + * Only use buffer local maps + * Keep input file order when reading from stdin and files + Major changes: + * Allow lua init file (#64[1]) + * Implement follow mode (#21[2]) + * Add git_colors option to use colors from git instead of internal syntax (#68[3]) + * Use :Man! to set filetype in python docs + * Use exec to start nvim, delete tempfile for stdin from nvim and set buftype=nofile + * Rename execed nvim process to "nvimpager" + * Remove extra redirect from tty + +------------------------------------------------------------------- Old: ---- v0.10.4.tar.gz New: ---- v0.11.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ nvimpager.spec ++++++ --- /var/tmp/diff_new_pack.mFX2sY/_old 2022-10-19 13:17:58.701259576 +0200 +++ /var/tmp/diff_new_pack.mFX2sY/_new 2022-10-19 13:17:58.705259584 +0200 @@ -17,7 +17,7 @@ Name: nvimpager -Version: 0.10.4 +Version: 0.11.0 Release: 0 Summary: Use nvim as a pager License: BSD-2-Clause @@ -25,8 +25,8 @@ URL: https://github.com/lucc/nvimpager Source: https://github.com/lucc/nvimpager/archive/refs/tags/v%{version}.tar.gz BuildRequires: scdoc -Requires: neovim >= 0.4.4 Requires: lua54 +Requires: neovim >= 0.7.2 BuildArch: noarch %description ++++++ v0.10.4.tar.gz -> v0.11.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nvimpager-0.10.4/.github/workflows/blank.yml new/nvimpager-0.11.0/.github/workflows/blank.yml --- old/nvimpager-0.10.4/.github/workflows/blank.yml 1970-01-01 01:00:00.000000000 +0100 +++ new/nvimpager-0.11.0/.github/workflows/blank.yml 2022-10-14 14:47:57.000000000 +0200 @@ -0,0 +1,59 @@ +name: CI + +on: [push] + +jobs: + + tests: + runs-on: ubuntu-latest + strategy: + matrix: + ppa-version: + - stable + - unstable + steps: + - uses: actions/checkout@v2 + - name: install dependencies + run: | + sudo add-apt-repository -y ppa:neovim-ppa/${{ matrix.ppa-version }} + sudo apt-get update + sudo apt-get install -yqq --no-install-recommends neovim scdoc lua-busted + - name: Run the test suite + run: script -ec "make test" + env: + TERM: dumb + + macos: + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - name: install dependencies + run: | + brew update + brew install neovim scdoc luarocks + luarocks --local install busted + - name: Run the test suite + run: script typescript make test BUSTED="$HOME/.luarocks/bin/busted --exclude-tags=osx_pending" + env: + TERM: dumb + + nix: + runs-on: ubuntu-latest + steps: + - name: Install Nix + uses: cachix/install-nix-action@v16 + - uses: actions/checkout@v2 + - name: Run the test suite + run: script -ec "nix develop --check" + env: + TERM: dumb + - name: Update the fake inputs + run: nix flake update + - name: Run the test suite again + run: script -ec "nix develop --check" + env: + TERM: dumb + - name: Run the test suite with nightly neovim + run: script -ec "nix develop --check '.#nightly'" + env: + TERM: dumb diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nvimpager-0.10.4/.travis.yml new/nvimpager-0.11.0/.travis.yml --- old/nvimpager-0.10.4/.travis.yml 2021-11-14 21:22:33.000000000 +0100 +++ new/nvimpager-0.11.0/.travis.yml 1970-01-01 01:00:00.000000000 +0100 @@ -1,57 +0,0 @@ -language: minimal -dist: focal - -addons: - apt: &apt_packages - - lua-busted - - neovim - - scdoc - homebrew: - - neovim - - scdoc - - luarocks - -matrix: - include: - - os: linux - - os: linux - env: UNSTABLE=true - addons: - apt: - source: { sourceline: 'ppa:neovim-ppa/unstable' } - packages: *apt_packages - - os: freebsd - addons: - pkg: - - neovim - - scdoc - - lua51-luarocks - env: BUSTED="$HOME/.luarocks/bin/busted --exclude-tags=osx_pending" - - os: osx - # Older versions have trouble with homebrew. When the osx builds start - # to fail again or take to long try updating this first. - osx_image: xcode12.5 - env: BUSTED="$HOME/.luarocks/bin/busted --exclude-tags=osx_pending" - allow_failures: - - os: linux - env: UNSTABLE=true - -before_install: | - case "$TRAVIS_OS_NAME" in - freebsd) luarocks51 --local install busted;; - osx) luarocks --local install busted;; - esac - -install: | - case "$TRAVIS_OS_NAME" in - freebsd) gmake install PREFIX=$HOME/.local;; - *) make install PREFIX=$HOME/.local;; - esac - -before_script: nvim --version - -script: | - case "$TRAVIS_OS_NAME" in - freebsd) gmake test BUSTED="$BUSTED";; - *) make test BUSTED="${BUSTED:-busted}";; - esac diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nvimpager-0.10.4/README.md new/nvimpager-0.11.0/README.md --- old/nvimpager-0.10.4/README.md 2021-11-14 21:22:33.000000000 +0100 +++ new/nvimpager-0.11.0/README.md 2022-10-14 14:47:57.000000000 +0200 @@ -32,8 +32,8 @@ Nvimpager comes with a small set of command line options but you can also use all of neovim's command line options. Use `nvimpager -h` to see the [help text][options]. The configuration is separated from the users config for -neovim. The main config file is `~/.config/nvimpager/init.vim`. See [the -manpage][configuration] for further explanation. +neovim. The main config file is `~/.config/nvimpager/init.vim` (or `.lua`). +See [the manpage][configuration] for further explanation. ## Installation @@ -47,7 +47,7 @@ ### Dependencies -* [neovim] ??? v0.4.0 +* [neovim] ??? v0.7.2 * [bash] * [busted] (for running the tests) * [scdoc] (to build the man page) @@ -69,26 +69,22 @@ Nvimpager is developed on [GitHub][nvimpager] where you are very much invited to [post][issues] bug reports, feature or pull requests! The test can be run -with `make test`. They are also run on travis: [![Build Status]][travis] +with `make test`. They are also run on GitHub: [![Build Status]][ghactions] -### Known Bugs (and non features) +### Limitations * if reading from stdin, nvimpager (like nvim) waits for EOF until it starts up * large files are slowing down neovim on startup (less does a better, i.e. faster and more memory efficient job at paging large files) -### TODO and ideas list +### Ideas * see how [neovim#7428](https://github.com/neovim/neovim/issues/7438) and - [neovim#8246](https://github.com/neovim/neovim/issues/8246) are resolved and + [neovim#18375](https://github.com/neovim/neovim/pull/18375) are resolved and maybe move more code (logic) from bash to lua (bash's `[[ -t ... ]]` can be replaced by `has('ttyin')`, `has('ttyout')`) * proper lazy pipe reading while paging (like less) to improve startup time and also memory usage for large input on pipes (maybe `stdioopen()` can be used?) -* properly kill the nvim process when the bash script is killed, alternatively - ... -* move temp file handling (removal) to nvim/lua (in a VimLeave autocommand) and - exec nvim ## License @@ -104,5 +100,5 @@ [bash]: https://www.gnu.org/software/bash/bash.html [busted]: https://olivinelabs.com/busted/ [scdoc]: https://git.sr.ht/~sircmpwn/scdoc -[Build Status]: https://travis-ci.com/lucc/nvimpager.svg?branch=develop -[travis]: https://travis-ci.com/github/lucc/nvimpager +[Build Status]: https://github.com/lucc/nvimpager/actions/workflows/blank.yml/badge.svg +[ghactions]: https://github.com/lucc/nvimpager/actions diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nvimpager-0.10.4/flake.lock new/nvimpager-0.11.0/flake.lock --- old/nvimpager-0.10.4/flake.lock 2021-11-14 21:22:33.000000000 +0100 +++ new/nvimpager-0.11.0/flake.lock 2022-10-14 14:47:57.000000000 +0200 @@ -1,43 +1,12 @@ { "nodes": { - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1627913399, - "narHash": "sha256-hY8g6H2KFL8ownSiFeMOjwPC8P0ueXpCVEbxgda3pko=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "12c64ca55c1014cdc1b16ed5a804aa8576601ff2", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, "flake-utils": { "locked": { - "lastModified": 1631561581, - "narHash": "sha256-3VQMV5zvxaVLvqqUrNz3iJelLw30mIVSfZmAaauM3dA=", + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", "owner": "numtide", "repo": "flake-utils", - "rev": "7e5bf3925f6fbdfaf50a2a7ca0be2879c4261d19", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_2": { - "locked": { - "lastModified": 1629481132, - "narHash": "sha256-JHgasjPR0/J1J3DRm4KxM4zTyAj4IOJY8vIl75v/kPI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "997f7efcb746a9c140ce1f13c72263189225f482", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", "type": "github" }, "original": { @@ -48,39 +17,20 @@ }, "neovim": { "inputs": { - "flake-compat": "flake-compat", - "neovim-flake": "neovim-flake", - "nixpkgs": "nixpkgs" - }, - "locked": { - "lastModified": 1633717671, - "narHash": "sha256-6S8zmZRKhbaau4E3BgVaEoeg4S/HWwfuRP07PKWovnw=", - "owner": "nix-community", - "repo": "neovim-nightly-overlay", - "rev": "09064a12c364bc9dc912d06a00508f0e237a99b9", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "neovim-nightly-overlay", - "type": "github" - } - }, - "neovim-flake": { - "inputs": { - "flake-utils": "flake-utils_2", + "flake-utils": [ + "flake-utils" + ], "nixpkgs": [ - "neovim", "nixpkgs" ] }, "locked": { "dir": "contrib", - "lastModified": 1633717173, - "narHash": "sha256-J9XnsjNixjXV9sE3rZ8Lg6mbBaR3scxhnyHO9A1ka34=", + "lastModified": 1665248803, + "narHash": "sha256-pYbr0Wz7DmdWgu9qv6JJ/SViXj0rT0LMoQ9tDw/VUH4=", "owner": "neovim", "repo": "neovim", - "rev": "3f097321955e32b0724e0f0d059ecef3d764aac8", + "rev": "edc8a1f04631b021f9c5e79f7162e34f7c3299db", "type": "github" }, "original": { @@ -92,27 +42,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1633528625, - "narHash": "sha256-AGj5q58eHACAe0RQGxObrGwMUsjMozTsiznhsLCYisQ=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "5e2018f7b383aeca6824a30c0cd1978c9532a46a", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1633617995, - "narHash": "sha256-+RfYXTAXtULLSAMFDHWaA20NhNg3YQ9GcntVJqDDjSI=", + "lastModified": 1665081174, + "narHash": "sha256-6hsmzdhdy8Kbvl5e0xZNE83pW3fKQvNiobJkM6KQrgA=", "owner": "nixos", "repo": "nixpkgs", - "rev": "70088dc29994c32f8520150e34c6e57e8453f895", + "rev": "598f83ebeb2235435189cf84d844b8b73e858e0f", "type": "github" }, "original": { @@ -126,7 +60,7 @@ "inputs": { "flake-utils": "flake-utils", "neovim": "neovim", - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs" } } }, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nvimpager-0.10.4/flake.nix new/nvimpager-0.11.0/flake.nix --- old/nvimpager-0.10.4/flake.nix 2021-11-14 21:22:33.000000000 +0100 +++ new/nvimpager-0.11.0/flake.nix 2022-10-14 14:47:57.000000000 +0200 @@ -3,7 +3,9 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; - neovim.url = "github:nix-community/neovim-nightly-overlay"; + neovim.url = "github:neovim/neovim?dir=contrib"; + neovim.inputs.nixpkgs.follows = "nixpkgs"; + neovim.inputs.flake-utils.follows = "flake-utils"; }; outputs = { self, nixpkgs, flake-utils, neovim, ... }: { @@ -11,11 +13,15 @@ nvimpager = prev.nvimpager.overrideAttrs (oa: { version = "dev"; src = ./.; + preBuild = "version=$(bash ./nvimpager -v | sed 's/.* //')"; + buildFlags = oa.buildFlags ++ [ "VERSION=\${version}-dev" ]; }); }; } - // - flake-utils.lib.eachDefaultSystem (system: + // (let + filter = builtins.filter (s: !nixpkgs.lib.strings.hasSuffix "-darwin" s); + inherit (flake-utils.lib) eachSystem defaultSystems; + in eachSystem (filter defaultSystems) (system: let stable = import nixpkgs { overlays = [ self.overlay ]; inherit system; }; nightly = import nixpkgs { overlays = [ neovim.overlay self.overlay ]; inherit system; }; @@ -30,10 +36,10 @@ shellHook = '' # to find nvimpager lua code in the current dir export LUA_PATH=./?.lua''${LUA_PATH:+\;}$LUA_PATH - # fix for my terminal in a pure shell - if [ "$TERM" = xterm-termite ]; then - export TERM=xterm - fi + # fix for different terminals in a pure shell + export TERM=xterm + # print the neovim version we are using + nvim --version | head -n 1 ''; }; in rec { @@ -42,13 +48,12 @@ nvimpager-with-nightly-neovim = nightly.nvimpager; }; defaultPackage = stable.nvimpager; - apps.nvimpager = flake-utils.lib.mkApp { drv = stable.nvimpager; name = "nvimpager"; }; + apps.nvimpager = flake-utils.lib.mkApp { drv = stable.nvimpager; }; defaultApp = apps.nvimpager; devShell = devShells.stable; devShells = { stable = mkShell stable; nightly = mkShell nightly; }; - } - ); + })); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nvimpager-0.10.4/lua/nvimpager.lua new/nvimpager-0.11.0/lua/nvimpager.lua --- old/nvimpager-0.10.4/lua/nvimpager.lua 2021-11-14 21:22:33.000000000 +0100 +++ new/nvimpager-0.11.0/lua/nvimpager.lua 2022-10-14 14:47:57.000000000 +0200 @@ -18,7 +18,11 @@ -- names that will be exported from this module local nvimpager = { -- user facing options - maps = true, -- if the default mappings should be defined + maps = true, -- if the default mappings should be defined + git_colors = false, -- if the highlighting from the git should be used + -- follow the end of the file when it changes (like tail -f or less +F) + follow = false, + follow_interval = 500, -- intervall to check the underlying file in ms } -- A mapping of ansi color numbers to neovim color names @@ -157,8 +161,6 @@ -- Initialize some module level variables for cat mode. local function init_cat_mode() - -- Initialize the ansi group to color cache with the "Normal" hl group. - cache[0] = group2ansi(nvim.nvim_call_function('hlID', {'Normal'})) -- Get the value of &termguicolors from neovim. colors_24_bit = nvim.nvim_get_option('termguicolors') -- Select the correct coloe escaping function. @@ -167,6 +169,8 @@ else color2escape = color2escape_8bit end + -- Initialize the ansi group to color cache with the "Normal" hl group. + cache[0] = group2ansi(nvim.nvim_call_function('hlID', {'Normal'})) end -- Check if the begining of the current buffer contains ansi escape sequences. @@ -180,22 +184,6 @@ return false end --- Savely get the listchars option on different nvim versions --- --- From release 0.4.3 to 0.4.4 the listchars option was changed from window --- local to global-local. This affects the calls to either --- nvim_win_get_option or nvim_get_option so that there is no save way to call --- just one in all versions. --- --- returns: string -- the listchars value -local function get_listchars() - -- this works for newer versions of neovim - local status, data = pcall(nvim.nvim_get_option, 'listchars') - if status then return data end - -- this works for old neovim versions - return nvim.nvim_win_get_option(0, 'listchars') -end - -- turn a listchars string into a table local function parse_listchars(listchars) local t = {} @@ -209,11 +197,8 @@ -- Iterate through the current buffer and print it to stdout with terminal -- color codes for highlighting. local function highlight() - -- Detect an empty buffer, see :help line2byte(). We can not use - -- nvim_buf_get_lines as the table will contain one empty string for both an - -- empty file and a file with just one empty line. - if nvim.nvim_buf_line_count(0) == 1 and - nvim.nvim_call_function("line2byte", {2}) == -1 then + -- Detect an empty buffer. + if nvim.nvim_buf_get_offset(0, 0) == -1 then return elseif check_escape_sequences() then for _, line in ipairs(nvim.nvim_buf_get_lines(0, 0, -1, false)) do @@ -226,7 +211,7 @@ local syntax_id_whitespace = nvim.nvim_call_function('hlID', {'Whitespace'}) local syntax_id_non_text = nvim.nvim_call_function('hlID', {'NonText'}) local list = nvim.nvim_win_get_option(0, "list") - local listchars = list and parse_listchars(get_listchars()) or {} + local listchars = list and parse_listchars(vim.o.listchars) or {} local last_syntax_id = -1 local last_conceal_id = -1 local linecount = nvim.nvim_buf_line_count(0) @@ -335,8 +320,7 @@ nvim.nvim_set_option("packpath", runtimepath) runtimepath = os.getenv("RUNTIME") .. "," .. runtimepath nvim.nvim_set_option("runtimepath", runtimepath) - new = new .. '/rplugin.vim' - nvim.nvim_command("let $NVIM_RPLUGIN_MANIFEST = '" .. new .. "'") + vim.env.NVIM_RPLUGIN_MANIFEST = new .. '/rplugin.vim' end -- Parse the command of the calling process to detect some common @@ -374,7 +358,7 @@ -- characters at the end of the line. I could not find a man pager where -- this was the case. -- FIXME This only works for man pages in languages where "NAME" is used - -- as the headline. Some (not all!) German man pages use "BBEZEICHNUNG" + -- as the headline. Some (not all!) German man pages use "BEZEICHNUNG" -- instead. if line == 'NAME' or line == 'N\bNA\bAM\bME\bE' or line == "Name" or line == 'N\bNa\bam\bme\be' then @@ -399,15 +383,25 @@ local function detect_filetype() if not doc and detect_man_page_in_current_buffer() then doc = 'man' end if doc == 'git' then - -- Use nvim's syntax highlighting for git buffers instead of git's - -- internal highlighting. - strip_ansi_escape_sequences_from_current_buffer() + if nvimpager.git_colors then + -- Use the highlighting from the git commands. + doc = nil + else + -- Use nvim's syntax highlighting for git buffers instead of git's + -- internal highlighting. + strip_ansi_escape_sequences_from_current_buffer() + end end - if doc == 'man' then + -- python uses the same "highlighting" technique with backspace as roff. + -- This means we have to load the full :Man plugin for python as well and + -- not just set the filetype to man. + if doc == 'man' or doc == 'pydoc' then nvim.nvim_buf_set_option(0, 'readonly', false) nvim.nvim_command("Man!") nvim.nvim_buf_set_option(0, 'readonly', true) - elseif doc == 'pydoc' or doc == 'perldoc' or doc == 'ri' then + -- do not set the file type again later on + doc = nil + elseif doc == 'perldoc' or doc == 'ri' then doc = 'man' -- only set the syntax, not the full :Man plugin end if doc ~= nil then @@ -665,21 +659,40 @@ end end +local follow_timer = nil +function nvimpager.toggle_follow() + if follow_timer ~= nil then + vim.fn.timer_pause(follow_timer, nvimpager.follow) + nvimpager.follow = not nvimpager.follow + else + follow_timer = vim.fn.timer_start( + nvimpager.follow_interval, + function() + nvim.nvim_command("silent checktime") + nvim.nvim_command("silent $") + end, + { ["repeat"] = -1 }) + nvimpager.follow = true + end +end + -- Set up mappings to make nvim behave a little more like a pager. local function set_maps() - local function map(mode, lhs, rhs) - nvim.nvim_set_keymap(mode, lhs, rhs, {noremap = true}) - nvim.nvim_buf_set_keymap(0, mode, lhs, rhs, {noremap = true}) - end - map('n', 'q', '<CMD>quitall!<CR>') - map('v', 'q', '<CMD>quitall!<CR>') - map('n', '<Space>', '<PageDown>') - map('n', '<S-Space>', '<PageUp>') - map('n', 'g', 'gg') - map('n', '<Up>', '<C-Y>') - map('n', '<Down>', '<C-E>') - map('n', 'k', '<C-Y>') - map('n', 'j', '<C-E>') + local function map(lhs, rhs, mode) + -- we are using buffer local maps because we want to overwrite the buffer + -- local maps from the man plugin (and maybe others) + vim.keymap.set(mode or 'n', lhs, rhs, { buffer = true }) + end + map('q', '<CMD>quitall!<CR>') + map('q', '<CMD>quitall!<CR>', 'v') + map('<Space>', '<PageDown>') + map('<S-Space>', '<PageUp>') + map('g', 'gg') + map('<Up>', '<C-Y>') + map('<Down>', '<C-E>') + map('k', '<C-Y>') + map('j', '<C-E>') + map('F', nvimpager.toggle_follow) end -- Setup function for the VimEnter autocmd. @@ -696,6 +709,18 @@ end nvim.nvim_buf_set_option(0, 'modifiable', false) nvim.nvim_buf_set_option(0, 'modified', false) + if nvimpager.maps then + -- if this is done in VimEnter it will override any settings in the user + -- config, if we do it globally we are not overwriting the mappings from + -- the man plugin + set_maps() + end + -- Check if the user requested follow mode on startup + if nvimpager.follow then + -- turn follow mode of so that we can use the init logic in toggle_follow + nvimpager.follow = false + nvimpager.toggle_follow() + end end -- Setup function to be called from --cmd. @@ -706,9 +731,15 @@ -- prevent messages when opening files (especially for the cat version) nvim.nvim_set_option('shortmess', nvim.nvim_get_option('shortmess')..'F') -- Define autocmd group for nvimpager. - nvim.nvim_command('augroup NvimPager') - nvim.nvim_command(' autocmd!') - nvim.nvim_command('augroup END') + local group = nvim.nvim_create_augroup('NvimPager', {}) + local tmp = os.getenv('TMPFILE') + if tmp and tmp ~= "" then + nvim.nvim_create_autocmd("VimEnter", {pattern = "*", once = true, + group = group, callback = function() + nvim.nvim_buf_set_option(0, "buftype", "nofile") + os.remove(tmp) + end}) + end doc = detect_parent_process() if doc == 'git' then -- We disable modelines for this buffer as they could disturb the git @@ -730,20 +761,17 @@ -- would not be available in --cmd. function nvimpager.stage2() detect_filetype() - local mode, events + local callback, events if #nvim.nvim_list_uis() == 0 then - mode, events = 'cat', 'VimEnter' + callback, events = nvimpager.cat_mode, 'VimEnter' else - if nvimpager.maps then - set_maps() - end - mode, events = 'pager', 'VimEnter,BufWinEnter' + callback, events = nvimpager.pager_mode, {'VimEnter', 'BufWinEnter'} end + local group = nvim.nvim_create_augroup('NvimPager', {clear = false}) -- The "nested" in these autocomands enables nested executions of - -- autocomands inside the *_mode() functions. See :h autocmd-nested, for - -- compatibility with nvim < 0.4 we use "nested" and not "++nested". - nvim.nvim_command( - 'autocmd NvimPager '..events..' * nested lua nvimpager.'..mode..'_mode()') + -- autocomands inside the *_mode() functions. See :h autocmd-nested. + nvim.nvim_create_autocmd(events, {pattern = '*', callback = callback, + nested = true, group = group}) end -- functions only exported for tests diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nvimpager-0.10.4/makefile new/nvimpager-0.11.0/makefile --- old/nvimpager-0.10.4/makefile 2021-11-14 21:22:33.000000000 +0100 +++ new/nvimpager-0.11.0/makefile 2022-10-14 14:47:57.000000000 +0200 @@ -21,7 +21,7 @@ $(PREFIX)/share/man/man1/nvimpager.1 \ $(PREFIX)/share/zsh/site-functions/_nvimpager -nvimpager.1: SOURCE_DATE_EPOCH = $(shell git log -1 --no-show-signature --pretty="%ct" 2>/dev/null || echo 1636921311) +nvimpager.1: SOURCE_DATE_EPOCH = $(shell git log -1 --no-show-signature --pretty="%ct" 2>/dev/null || echo 1665751677) nvimpager.1: nvimpager.md sed '1s/$$/ "nvimpager $(VERSION)"/' $< | scdoc > $@ @@ -35,14 +35,23 @@ TYPE = minor version: [ $(TYPE) = major ] || [ $(TYPE) = minor ] || [ $(TYPE) = patch ] + git switch main + git diff --quiet HEAD sed -i 's/version=.*version=/version=/' nvimpager - awk -i inplace -F '[v.]' -v type=$(TYPE)\ - -e 'type == "major" && /version=/ { print $$1 "version=v" $$3+1 ".0" }' \ - -e 'type == "minor" && /version=/ { print $$1 "version=v" $$3 "." $$4+1 }' \ - -e 'type == "patch" && /version=/ { print $$1 "version=v" $$3 "." $$4 "." $$5+1 }' \ + awk -i inplace -F '[=.]' -v type=$(TYPE)\ + -e 'type == "major" && /version=/ { print $$1"="$$2+1 ".0.0" }' \ + -e 'type == "minor" && /version=/ { print $$1"="$$2 "." $$3+1 ".0" }' \ + -e 'type == "patch" && /version=/ { print $$1"="$$2 "." $$3 "." $$4+1 }' \ -e '/version=/ { next }' \ -e '{ print $$0 }' nvimpager sed -i "/SOURCE_DATE_EPOCH/s/[0-9]\{10,\}/$(shell date +%s)/" $(MAKEFILE_LIST) + git add nvimpager makefile + (./nvimpager -v | sed 's/^nvimpager/Version/'; \ + printf '%s\n' '' 'Major changes:' 'Breaking changes:' 'Changes:'; \ + git log $(shell git tag --list --sort=version:refname 'v*' | tail -n 1)..HEAD) \ + | sed -E '/^(commit|Merge:|Author:)/d; /^Date/{N;N; s/.*\n.*\n /-/;}' \ + | git commit --edit --file - + git tag v$$(./nvimpager -v | sed 's/.* //') clean: $(RM) nvimpager.configured nvimpager.1 luacov.* diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nvimpager-0.10.4/nvimpager new/nvimpager-0.11.0/nvimpager --- old/nvimpager-0.10.4/nvimpager 2021-11-14 21:22:33.000000000 +0100 +++ new/nvimpager-0.11.0/nvimpager 2022-10-14 14:47:57.000000000 +0200 @@ -5,13 +5,15 @@ RUNTIME=${BASH_SOURCE%/*} PARENT=$PPID +TMPFILE= export RUNTIME export PARENT +export TMPFILE name=nvimpager mode=auto -rc=${XDG_CONFIG_HOME:-~/.config}/nvimpager/init.vim -nvim=${NVIM:-nvim} +rc=${XDG_CONFIG_HOME:-~/.config}/nvimpager/init.lua +nvim=${NVIMPAGER_NVIM:-nvim} usage () { echo "Usage: ${0##*/} [-acp] [--] [nvim options and files]" @@ -49,8 +51,8 @@ h) usage; description; exit;; p) mode=pager;; v) - version=v0.10.4 - echo "$name $version" + version=0.11.0 + echo "$name ${version#v}" exit ;; *) usage >&2; exit 2;; @@ -69,7 +71,12 @@ exec cat "$@" fi -if [[ ! -r $rc ]]; then +if [[ -r $rc && -r ${rc%lua}vim ]] ; then + echo Conflicting configs: "$rc" "${rc%lua}vim" + exit 2 +elif [[ ! -r $rc && -r ${rc%lua}vim ]]; then + rc=${rc%lua}vim +elif [[ ! -r $rc ]]; then rc=NORC fi @@ -83,8 +90,8 @@ files+=("$1") shift elif [[ $1 = - ]]; then - stdin=$(mktemp) - files+=("$stdin") + TMPFILE=$(mktemp) + files+=("$TMPFILE") shift else if [[ $mode = auto ]]; then @@ -96,14 +103,14 @@ # If we did not get any file arguments and stdin is not a terminal, read stdin # into a temp file. -if [[ $stdin = false && ${#files[@]} -eq 0 && ! -t 0 ]]; then - stdin=$(mktemp) - files+=("$stdin") +if [[ -z $TMPFILE && ${#files[@]} -eq 0 && ! -t 0 ]]; then + TMPFILE=$(mktemp) + files=("$TMPFILE") fi -if [[ $stdin != false ]]; then +if [[ $TMPFILE ]]; then # Bash runs the EXIT trap also when exiting due to signals. - trap 'rm -f "$stdin"' EXIT - cat > "$stdin" + trap 'rm -f "$TMPFILE"' EXIT + cat > "$TMPFILE" fi # these come before all user supplied -c and --cmd arguments @@ -124,4 +131,4 @@ then args1+=(--headless) fi -$nvim "${args1[@]}" "${files[@]}" "$@" "${args2[@]}" </dev/tty +exec -a nvimpager $nvim "${args1[@]}" "${files[@]}" "$@" "${args2[@]}" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nvimpager-0.10.4/nvimpager.md new/nvimpager-0.11.0/nvimpager.md --- old/nvimpager-0.10.4/nvimpager.md 2021-11-14 21:22:33.000000000 +0100 +++ new/nvimpager-0.11.0/nvimpager.md 2022-10-14 14:47:57.000000000 +0200 @@ -52,9 +52,11 @@ Like neovim itself nvimpager will honour *$XDG_CONFIG_HOME* and *$XDG_DATA_HOME*, which default to *~/.config* and *~/.local* respectively. The main config directory is *$XDG_CONFIG_HOME/nvimpager* and the main user -config file is *$XDG_CONFIG_HOME/nvimpager/init.vim*. The site directory is -*$XDG_DATA_HOME/.local/share/nvimpager/site*. The manifest for remote plugins -is read from (and written to) *$XDG_DATA_HOME/nvimpager/rplugin.vim*. +config file is *$XDG_CONFIG_HOME/nvimpager/init.lua* or +*$XDG_CONFIG_HOME/nvimpager/init.vim*. It is an error if both files are +present. The site directory is *$XDG_DATA_HOME/.local/share/nvimpager/site*. +The manifest for remote plugins is read from (and written to) +*$XDG_DATA_HOME/nvimpager/rplugin.vim*. The rest of the *&runtimepath* is configured like for neovim. The *-u* option of *nvim*(1) itself can be used to change the main config file from the command @@ -68,13 +70,13 @@ ## Environment variables -The environment variable *$NVIM* can be used to specify an nvim executable to -use. If unset it defaults to *nvim*. +The environment variable *$NVIMPAGER_NVIM* can be used to specify an nvim +executable to use. If unset it defaults to *nvim*. ## Configuration variables The script exposes a lua table called *nvimpager* to *--cmd*/*-c* options and -the *init.vim* file. It can be modified to change some options that are +the init file. It can be modified to change some options that are specific to nvimpager. The following fields (options) exist: @@ -83,12 +85,38 @@ :- *type* :- *default* :< *explanation* +| follow +: bool +: false +: start in follow mode, i.e. continuously load changes to the opened file and + scroll to the bottom (like *less +F* or *tail -f*) +| follow_interval +: number +: 500 +: how often in ms the underlying file should be checked in follow mode +| git_colors +: bool +: false +: use git command highlighting instead of nvim syntax highlighting, + set this to true if you use an external diff | maps : bool : true : if some default less like maps should be defined inside pager mode -So to disable all mappings defined by nvimpager the user can put +So to start nvimpager and follow changes to the opened file the user can put + +``` +lua nvimpager.follow = true +``` + +in the init file (or on the command line). + +## Default key mappings + +Nvimpager defines some mappings to make it feel more like a pager than an +editor. These mappings are inspired by *less*(1) which are very close to the +defaults in neovim. These mappings can be deactivated altogether by putting ``` lua nvimpager.maps = false @@ -96,6 +124,19 @@ in the init file (or on the command line). +The following mappings are defined by default: + +- *q* is mapped to quit nvimpager in normal and visual mode +- *<Space>* and *<S-Space>* move down or up a page respectively +- *g* goes to the top of the file +- *<Down>* and *j* scroll the window down one line +- *<Up>* and *k* scroll the window up one line +- *F* toggles "follow mode" where nvimpager continuously loads changes to the + underlying file and scrolls to the bottom. This is usefull for watching log + files. It is modeled after the *F* command in *less*(1) or the *-f* option + of *tail*(1) + + # EXAMPLES To use nvimpager to view a file (with neovim's syntax highlighting if the @@ -119,6 +160,27 @@ git diff ``` +Options for *nvim*(1) can be specified if they are separated from the options +for nvimpager itself. Either by separating them with *--* or by putting the +nvim options after at least one non option argument: + +``` +nvimpager -p -- -c 'echo "option for nvim"' file +nvimpager -p file -u custom_init.vim +``` + +Start nvimpager in "follow mode" to watch a growing log file: + +``` +nvimpager log_file -c 'lua nvimpager.follow = true' +``` + +# LIMITATIONS + +If reading from stdin, nvimpager (like *nvim*(1)) waits for EOF until it starts +up. This means that it can not be used to continuously watch output from a +long running command even in follow mode. + # SEE ALSO *nvim(1)* https://github.com/neovim/neovim diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nvimpager-0.10.4/test/fixtures/conceal.tex.red new/nvimpager-0.11.0/test/fixtures/conceal.tex.red --- old/nvimpager-0.10.4/test/fixtures/conceal.tex.red 1970-01-01 01:00:00.000000000 +0100 +++ new/nvimpager-0.11.0/test/fixtures/conceal.tex.red 2022-10-14 14:47:57.000000000 +0200 @@ -0,0 +1 @@ +[0;95m\ss[0;91m should be ??[0;91m diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nvimpager-0.10.4/test/fixtures/difftastic new/nvimpager-0.11.0/test/fixtures/difftastic --- old/nvimpager-0.10.4/test/fixtures/difftastic 1970-01-01 01:00:00.000000000 +0100 +++ new/nvimpager-0.11.0/test/fixtures/difftastic 2022-10-14 14:47:57.000000000 +0200 @@ -0,0 +1,10 @@ +[1;33m.github/workflows/blank.yml[0m -- text + 8 [2;37m runs-on: ubuntu-latest[0m 8 [2;37m runs-on: ubuntu-latest[0m + 9 [2;37m strategy:[0m 9 [2;37m strategy:[0m +10 [2;37m matrix:[0m 10 [2;37m matrix:[0m +11 [2;37m ppa-version:[0m 11 [2;37m ppa-version:[0m +12 [1;91m - [0m[31mstable[0m 12 [1;92m # this is currently neovim 0.6.1 and does not work/takes forever[0m +.. 13 [1;92m #- [0m[32mstable[0m +13 [2;37m - unstable[0m 14 [2;37m - unstable[0m +14 [2;37m steps:[0m 15 [2;37m steps:[0m + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nvimpager-0.10.4/test/fixtures/plain.red new/nvimpager-0.11.0/test/fixtures/plain.red --- old/nvimpager-0.10.4/test/fixtures/plain.red 1970-01-01 01:00:00.000000000 +0100 +++ new/nvimpager-0.11.0/test/fixtures/plain.red 2022-10-14 14:47:57.000000000 +0200 @@ -0,0 +1 @@ +[0;91msome text[0;91m diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nvimpager-0.10.4/test/fixtures/plain.red24 new/nvimpager-0.11.0/test/fixtures/plain.red24 --- old/nvimpager-0.10.4/test/fixtures/plain.red24 1970-01-01 01:00:00.000000000 +0100 +++ new/nvimpager-0.11.0/test/fixtures/plain.red24 2022-10-14 14:47:57.000000000 +0200 @@ -0,0 +1 @@ +[0;38;2;255;0;0msome text[0;38;2;255;0;0m diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nvimpager-0.10.4/test/fixtures/plain.txt new/nvimpager-0.11.0/test/fixtures/plain.txt --- old/nvimpager-0.10.4/test/fixtures/plain.txt 1970-01-01 01:00:00.000000000 +0100 +++ new/nvimpager-0.11.0/test/fixtures/plain.txt 2022-10-14 14:47:57.000000000 +0200 @@ -0,0 +1 @@ +some text diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nvimpager-0.10.4/test/helpers.lua new/nvimpager-0.11.0/test/helpers.lua --- old/nvimpager-0.10.4/test/helpers.lua 1970-01-01 01:00:00.000000000 +0100 +++ new/nvimpager-0.11.0/test/helpers.lua 2022-10-14 14:47:57.000000000 +0200 @@ -0,0 +1,121 @@ +-- Helper functions for the test suite + +-- assert library used by busted +local assert = require("luassert") + +-- gloabl varables to set $XDG_CONFIG_HOME and $XDG_DATA_HOME to for the +-- tests. +local tmp = os.getenv("TMPDIR") or "/tmp" +local confdir = tmp .. "/nvimpager-testsuite/no-config" +local datadir = tmp .. "/nvimpager-testsuite/no-data" + +-- Run a shell command, assert it terminates with return code 0 and return its +-- output. +-- +-- The assertion of the return status works even with Lua 5.1. The last byte +-- of output of the command *must not* be a decimal digit. +-- +-- command: string -- the shell command to execute +-- returns: string -- the output of the command +local function run(command) + -- From Lua 5.2 on we could use io.close to retrieve the return status of + -- the process. It would return true, "exit", x where x is the status. + -- For Lua 5.1 (currently used by neovim) we have to echo the return status + -- in the shell command and extract it from the output. + -- References: + -- https://www.lua.org/manual/5.1/manual.html#pdf-io.close + -- https://www.lua.org/manual/5.1/manual.html#pdf-file:close + -- https://www.lua.org/manual/5.2/manual.html#pdf-io.close + -- https://www.lua.org/manual/5.2/manual.html#pdf-file:close + -- https://www.lua.org/manual/5.2/manual.html#pdf-os.execute + -- https://stackoverflow.com/questions/7607384 + command = string.format("XDG_CONFIG_HOME=%s XDG_DATA_HOME=%s %s; echo $?", + confdir, datadir, command) + local proc = io.popen(command) + local output = proc:read('*a') + local status = {proc:close()} + -- This is *not* the return value of the command. + assert.equal(true, status[1]) + -- In Lua 5.2 we could also assert this and it would be meaningful: + -- assert.equal("exit", status[2]) + -- assert.equal(0, status[3]) + -- For Lua 5.1 we have echoed the return status with the output. First we + -- assert the last two bytes, which is easy: + assert.equal("0\n", output:sub(-2), "command failed") + -- When the original command did not produce any output this is it. + if #output ~= 2 then + -- Otherwise we can only hope that the command did not produce a digit as + -- it's last character of output. + assert.is_nil(tonumber(output:sub(-3, -3)), "command failed") + end + -- If the assert succeeded we can remove two bytes from the end. + return output:sub(1, -3) +end + +-- Read contents of a file and return them. +-- +-- filename: string -- the name of the file to read +-- returns: string -- the contents of the file +local function read(filename) + local file = io.open(filename) + local contents = file:read('*a') + return contents +end + +-- Write contents to a file. +-- +-- filename: string -- the name of the file to write +-- contents: string -- the contents to write to the file +-- returns: nil +local function write(filename, contents) + local handle = io.open(filename, "w") + if handle == nil then assert.not_nil(handle, "could not open file") end + handle:write(contents) + handle:flush() + handle:close() +end + +-- Freshly require the nvimpager module, optinally with mocks +-- +-- api: table|nil -- a mock for the neovim api table (:help lua-api) +-- return: table -- the nvimpager module +local function load_nvimpager(api) + -- Create a local mock of the vim module that is provided by neovim. + local default_api = { + nvim_get_hl_by_id = function() return {} end, + -- These can return different types so we just default to nil. + nvim_call_function = function() end, + nvim_get_option = function() end, + } + if api == nil then + api = default_api + else + for key, value in pairs(default_api) do + if api[key] == nil then api[key] = value end + end + end + local vim = { api = api } + -- Register the api mock in the globals. + _G.vim = vim + -- Reload the nvimpager script + package.loaded["lua/nvimpager"] = nil + return require("lua/nvimpager") +end + +-- generator for random strings +local chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" +local len = chars:len() +local function random(count) + local i = math.random(len) + if count == nil or count <= 1 then return chars:sub(i, i) end + return chars:sub(i, i) .. random(count - 1) +end + +return { + confdir = confdir, + datadir = datadir, + load_nvimpager = load_nvimpager, + read = read, + run = run, + write = write, +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nvimpager-0.10.4/test/nvimpager_spec.lua new/nvimpager-0.11.0/test/nvimpager_spec.lua --- old/nvimpager-0.10.4/test/nvimpager_spec.lua 2021-11-14 21:22:33.000000000 +0100 +++ new/nvimpager-0.11.0/test/nvimpager_spec.lua 2022-10-14 14:47:57.000000000 +0200 @@ -5,91 +5,8 @@ local describe, it, assert, mock, setup, before_each = describe, it, assert, mock, setup, before_each -- luacheck: ignore --- gloabl varables to set $XDG_CONFIG_HOME and $XDG_DATA_HOME to for the --- tests. -local tmp = os.getenv("TMPDIR") or "/tmp" -local confdir = tmp .. "/nvimpager-testsuite/no-config" -local datadir = tmp .. "/nvimpager-testsuite/no-data" - --- Run a shell command, assert it terminates with return code 0 and return its --- output. --- --- The assertion of the return status works even with Lua 5.1. The last byte --- of output of the command *must not* be a decimal digit. --- --- command: string -- the shell command to execute --- returns: string -- the output of the command -local function run(command) - -- From Lua 5.2 on we could use io.close to retrieve the return status of - -- the process. It would return true, "exit", x where x is the status. - -- For Lua 5.1 (currently used by neovim) we have to echo the return status - -- in the shell command and extract it from the output. - -- References: - -- https://www.lua.org/manual/5.1/manual.html#pdf-io.close - -- https://www.lua.org/manual/5.1/manual.html#pdf-file:close - -- https://www.lua.org/manual/5.2/manual.html#pdf-io.close - -- https://www.lua.org/manual/5.2/manual.html#pdf-file:close - -- https://www.lua.org/manual/5.2/manual.html#pdf-os.execute - -- https://stackoverflow.com/questions/7607384 - command = string.format("XDG_CONFIG_HOME=%s XDG_DATA_HOME=%s %s; echo $?", - confdir, datadir, command) - local proc = io.popen(command) - local output = proc:read('*all') - local status = {proc:close()} - -- This is *not* the return value of the command. - assert.equal(true, status[1]) - -- In Lua 5.2 we could also assert this and it would be meaningful: - -- assert.equal("exit", status[2]) - -- assert.equal(0, status[3]) - -- For Lua 5.1 we have echoed the return status with the output. First we - -- assert the last two bytes, which is easy: - assert.equal("0\n", output:sub(-2), "command failed") - -- When the original command did not produce any output this is it. - if #output ~= 2 then - -- Otherwise we can only hope that the command did not produce a digit as - -- it's last character of output. - assert.is_nil(tonumber(output:sub(-3, -3)), "command failed") - end - -- If the assert succeeded we can remove two bytes from the end. - return output:sub(1, -3) -end - --- Read contents of a file and return them. --- --- filename: string -- the name of the file to read --- returns: string -- the contents of the file -local function read(filename) - local file = io.open(filename) - local contents = file:read('*all') - return contents -end - --- Freshly require the nvimpager module, optinally with mocks --- --- api: table|nil -- a mock for the neovim api table (:help lua-api) --- return: table -- the nvimpager module -local function load_nvimpager(api) - -- Create a local mock of the vim module that is provided by neovim. - local default_api = { - nvim_get_hl_by_id = function() return {} end, - -- These can return different types so we just default to nil. - nvim_call_function = function() end, - nvim_get_option = function() end, - } - if api == nil then - api = default_api - else - for key, value in pairs(default_api) do - if api[key] == nil then api[key] = value end - end - end - local vim = { api = api } - -- Register the api mock in the globals. - _G.vim = vim - -- Reload the nvimpager script - package.loaded["lua/nvimpager"] = nil - return require("lua/nvimpager") -end +local helpers = require("test/helpers") +local run, read = helpers.run, helpers.read describe("auto mode", function() -- Auto mode only exists during the run of the bash script. At the end of @@ -110,7 +27,7 @@ set -e set -u shopt -s expand_aliases - NVIM=: + NVIMPAGER_NVIM=: alias exec=: alias trap=: source ]] .. command .. "\nset" @@ -159,6 +76,13 @@ assert.equal(expected, output) end) + it("handles color schemes with a non trivial Normal group", function() + local output = run("./nvimpager -c test/fixtures/conceal.tex " .. + "--cmd 'hi Normal ctermfg=Red'") + local expected = read("test/fixtures/conceal.tex.red") + assert.equal(expected, output) + end) + it("highlights all files", function() local output = run("./nvimpager -c test/fixtures/makefile " .. "test/fixtures/help.txt ") @@ -202,6 +126,23 @@ assert.equal(read("test/fixtures/makefile.ansi"), output) end) + describe("can change the default foreground color", function() + for termguicolors, extension in pairs({termguicolors = "red24", notermguicolors = "red"}) do + for _, command in pairs({"--cmd", "-c"}) do + for stdin, redirect in pairs({[false] = "", [true] = "<"}) do + it("with "..command..", setting "..termguicolors..(stdin and " input via stdin" or ""), function() + local script = "./nvimpager -c -- " .. command .. + " 'highlight Normal ctermfg=red guifg=red | set " .. + termguicolors .. "' " .. redirect .. "test/fixtures/plain.txt" + local output = run(script) + local expected = read("test/fixtures/plain." .. extension) + assert.equal(expected, output) + end) + end + end + end + end) + describe("with modeline", function() it("highlights files even after mode line files", function() local output = run("./nvimpager -c test/fixtures/conceal.tex " .. @@ -339,14 +280,14 @@ -- Nvim writes this message to stderr so we have to redirect this. local output = run("./nvimpager -c -- README.md " .. "-c 'echo $NVIM_RPLUGIN_MANIFEST' -c quit 2>&1") - assert.equal(datadir..'/nvimpager/rplugin.vim', output) + assert.equal(helpers.datadir..'/nvimpager/rplugin.vim', output) end) end) describe("lua functions", function() local nvimpager - setup(function() nvimpager = load_nvimpager() end) + setup(function() nvimpager = helpers.load_nvimpager() end) describe("split_rgb_number", function() it("handles numbers from 0 to 16777215", function() @@ -377,7 +318,7 @@ nvim_call_function = function() return 0 end, } local m = mock(api) - local nvimpager = load_nvimpager(api) + local nvimpager = helpers.load_nvimpager(api) nvimpager._testable.init_cat_mode() local escape = nvimpager._testable.group2ansi(100) assert.stub(m.nvim_get_hl_by_id).was.called_with(100, termguicolors) @@ -738,6 +679,13 @@ assert.equal(expected, output) end) + it("can pass though git colors", function() + local output = run("test/fixtures/bin/git ./nvimpager -c " .. + "test/fixtures/difftastic --cmd 'lua nvimpager.git_colors=true'") + local expected = read("test/fixtures/difftastic") + assert.equal(expected, output) + end) + it("handles man #osx_pending", function() local output = run("test/fixtures/bin/man ./nvimpager -c " .. "test/fixtures/man.cat") @@ -745,3 +693,52 @@ assert.equal(expected, output) end) end) + +describe("init files", function() + it("can be specified with -u", function() + local init = os.tmpname() + finally(function() os.remove(init) end) + helpers.write(init, "let g:myvar = 42") + local output = run("./nvimpager -c -- -u " .. init .. + [[ -c 'lua io.write(vim.g.myvar, "\n")' -c qa]]) + assert.equal("42\n", output) + end) + + local function tempdir() + local dir = run("mktemp -d"):sub(1, -2) -- remove the final newline + finally(function() run("rm -r " .. dir) end) + return dir + end + + it("can be init.lua", function() + local dir = tempdir() + run("mkdir -p " .. dir .. "/nvimpager") + helpers.write(dir .. "/nvimpager/init.lua", "vim.g.myvar = 42") + local output = run("XDG_CONFIG_HOME=" .. dir .. + [[ ./nvimpager -c -- -c 'lua io.write(vim.g.myvar, "\n")' -c qa]]) + assert.equal("42\n", output) + end) + + it("can be init.vim", function() + local dir = tempdir() + run("mkdir -p " .. dir .. "/nvimpager") + helpers.write(dir .. "/nvimpager/init.vim", "let myvar = 42") + local output = run("XDG_CONFIG_HOME=" .. dir .. + [[ ./nvimpager -c -- -c 'lua io.write(vim.g.myvar, "\n")' -c qa]]) + assert.equal("42\n", output) + end) + + it("can not coexist (.lua and .vim)", function() + local dir = tempdir() + local conf = dir .. "/nvimpager" + run("mkdir -p " .. conf) + helpers.write(conf .. "/init.lua", "vim.g.myvar = 41") + helpers.write(conf .. "/init.vim", "let myvar = 43") + local output = run("XDG_CONFIG_HOME=" .. dir .. + [[ ./nvimpager -c -- -c 'lua io.write(vim.g.myvar, "\n")' -c qa; + test $? -eq 2]]) + local expected = "Conflicting configs: " .. conf .. "/init.lua " .. + conf .. "/init.vim\n" + assert.equal(expected, output) + end) +end)