Skip to content

Commit 7674896

Browse files
committed
Merge branch 'js/stop-exporting-bogus-columns' into next
When we cannot figure out how wide the terminal is, we use a fallback value of 80 ourselves (which cannot be avoided), but when we run the pager, we export it in COLUMNS, which forces the pager to use the hardcoded value, even when the pager is perfectly capable to figure it out itself. Stop exporting COLUMNS when we fall back on the hardcoded default value for our own use. * js/stop-exporting-bogus-columns: pager: avoid setting COLUMNS when we're guessing its value
2 parents 529d71a + 9b6e2c8 commit 7674896

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

pager.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
static struct child_process pager_process = CHILD_PROCESS_INIT;
1212
static const char *pager_program;
1313

14+
/* Is the value coming back from term_columns() just a guess? */
15+
static int term_columns_guessed;
16+
17+
1418
static void close_pager_fds(void)
1519
{
1620
/* signal EOF to pager */
@@ -114,7 +118,8 @@ void setup_pager(void)
114118
{
115119
char buf[64];
116120
xsnprintf(buf, sizeof(buf), "%d", term_columns());
117-
setenv("COLUMNS", buf, 0);
121+
if (!term_columns_guessed)
122+
setenv("COLUMNS", buf, 0);
118123
}
119124

120125
setenv("GIT_PAGER_IN_USE", "true", 1);
@@ -158,15 +163,20 @@ int term_columns(void)
158163
return term_columns_at_startup;
159164

160165
term_columns_at_startup = 80;
166+
term_columns_guessed = 1;
161167

162168
col_string = getenv("COLUMNS");
163-
if (col_string && (n_cols = atoi(col_string)) > 0)
169+
if (col_string && (n_cols = atoi(col_string)) > 0) {
164170
term_columns_at_startup = n_cols;
171+
term_columns_guessed = 0;
172+
}
165173
#ifdef TIOCGWINSZ
166174
else {
167175
struct winsize ws;
168-
if (!ioctl(1, TIOCGWINSZ, &ws) && ws.ws_col)
176+
if (!ioctl(1, TIOCGWINSZ, &ws) && ws.ws_col) {
169177
term_columns_at_startup = ws.ws_col;
178+
term_columns_guessed = 0;
179+
}
170180
}
171181
#endif
172182

0 commit comments

Comments
 (0)