From: Linus Torvalds Date: Sun, 18 Dec 2005 20:15:58 +0000 (-0800) Subject: Make "git help" react to window size correctly X-Git-Tag: v1.0.0^2~18 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ea77e675e564211513ebedb4f5bdcda482d7fd30;p=git.git 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 Signed-off-by: Junio C Hamano --- diff --git a/git.c b/git.c index c26cac65..157c5491 100644 --- a/git.c +++ b/git.c @@ -8,6 +8,7 @@ #include #include #include +#include #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; }