Skip to content

Commit be11f7a

Browse files
peffgitster
authored andcommitted
pager: set COLUMNS to term_columns()
After we invoke the pager, our stdout goes to a pipe, not the terminal, meaning we can no longer use an ioctl to get the terminal width. For that reason, ad6c373 (pager: find out the terminal width before spawning the pager, 2012-02-12) started caching the terminal width. But that cache is only an in-process variable. Any programs we spawn will also not be able to run that ioctl, but won't have access to our cache. They'll end up falling back to our 80-column default. You can see the problem with: git tag --column=row Since git-tag spawns a pager these days, its spawned git-column helper will see neither the terminal on stdout nor a useful COLUMNS value (assuming you do not export it from your shell already). And you'll end up with 80-column output in the pager, regardless of your terminal size. We can fix this by setting COLUMNS right before spawning the pager. That fixes this case, as well as any more complicated ones (e.g., a paged program spawns another script which then generates columnized output). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 468165c commit be11f7a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pager.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,15 @@ void setup_pager(void)
109109
return;
110110

111111
/*
112-
* force computing the width of the terminal before we redirect
113-
* the standard output to the pager.
112+
* After we redirect standard output, we won't be able to use an ioctl
113+
* to get the terminal size. Let's grab it now, and then set $COLUMNS
114+
* to communicate it to any sub-processes.
114115
*/
115-
(void) term_columns();
116+
{
117+
char buf[64];
118+
xsnprintf(buf, sizeof(buf), "%d", term_columns());
119+
setenv("COLUMNS", buf, 0);
120+
}
116121

117122
setenv("GIT_PAGER_IN_USE", "true", 1);
118123

0 commit comments

Comments
 (0)