@@ -49,7 +49,11 @@ func drawBar(width int, number float64) string {
4949// }}}
5050
5151// printCharts() {{{
52- func printCharts (data DrawData , chartWidth int , barWidth int , stats MemData ) {
52+ func printCharts (stats MemData ) {
53+ chartWidth := getTerminalWidth () - 2
54+ barWidth := chartWidth - 4 - 5
55+ data := calcDrawData (stats , barWidth )
56+
5357 // head
5458 fmt .Println (" ╭" + strings .Repeat ("─" , chartWidth - 2 ) + "╮" )
5559
@@ -82,67 +86,3 @@ func printCharts(data DrawData, chartWidth int, barWidth int, stats MemData) {
8286}
8387
8488// }}}
85-
86- // printNumbers() {{{
87- func printTable (data MemData , chartWidth int , human bool ) {
88- if chartWidth > 40 {
89- chartWidth = 40
90- }
91-
92- labels := [10 ]string {
93- "Total" ,
94- "Used" ,
95- "Shared" ,
96- "Buffers" ,
97- "Cache" ,
98- "Available" ,
99- "Free" ,
100- "Swap Total" ,
101- "Swap Used" ,
102- "Swap Free" ,
103- }
104- values := [10 ]string {
105- toHumanStr (data .MemTotal , human ),
106- toHumanStr (data .MemUsed , human ),
107- toHumanStr (data .MemShared , human ),
108- toHumanStr (data .MemBuffers , human ),
109- toHumanStr (data .MemCached , human ),
110- toHumanStr (data .MemAvailable , human ),
111- toHumanStr (data .MemFree , human ),
112- toHumanStr (data .SwapTotal , human ),
113- toHumanStr (data .SwapUsed , human ),
114- toHumanStr (data .SwapFree , human ),
115- }
116- colors := [10 ]string {
117- "\033 [1m" ,
118- "\033 [32m" ,
119- "\033 [35m" ,
120- "\033 [34m" ,
121- "\033 [33m" ,
122- "" ,
123- "" ,
124- "" ,
125- "" ,
126- "" ,
127- }
128-
129- // head
130- fmt .Println (" ╭─────────────┬" + strings .Repeat ("─" , chartWidth - 16 ) + "╮" )
131-
132- // body
133- for i := 0 ; i < len (labels ); i ++ {
134- // separator before swap
135- if i == len (labels )- 3 {
136- fmt .Println (" ├─────────────┼" + strings .Repeat ("─" , chartWidth - 16 ) + "┤" )
137- }
138-
139- spacesNumberLabel := 10 - len (labels [i ])
140- spacesNumberValue := chartWidth - 19 - len (values [i ])
141- fmt .Printf (" │ %s%s\033 [0m%s │ %s %s │\n " , colors [i ], labels [i ], strings .Repeat (" " , spacesNumberLabel ), strings .Repeat (" " , spacesNumberValue ), values [i ])
142- }
143-
144- // tail
145- fmt .Println (" ╰─────────────┴" + strings .Repeat ("─" , chartWidth - 16 ) + "╯" )
146- }
147-
148- // }}}
0 commit comments