Skip to content

The pager

By the end of this chapter you know where -p sends the page, what the receiving pager is actually handed in each situation, and how the lab proved it without photographing anything.

What -p does

glow -p file.md renders the document and hands the result to a pager program instead of printing it. The pager is the program named by the PAGER environment variable when that is set; the project documents the default as less -r — less told to let colour codes through. A pager session is interactive: scroll with the arrow keys or space, search with /, quit with q.

An interactive session leaves nothing behind to check, so the lab proved the handover by substitution: it set PAGER to a stand-in script — a "pager spy" that records being called and saves everything it is handed (glow-lab/pager-spy.sh). The spy's evidence (transcript glow-lab/transcripts/t03-pager.txt):

  • With -p and stdout redirected to a file, the pager still ran. Glow's own stdout received 0 bytes; the spy received the whole document — 798 bytes, the plain notty rendering, because off a terminal that is what a pager gets.
  • With -p on a terminal, the spy received 9,212 bytes holding 1,196 ESC bytes — the full coloured rendering of the same document.
  • In both cases the pager was called with no arguments at all: Glow writes the rendering to the pager's standard input. That is why the default has to be an ANSI-aware less: a pager that treats its input as raw text to escape would show you the colour codes instead of the page.

The lab also ran the real default once: on its answering pretend terminal with PAGER unset, -p opened the document full-screen in less and closed on q, as documented. A live less session beyond that is driven by hand and leaves no record; this guide claims no more for it than that.

Pager, permanently

If you always want the pager, the configuration file has a pager: true setting (chapter 12). One run at a time, -p is the switch. And notice the difference between the two pagers Glow offers: -p hands the page to your pager, an external program with your settings and your habits; -t opens Glow's own pager (chapter 11), which trades that familiarity for rendering at your window's width and a header that names the file.

Check: set PAGER=cat for one run — PAGER=cat glow -p file.md — and the "pager" simply prints the coloured rendering to your terminal, proving the handover is to whatever PAGER names. Then unset it and take the real less ride. If both match, you have this chapter.