|
11 | 11 | static struct child_process pager_process = CHILD_PROCESS_INIT;
|
12 | 12 | static const char *pager_program;
|
13 | 13 |
|
| 14 | +/* Is the value coming back from term_columns() just a guess? */ |
| 15 | +static int term_columns_guessed; |
| 16 | + |
| 17 | + |
14 | 18 | static void close_pager_fds(void)
|
15 | 19 | {
|
16 | 20 | /* signal EOF to pager */
|
@@ -114,7 +118,8 @@ void setup_pager(void)
|
114 | 118 | {
|
115 | 119 | char buf[64];
|
116 | 120 | xsnprintf(buf, sizeof(buf), "%d", term_columns());
|
117 |
| - setenv("COLUMNS", buf, 0); |
| 121 | + if (!term_columns_guessed) |
| 122 | + setenv("COLUMNS", buf, 0); |
118 | 123 | }
|
119 | 124 |
|
120 | 125 | setenv("GIT_PAGER_IN_USE", "true", 1);
|
@@ -158,15 +163,20 @@ int term_columns(void)
|
158 | 163 | return term_columns_at_startup;
|
159 | 164 |
|
160 | 165 | term_columns_at_startup = 80;
|
| 166 | + term_columns_guessed = 1; |
161 | 167 |
|
162 | 168 | col_string = getenv("COLUMNS");
|
163 |
| - if (col_string && (n_cols = atoi(col_string)) > 0) |
| 169 | + if (col_string && (n_cols = atoi(col_string)) > 0) { |
164 | 170 | term_columns_at_startup = n_cols;
|
| 171 | + term_columns_guessed = 0; |
| 172 | + } |
165 | 173 | #ifdef TIOCGWINSZ
|
166 | 174 | else {
|
167 | 175 | struct winsize ws;
|
168 |
| - if (!ioctl(1, TIOCGWINSZ, &ws) && ws.ws_col) |
| 176 | + if (!ioctl(1, TIOCGWINSZ, &ws) && ws.ws_col) { |
169 | 177 | term_columns_at_startup = ws.ws_col;
|
| 178 | + term_columns_guessed = 0; |
| 179 | + } |
170 | 180 | }
|
171 | 181 | #endif
|
172 | 182 |
|
|
0 commit comments