summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);