summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2007-03-13 16:15:38 +0000
committerDan McGee <dan@archlinux.org>2007-03-13 16:15:38 +0000
commit6e05ad1d24d213d0e84dd69fea40ff20cff22401 (patch)
tree845584ea08fac4bebf96c1ff334e09840363537d /src
parent2020e0ec73bd2e83ff1598492f758a03e7afe586 (diff)
downloadpacman-6e05ad1d24d213d0e84dd69fea40ff20cff22401.tar.xz
* Resizing terminal while progress bars were displayed caused some weird
issues, this should fix it. Progress bars now go from displaying, to showing percent only, to not displaying at all. Changed unsigned -> signed to prevent wraparound errors in integer comparison.
Diffstat (limited to 'src')
-rw-r--r--src/pacman/log.c2
-rw-r--r--src/pacman/util.c76
-rw-r--r--src/pacman/util.h4
3 files changed, 45 insertions, 37 deletions
diff --git a/src/pacman/log.c b/src/pacman/log.c
index 9d719912..ca83df0b 100644
--- a/src/pacman/log.c
+++ b/src/pacman/log.c
@@ -134,7 +134,7 @@ void pm_fprintf(FILE *file, unsigned short line, char *fmt, ...)
fprintf(file, str);
if(needpad == 1) {
- unsigned int i, cols = getcols();
+ int i, cols = getcols();
for(i=len; i < cols; ++i) {
fprintf(file, " ");
}
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 76bbc189..9c79cf5f 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -53,7 +53,7 @@
extern config_t *config;
/* gets the current screen column width */
-unsigned int getcols()
+int getcols()
{
if(!isatty(1)) {
/* We will default to 80 columns if we're not a tty
@@ -161,10 +161,10 @@ int rmrf(char *path)
/* output a string, but wrap words properly with a specified indentation
*/
-void indentprint(const char *str, unsigned int indent)
+void indentprint(const char *str, int indent)
{
const char *p = str;
- unsigned int cidx = indent;
+ int cidx = indent;
while(*p) {
if(*p == ' ') {
@@ -177,9 +177,9 @@ void indentprint(const char *str, unsigned int indent)
next = p + strlen(p);
}
len = next - p;
- if(len > (getcols()-cidx-1)) {
+ if(len > (getcols() - cidx - 1)) {
/* newline */
- unsigned int i;
+ int i;
fprintf(stdout, "\n");
for(i = 0; i < indent; i++) {
fprintf(stdout, " ");
@@ -242,7 +242,7 @@ void list_display(const char *title, alpm_list_t *list)
for(i = list, cols = len; i; i = alpm_list_next(i)) {
char *str = alpm_list_getdata(i);
int s = strlen(str) + 2;
- unsigned int maxcols = getcols();
+ int maxcols = getcols();
if(s + cols >= maxcols) {
int i;
cols = len;
@@ -385,46 +385,55 @@ void fill_progress(const int percent, const int proglen)
static unsigned int lasthash = 0, mouth = 0;
unsigned int i;
+ /* printf("\ndebug: proglen: %i\n", proglen); DEBUG*/
+
if(percent == 0) {
lasthash = 0;
mouth = 0;
}
- printf(" [");
- for(i = hashlen; i > 1; --i) {
- /* if special progress bar enabled */
- if(chomp) {
- if(i > hashlen - hash) {
- printf("-");
- } else if(i == hashlen - hash) {
- if(lasthash == hash) {
- if(mouth) {
- printf("\033[1;33mC\033[m");
+ /* magic numbers, how I loathe thee */
+ if(proglen > 8) {
+ printf(" [");
+ for(i = hashlen; i > 1; --i) {
+ /* if special progress bar enabled */
+ if(chomp) {
+ if(i > hashlen - hash) {
+ printf("-");
+ } else if(i == hashlen - hash) {
+ if(lasthash == hash) {
+ if(mouth) {
+ printf("\033[1;33mC\033[m");
+ } else {
+ printf("\033[1;33mc\033[m");
+ }
} else {
- printf("\033[1;33mc\033[m");
+ lasthash = hash;
+ mouth = mouth == 1 ? 0 : 1;
+ if(mouth) {
+ printf("\033[1;33mC\033[m");
+ } else {
+ printf("\033[1;33mc\033[m");
+ }
}
+ } else if(i%3 == 0) {
+ printf("\033[0;37mo\033[m");
} else {
- lasthash = hash;
- mouth = mouth == 1 ? 0 : 1;
- if(mouth) {
- printf("\033[1;33mC\033[m");
- } else {
- printf("\033[1;33mc\033[m");
- }
+ printf("\033[0;37m \033[m");
}
- } else if(i%3 == 0) {
- printf("\033[0;37mo\033[m");
+ } /* else regular progress bar */
+ else if(i > hashlen - hash) {
+ printf("#");
} else {
- printf("\033[0;37m \033[m");
+ printf("-");
}
- } /* else regular progress bar */
- else if(i > hashlen - hash) {
- printf("#");
- } else {
- printf("-");
}
+ printf("]");
+ }
+ /* print percent after progress bar */
+ if(proglen > 5) {
+ printf(" %3d%%", percent);
}
- printf("] %3d%%", percent);
if(percent == 100) {
printf("\n");
@@ -434,5 +443,4 @@ void fill_progress(const int percent, const int proglen)
fflush(stdout);
}
-
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/util.h b/src/pacman/util.h
index 5ff08212..6eba38fe 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -50,10 +50,10 @@
#define UPDATE_SPEED_SEC 0.2f
#define _(str) gettext(str)
-unsigned int getcols();
+int getcols();
int makepath(char *path);
int rmrf(char *path);
-void indentprint(const char *str, unsigned int indent);
+void indentprint(const char *str, int indent);
char *strtoupper(char *str);
char *strtrim(char *str);
int reg_match(char *string, char *pattern);