chore: added palette
6621297b
3 file(s) · +59 −18
| 2 | 2 | ||
| 3 | 3 | import ( |
|
| 4 | 4 | "fmt" |
|
| 5 | - | "math/rand" |
|
| 6 | - | "time" |
|
| 7 | 5 | ) |
|
| 8 | 6 | ||
| 9 | 7 | const ( |
|
| 10 | - | Reset = "\033[0m" |
|
| 11 | - | Bold = "\033[1m" |
|
| 12 | - | Red = "\033[31m" |
|
| 13 | - | Green = "\033[32m" |
|
| 14 | - | Blue = "\033[34m" |
|
| 15 | - | Cyan = "\033[36m" |
|
| 8 | + | Reset = "\033[0m" |
|
| 9 | + | Bold = "\033[1m" |
|
| 10 | + | Red = "\033[31m" |
|
| 11 | + | Green = "\033[32m" |
|
| 12 | + | Yellow = "\033[33m" |
|
| 13 | + | Blue = "\033[34m" |
|
| 14 | + | Magenta = "\033[35m" |
|
| 15 | + | Cyan = "\033[36m" |
|
| 16 | + | White = "\033[37m" |
|
| 17 | + | Gray = "\033[90m" |
|
| 16 | 18 | ) |
|
| 17 | 19 | ||
| 18 | - | type Row struct { |
|
| 19 | - | Key string |
|
| 20 | - | Value string |
|
| 20 | + | type Color struct { |
|
| 21 | + | Name string |
|
| 22 | + | Code string |
|
| 23 | + | } |
|
| 24 | + | ||
| 25 | + | var Palette = []Color{ |
|
| 26 | + | {"Red", Red}, |
|
| 27 | + | {"Green", Green}, |
|
| 28 | + | {"Yellow", Yellow}, |
|
| 29 | + | {"Blue", Blue}, |
|
| 30 | + | {"Magenta", Magenta}, |
|
| 31 | + | {"Cyan", Cyan}, |
|
| 32 | + | {"White", White}, |
|
| 33 | + | {"Gray", Gray}, |
|
| 21 | 34 | } |
|
| 22 | 35 | ||
| 23 | 36 | func Colorize(color, s string) string { |
|
| 29 | 42 | ||
| 30 | 43 | fmt.Println() |
|
| 31 | 44 | for _, row := range rows { |
|
| 32 | - | label := Colorize(Bold+Green, fmt.Sprintf("%-*s", width, row.Key)) |
|
| 45 | + | label := Colorize(Bold+Yellow, fmt.Sprintf("%-*s", width, row.Key)) |
|
| 33 | 46 | line := " " + label + " " + row.Value |
|
| 34 | 47 | ||
| 35 | 48 | fmt.Println(line) |
|
| 46 | 59 | } |
|
| 47 | 60 | return width |
|
| 48 | 61 | } |
|
| 62 | + | ||
| 63 | + | func PrintPalette() { |
|
| 64 | + | fmt.Print(" ") |
|
| 65 | + | for _, c := range Palette { |
|
| 66 | + | swatch := Colorize(c.Code, "● ") |
|
| 67 | + | fmt.Print(swatch) |
|
| 68 | + | } |
|
| 69 | + | fmt.Println() |
|
| 70 | + | } |
|
| 4 | 4 | "bufio" |
|
| 5 | 5 | "fmt" |
|
| 6 | 6 | "os" |
|
| 7 | + | "path/filepath" |
|
| 7 | 8 | "strconv" |
|
| 8 | 9 | "strings" |
|
| 9 | 10 | "syscall" |
|
| 10 | 11 | "time" |
|
| 11 | - | "path/filepath" |
|
| 12 | 12 | ) |
|
| 13 | + | ||
| 14 | + | type Row struct { |
|
| 15 | + | Key string |
|
| 16 | + | Value string |
|
| 17 | + | } |
|
| 13 | 18 | ||
| 14 | 19 | func GetHostname() Row { |
|
| 15 | 20 | hostname, err := os.Hostname() |
|
| 93 | 98 | return Row{Key: "Packages", Value: packages} |
|
| 94 | 99 | } |
|
| 95 | 100 | ||
| 101 | + | func GetDe() Row { |
|
| 102 | + | var de string |
|
| 103 | + | de = os.Getenv("DESKTOP_SESSION") |
|
| 104 | + | if de == "" { |
|
| 105 | + | de = "Unknown" |
|
| 106 | + | } |
|
| 107 | + | return Row{Key: "DE", Value: de} |
|
| 108 | + | } |
|
| 109 | + | ||
| 96 | 110 | func GetShell() Row { |
|
| 97 | 111 | var shell string |
|
| 98 | 112 | shellEnv := os.Getenv("SHELL") |
|
| 122 | 136 | cpu = strings.TrimPrefix(cleanSpace, ": ") |
|
| 123 | 137 | } |
|
| 124 | 138 | } |
|
| 125 | - | return Row{Key: "CPU", Value: cpu} |
|
| 139 | + | return Row{Key: "CPU", Value: cpu} |
|
| 126 | 140 | } |
|
| 127 | 141 | ||
| 128 | 142 | func GetMemory() Row { |
|
| 175 | 189 | ||
| 176 | 190 | uptimeValues := time.Duration(float64(si.Uptime) * float64(time.Second)) |
|
| 177 | 191 | ||
| 178 | - | hours := int(uptimeValues.Hours()) |
|
| 192 | + | days := int(uptimeValues.Hours() / 24) |
|
| 193 | + | hours := int(uptimeValues.Hours()) % 24 |
|
| 179 | 194 | minutes := int(uptimeValues.Minutes()) % 60 |
|
| 180 | 195 | ||
| 181 | - | uptime = fmt.Sprintf("%d hours, %d mins", hours, minutes) |
|
| 196 | + | if days > 0 { |
|
| 197 | + | uptime = fmt.Sprintf("%d days, %d hours, %d mins", days, hours, minutes) |
|
| 198 | + | } else { |
|
| 199 | + | uptime = fmt.Sprintf("%d hours, %d mins", hours, minutes) |
|
| 200 | + | } |
|
| 182 | 201 | return Row{Key: "Uptime", Value: uptime} |
|
| 183 | 202 | } |
|
| 12 | 12 | system.GetMachine(), |
|
| 13 | 13 | system.GetKernel(), |
|
| 14 | 14 | system.GetDistro(), |
|
| 15 | - | // DE |
|
| 15 | + | system.GetDe(), |
|
| 16 | 16 | system.GetPackages(), |
|
| 17 | 17 | system.GetShell(), |
|
| 18 | 18 | system.GetCpu(), |
|
| 19 | 19 | system.GetMemory(), |
|
| 20 | 20 | system.GetUptime(), |
|
| 21 | - | // Colors |
|
| 22 | 21 | } |
|
| 23 | 22 | system.PrintRows(rows) |
|
| 23 | + | system.PrintPalette() |
|
| 24 | 24 | } |
|
| 25 | 25 |