-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
87 lines (71 loc) · 1.48 KB
/
main.go
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
)
// types {{{
type MemData struct {
MemTotal float64
MemUsed float64
MemShared float64
MemBuffers float64
MemCached float64
MemAvailable float64
MemFree float64
SwapFree float64
SwapUsed float64
SwapTotal float64
}
type DrawData struct {
Buffers int
Cache int
Free int
Shared int
Used int
SwapFree int
SwapUsed int
}
type winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}
// }}}
// args {{{
var (
Version = "[built from source]"
CommitSHA = ""
dispHuman = flag.Bool("h", false, "display human-readable numbers (implies -table)")
dispTable = flag.Bool("table", false, "print table with numbers in addition to the chart")
dispVersion = flag.Bool("version", false, "display version and exit")
)
// }}}
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage:\n %s [options]\n\nOptions:\n", filepath.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if *dispVersion {
fmt.Printf("frei %s", Version)
if CommitSHA != "" {
fmt.Printf(" (commit %s)", CommitSHA)
}
fmt.Print("\n")
os.Exit(0)
}
data, err := GetMemInfo()
if err != nil {
panic("Cannot get memory info")
}
chartWidth := getTerminalWidth() - 2
barWidth := chartWidth - 4 - 5
drawData := calcDrawData(data, barWidth)
printCharts(drawData, chartWidth, barWidth, data)
if *dispTable || *dispHuman {
printTable(data, chartWidth, *dispHuman)
}
}