summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@osdl.org>2005-12-18 20:15:58 (GMT)
committerJunio C Hamano <junkio@cox.net>2005-12-18 21:53:33 (GMT)
commitea77e675e564211513ebedb4f5bdcda482d7fd30 (patch)
treeb804a7bacbbf43ccc657a71baf58ec15cf7c336c
parentd808111ebdb0b50709527612221eb2970ed6ece9 (diff)
downloadgit-ea77e675e564211513ebedb4f5bdcda482d7fd30.zip
git-ea77e675e564211513ebedb4f5bdcda482d7fd30.tar.gz
git-ea77e675e564211513ebedb4f5bdcda482d7fd30.tar.bz2
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>
-rw-r--r--git.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/git.c b/git.c
index c26cac6..157c549 100644
--- a/git.c
+++ b/git.c
@@ -8,6 +8,7 @@
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
+#include <sys/ioctl.h>
#include "git-compat-util.h"
#ifndef PATH_MAX
@@ -26,6 +27,16 @@ static int term_columns(void)
if (col_string && (n_cols = atoi(col_string)) > 0)
return n_cols;
+#ifdef TIOCGWINSZ
+ {
+ struct winsize ws;
+ if (!ioctl(1, TIOCGWINSZ, &ws)) {
+ if (ws.ws_col)
+ return ws.ws_col;
+ }
+ }
+#endif
+
return 80;
}