Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- cache.h | 1 + help.c | 22 ---------------------- pager.c | 23 +++++++++++++++++++++++ 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/cache.h b/cache.h index 89f6a40..124f100 100644 --- a/cache.h +++ b/cache.h @@ -985,6 +985,7 @@ extern void setup_pager(void); extern const char *pager_program; extern int pager_in_use(void); extern int pager_use_color; +extern int term_columns(); extern const char *editor_program; extern const char *excludes_file; diff --git a/help.c b/help.c index 7f4928e..888bf8c 100644 --- a/help.c +++ b/help.c @@ -4,28 +4,6 @@ #include "levenshtein.h" #include "help.h" -/* most GUI terminals set COLUMNS (although some don't export it) */ -static int term_columns(void) -{ - char *col_string = getenv("COLUMNS"); - int n_cols; - - 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; -} - void add_cmdname(struct cmdnames *cmds, const char *name, int len) { struct cmdname *ent = xmalloc(sizeof(*ent) + len + 1); diff --git a/pager.c b/pager.c index dac358f..fc6c3e0 100644 --- a/pager.c +++ b/pager.c @@ -12,6 +12,7 @@ */ static int spawned_pager; +static int max_columns; #ifndef WIN32 static void pager_preexec(void) @@ -116,3 +117,25 @@ int pager_in_use(void) env = getenv("GIT_PAGER_IN_USE"); return env ? git_config_bool("GIT_PAGER_IN_USE", env) : 0; } + +int term_columns() +{ + char *col_string = getenv("COLUMNS"); + int n_cols; + + if (col_string && (n_cols = atoi(col_string)) > 0) + return n_cols; + + else if (spawned_pager && max_columns) + return max_columns; +#ifdef TIOCGWINSZ + else { + struct winsize ws; + if (!ioctl(1, TIOCGWINSZ, &ws)) { + if (ws.ws_col) + return ws.ws_col; + } + } +#endif + return 80; +} -- 1.7.0.1.370.gd3c5 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html