Explorar el Código

Adding colors using tput

Pierre V hace 8 años
padre
commit
44b8a16323
Se han modificado 1 ficheros con 33 adiciones y 27 borrados
  1. 33
    27
      pert

+ 33
- 27
pert Ver fichero

@@ -2,7 +2,7 @@
2 2
 set -o nounset
3 3
 set -o errexit
4 4
 
5
-function _echo 
5
+function _echo
6 6
 {
7 7
     echo -e "$1"
8 8
 }
@@ -12,6 +12,11 @@ function _echoB
12 12
     _echo "\033[1m$1\033[0m"
13 13
 }
14 14
 
15
+red=$(tput setaf 1)
16
+green=$(tput setaf 2)
17
+yellow=$(tput setaf 3)
18
+normal=$(tput sgr0)
19
+
15 20
 function _help
16 21
 {
17 22
     _echo ""
@@ -29,7 +34,7 @@ function _help
29 34
 }
30 35
 
31 36
 scale=2
32
-function _calc 
37
+function _calc
33 38
 {
34 39
     _echo "scale=$scale; $@" | bc -l | sed 's/^\./0./'
35 40
 }
@@ -42,7 +47,7 @@ function _divider
42 47
     printf "%$width.${width}s+\n" "$divider"
43 48
 }
44 49
 
45
-readonly format=" | %-12s |%11s |%10s |%12s |%9s |%9s |%9s |\n"
50
+readonly format=" | %-12s |${green}%11s${normal} |%10s |${red}%12s${normal} |%9s |${yellow}%9s${normal} |%9s |\n"
46 51
 function _header
47 52
 {
48 53
     _echo ""
@@ -53,78 +58,79 @@ function _header
53 58
     _divider
54 59
 }
55 60
 
61
+
56 62
 function pert_table
57 63
 {
58 64
     _header
59
-    
65
+
60 66
     counter=0
61 67
     total_estimate=0
62 68
     total_standard_deviation=0
63 69
     total_variance=0
64 70
     for var in "$@"; do
65
-        
71
+
66 72
         # counter iterator
67 73
         counter=$[$counter +1]
68
-    
74
+
69 75
         # split values
70 76
         IFS=',' read -ra ADDR <<< "$var"
71
-        
77
+
72 78
         # optimistic value
73 79
         o="0"
74 80
         if [ -n "${ADDR[0]-}" ]; then
75 81
             o=${ADDR[0]}
76 82
         fi
77
-        
83
+
78 84
         # realistic value
79 85
         r="0"
80 86
         if [ -n "${ADDR[1]-}" ]; then
81 87
             r=${ADDR[1]}
82 88
         fi
83
-        
89
+
84 90
         # pessimistic value
85 91
         p="0"
86 92
         if [ -n "${ADDR[2]-}" ]; then
87 93
             p=${ADDR[2]}
88 94
         fi
89
-        
95
+
90 96
         # check values
91 97
         if [ -z "$o" ] || [ -z "$r" ] || [ -z "$p" ]; then
92 98
             printf "$format" "$counter. bad input" $o $r $p
93 99
         else
94
-        
100
+
95 101
             # pert estimate
96 102
             pert_estimate=$(_calc "($o+4*$r+$p)/6")
97
-            total_estimate=$(_calc "$total_estimate + $pert_estimate") 
98
-            
103
+            total_estimate=$(_calc "$total_estimate + $pert_estimate")
104
+
99 105
             # standard deviation
100 106
             standard_deviation=$(_calc "($p-$o)/6")
101 107
             total_standard_deviation=$(_calc "$total_standard_deviation + $standard_deviation")
102
-    
108
+
103 109
             # variance
104 110
             variance=$(_calc "$standard_deviation * $standard_deviation")
105 111
             total_variance=$(_calc "$total_variance + $variance")
106
-        
107
-            # row        
112
+
113
+            # row
108 114
             printf "$format" "$counter. task" $o $r $p $pert_estimate $standard_deviation $variance
109 115
         fi
110
-    
116
+
111 117
     done
112
-    
118
+
113 119
     _divider
114
-    
120
+
115 121
     if [[ $total_estimate > 0 ]]; then
116
-        
117
-        # footer summary       
122
+
123
+        # footer summary
118 124
         printf "$format" "summary" "-" "-" "-" $total_estimate $total_standard_deviation $total_variance
119 125
         _divider
120
-        
126
+
121 127
         _echo ""
122 128
         _echoB "Three point estimates"
123 129
         _echo ""
124
-        
125
-        width=42 
130
+
131
+        width=42
126 132
         tpeformat=" | %-13s |%11s |%10s |\n"
127
-        
133
+
128 134
         _divider
129 135
         printf "$tpeformat" "confidence"
130 136
         _divider
@@ -132,9 +138,9 @@ function pert_table
132 138
         printf "$tpeformat" "2 Sigma - 95%" $(_calc "$total_estimate - 2 * $total_standard_deviation") $(_calc "$total_estimate + 2 * $total_standard_deviation")
133 139
         printf "$tpeformat" "3 Sigma - 99%" $(_calc "$total_estimate - 3 * $total_standard_deviation") $(_calc "$total_estimate + 3 * $total_standard_deviation")
134 140
         _divider
135
-    
141
+
136 142
     fi
137
-    
143
+
138 144
     _echo ""
139 145
 }
140 146
 

Loading…
Cancelar
Guardar