@matheusbsbs / matheus-bagliano / commits / ea77e675e5
Fork 0

Make "git help" react to window size correctly

Currently the git "show commands" function will react to the environment variable COLUMNS, or just default to a width of 80 characters. That's just soo eighties. Nobody sane sets COLUMNS any more, unless they need to support some stone-age software from before the age of steam engines, SIGWINCH and TIOCGWINSZ. So get with the new century, and use TIOCGWINSZ to get the terminal size. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Dec 18, 2005 at 12:15 UTC ea77e675e564211513ebedb4f5bdcda482d7fd30
1 file changed +11
git.c
+11
@@ -8,6 +8,7 @@
8 #include <errno.h>
9 #include <limits.h>
10 #include <stdarg.h>
11 +#include <sys/ioctl.h>
12 #include "git-compat-util.h"
13
14 #ifndef PATH_MAX
@@ -26,6 +27,16 @@ static int term_columns(void)
27 if (col_string && (n_cols = atoi(col_string)) > 0)
28 return n_cols;
29
30 +#ifdef TIOCGWINSZ
31 + {
32 + struct winsize ws;
33 + if (!ioctl(1, TIOCGWINSZ, &ws)) {
34 + if (ws.ws_col)
35 + return ws.ws_col;
36 + }
37 + }
38 +#endif
39 +
40 return 80;
41 }
42