File tree Expand file tree Collapse file tree 3 files changed +38
-22
lines changed Expand file tree Collapse file tree 3 files changed +38
-22
lines changed Original file line number Diff line number Diff line change @@ -1176,6 +1176,7 @@ extern void setup_pager(void);
1176
1176
extern const char * pager_program ;
1177
1177
extern int pager_in_use (void );
1178
1178
extern int pager_use_color ;
1179
+ extern int term_columns (void );
1179
1180
1180
1181
extern const char * editor_program ;
1181
1182
extern const char * askpass_program ;
Original file line number Diff line number Diff line change 5
5
#include "help.h"
6
6
#include "common-cmds.h"
7
7
8
- /* most GUI terminals set COLUMNS (although some don't export it) */
9
- static int term_columns (void )
10
- {
11
- char * col_string = getenv ("COLUMNS" );
12
- int n_cols ;
13
-
14
- if (col_string && (n_cols = atoi (col_string )) > 0 )
15
- return n_cols ;
16
-
17
- #ifdef TIOCGWINSZ
18
- {
19
- struct winsize ws ;
20
- if (!ioctl (1 , TIOCGWINSZ , & ws )) {
21
- if (ws .ws_col )
22
- return ws .ws_col ;
23
- }
24
- }
25
- #endif
26
-
27
- return 80 ;
28
- }
29
-
30
8
void add_cmdname (struct cmdnames * cmds , const char * name , int len )
31
9
{
32
10
struct cmdname * ent = xmalloc (sizeof (* ent ) + len + 1 );
Original file line number Diff line number Diff line change @@ -76,6 +76,12 @@ void setup_pager(void)
76
76
if (!pager )
77
77
return ;
78
78
79
+ /*
80
+ * force computing the width of the terminal before we redirect
81
+ * the standard output to the pager.
82
+ */
83
+ (void ) term_columns ();
84
+
79
85
setenv ("GIT_PAGER_IN_USE" , "true" , 1 );
80
86
81
87
/* spawn the pager */
@@ -110,3 +116,34 @@ int pager_in_use(void)
110
116
env = getenv ("GIT_PAGER_IN_USE" );
111
117
return env ? git_config_bool ("GIT_PAGER_IN_USE" , env ) : 0 ;
112
118
}
119
+
120
+ /*
121
+ * Return cached value (if set) or $COLUMNS environment variable (if
122
+ * set and positive) or ioctl(1, TIOCGWINSZ).ws_col (if positive),
123
+ * and default to 80 if all else fails.
124
+ */
125
+ int term_columns (void )
126
+ {
127
+ static int term_columns_at_startup ;
128
+
129
+ char * col_string ;
130
+ int n_cols ;
131
+
132
+ if (term_columns_at_startup )
133
+ return term_columns_at_startup ;
134
+
135
+ term_columns_at_startup = 80 ;
136
+
137
+ col_string = getenv ("COLUMNS" );
138
+ if (col_string && (n_cols = atoi (col_string )) > 0 )
139
+ term_columns_at_startup = n_cols ;
140
+ #ifdef TIOCGWINSZ
141
+ else {
142
+ struct winsize ws ;
143
+ if (!ioctl (1 , TIOCGWINSZ , & ws ) && ws .ws_col )
144
+ term_columns_at_startup = ws .ws_col ;
145
+ }
146
+ #endif
147
+
148
+ return term_columns_at_startup ;
149
+ }
You can’t perform that action at this time.
0 commit comments