diff options
author | Aaron Griffin <aaron@archlinux.org> | 2006-11-22 04:53:10 +0000 |
---|---|---|
committer | Aaron Griffin <aaron@archlinux.org> | 2006-11-22 04:53:10 +0000 |
commit | 54691771831c97c7366bf8ee7c54da3952c22120 (patch) | |
tree | 6db658673d8009bb798c7c053621d431d171c891 /src/pacman/util.c | |
parent | 3c7f616805b4e7b29a1b5ef8cf218627c9da34bd (diff) | |
download | pacman-54691771831c97c7366bf8ee7c54da3952c22120.tar.xz |
Removed global maxcols - it is looked up on the fly now, so the progress bar is
resized. Also used ioctl in place of the COLUMNS env variable
Diffstat (limited to 'src/pacman/util.c')
-rw-r--r-- | src/pacman/util.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/pacman/util.c b/src/pacman/util.c index 68f39e38..c6841e16 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -24,6 +24,9 @@ #include <sys/stat.h> #endif +#include <sys/types.h> +#include <sys/ioctl.h> + #include "config.h" #include <stdio.h> #include <stdlib.h> @@ -45,18 +48,33 @@ #include "conf.h" #include "log.h" -extern int maxcols; extern config_t *config; extern int neednl; /* gets the current screen column width */ int getcols() { +#ifdef TIOCGSIZE + struct ttysize win; + if(ioctl(1, TIOCGSIZE, &win) == 0) { + return win.ts_cols; + } +#elif defined(TIOCGWINSZ) + struct winsize win; + if(ioctl(1, TIOCGWINSZ, &win) == 0) { + return win.ws_col; + } +#endif + else { + return -1; + } + /* Original envvar way - prone to display issues const char *cenv = getenv("COLUMNS"); if(cenv != NULL) { return atoi(cenv); } return -1; + */ } /* does the same thing as 'mkdir -p' */ @@ -152,7 +170,7 @@ void indentprint(const char *str, int indent) next = p + strlen(p); } len = next - p; - if(len > (maxcols-cidx-1)) { + if(len > (getcols()-cidx-1)) { /* newline */ int i; fprintf(stdout, "\n"); |