summarylogtreecommitdiffstats
path: root/progress.patch
blob: 7dea54cf6269fbb0abd3005271f8c796adce8399 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 2823d510..255f68a2 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -155,10 +155,26 @@ static void fill_progress(const int percent, const int proglen)
 	/* 8 = 1 space + 1 [ + 1 ] + 5 for percent */
 	const int hashlen = proglen > 8 ? proglen - 8 : 0;
 	const int hash = percent * hashlen / 100;
+	const char* terms[] = {"xterm-kitty", "st-256color"};
+	char* TERM;
+	int fancy = 0;
 	int i;
 
+	TERM = getenv("TERM");
+	if(TERM != NULL) {
+		for(i = 0; i < sizeof(terms)/sizeof(terms[0]); i++) {
+			if(!strcmp(TERM, terms[i])) {
+				fancy = 1;
+			}
+		}
+	}
+
 	if(hashlen > 0) {
-		fputs(" [", stdout);
+		if(fancy) {
+			fputs(" ", stdout);
+		} else {
+			fputs(" [", stdout);
+		}
 		for(i = hashlen; i > 0; --i) {
 			/* if special progress bar enabled */
 			if(config->chomp) {
@@ -177,12 +193,28 @@ static void fill_progress(const int percent, const int proglen)
 				}
 			} /* else regular progress bar */
 			else if(i > hashlen - hash) {
-				putchar('#');
+				if(fancy) {
+					fputs("", stdout);
+				} else {
+					putchar('#');
+				}
 			} else {
-				putchar('-');
+				if(fancy) {
+					fputs("", stdout);
+				} else {
+					putchar('-');
+				}
+			}
+		}
+		if(fancy){
+			if (hashlen == hash) {
+				fputs("", stdout);
+			} else {
+				fputs("", stdout);
 			}
+		} else {
+			putchar(']');
 		}
-		putchar(']');
 	}
 	/* print display percent after progress bar */
 	/* 5 = 1 space + 3 digits + 1 % */