Repository navigation
Add --pager flag to pipe output into a pager - #376
Merged
Merged
Conversation
jojinkb
requested review from
floryut,
rkmathi,
superbrothers and
tksm
as code owners
July 25, 2026 10:20
Piping stern into a pager in the shell loses colors unless you type `stern <args> --color=always | less -R` every time. The new --pager flag makes stern spawn the pager itself, so colors are preserved with the default --color=auto because stern remains attached to the terminal. The pager is used only when the standard output is a terminal, so redirects and scripts are unaffected even when `pager` is set in the config file. It runs with LESS=FRX and LV=-c set (unless already set), following git's pager defaults, so `--pager less` shows colors out of the box. When the pager exits, stern stops tailing and exits; when all logs have been shown (e.g. --no-follow), stern keeps the pager open until the user quits it. Closes stern#345 Signed-off-by: Jojin <[email protected]>
superbrothers
force-pushed
the
345-pager
branch
from
October 18, 2026 06:29
193a2bf to
defb85a
Compare
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Adds an opt-in
--pagerflag that makes stern pipe its output into a pager command (e.g.less), as requested in #345.Since stern spawns the pager itself and stays attached to the terminal, colors are preserved with the default
--color=auto— no more typingstern <args> --color=always | less -R. Like every other flag, it can be set permanently in the config file:Closes #345
Behavior details
batandgh), so redirects and scripts are unaffected even whenpageris set in the config file.LESS=FRXandLV=-cunless those variables are already set (same defaults as git), so plainlessshows raw ANSI colors, quits if the output fits on one screen, and doesn't clear the screen on exit.qinless), the root context is canceled so stern stops tailing and exits cleanly instead of writing into a broken pipe.Tail.Startalready treatscontext.Canceledas a normal stop, so no changes to thesternpackage were needed.--no-followkeeps the pager open: once all logs have been shown, stern closes the pipe (EOF) and waits for the pager, so you can keep browsing until you quit.github.com/kballard/go-shellquote(promoted from an indirect to a direct dependency;go.sumunchanged), so--pager 'less -S'works.--prompthandler so the two don't conflict, and stderr (the+/-tail markers and errors) intentionally bypasses the pager, matchingstern | lesssemantics.$PAGERenvironment fallback or abat-style--paging=auto|always|nevermode, I'm happy to extend it — kept the first iteration minimal on purpose.How to validate
Unit tests cover the pager lifecycle (output piped through, context canceled on pager exit, error cases,
LESS/LVenvironment handling, tty detection):Interactively, with any cluster:
Without a cluster (pager engages only on a terminal;
--stdinmode uses the same output path):README.mdwas regenerated withmake update-readme, and a "Using a pager" section documents the feature.