System information fetch utility with a really cool looking mushroom in it.
1use fmt;
2use strings;
3use shlex;
4use os;
5use io;
6
7fn fgblack(text: str) str = strings::concat("\x1B[30m", text, "\x1B[0m");
8fn fgred(text: str) str = strings::concat("\x1B[31m", text, "\x1B[0m");
9fn fggreen(text: str) str = strings::concat("\x1B[32m", text, "\x1B[0m");
10fn fgyellow(text: str) str = strings::concat("\x1B[33m", text, "\x1B[0m");
11fn fgblue(text: str) str = strings::concat("\x1B[34m", text, "\x1B[0m");
12fn fgmagenta(text: str) str = strings::concat("\x1B[34m", text, "\x1B[0m");
13fn fgcyan(text: str) str = strings::concat("\x1B[35m", text, "\x1B[0m");
14fn fgwhite(text: str) str = strings::concat("\x1B[36m", text, "\x1B[0m");
15
16export fn main() void = {
17 const WM = fgmagenta("WM");
18 defer free(WM);
19
20 const DISTRO = fggreen("Distro");
21 defer free(DISTRO);
22
23 const SHELL = fgblue("Shell");
24 defer free(SHELL);
25
26 const TERM = fgcyan("Term");
27 defer free(TERM);
28
29 let user = match (os::getenv("USER")) {
30 case let u: str => yield u;
31 case void => yield "NONE";
32 };
33 const USER = fgyellow(user);
34 defer free(USER);
35
36 let hostname = os::hostname();
37 const MACHINE = strings::rpad(fgyellow(hostname), ' ', 39 - len(user) - len(hostname));
38 defer free(MACHINE);
39
40 let os_release_path = os::open("/etc/os-release")!;
41 let os_name: [16]u8 = [0...];
42 io::read(os_release_path, os_name)!;
43 let os_name = strings::fromutf8(os_name)!;
44 let os_name = strings::trimprefix(os_name, "NAME=\"");
45 const DISTRO_NAME = strings::rpad(fggreen(os_name), ' ', 21);
46 defer free(DISTRO_NAME);
47
48 let shell = match (os::getenv("SHELL")) {
49 case let s: str => yield s;
50 case void => yield "NONE";
51 };
52 const SHELL_NAME = strings::rpad(fgblue(shell), ' ', 19);
53 defer free(SHELL_NAME);
54
55 let term = match (os::getenv("TERM")) {
56 case let t: str => yield t;
57 case void => yield "NONE";
58 };
59 const TERM_NAME = strings::rpad(fgcyan(term), ' ', 21);
60 defer free(TERM_NAME);
61
62 let wm = match (os::getenv("XDG_DESKTOP_SESSION")) {
63 case let wm: str => yield wm;
64 case void => yield match (os::getenv("DESKTOP_SESSION")) {
65 case let wm: str => yield wm;
66 case void => yield match (os::getenv("WM")) {
67 case let wm: str => yield wm;
68 case void => yield "NONE";
69 };
70 };
71 };
72 const WM_NAME = strings::rpad(fgmagenta(wm), ' ', 20);
73 defer free(WM_NAME);
74
75 const ART = strings::concat(" .-'~~~-.
76 {}@{}.'o ", fgred("oOOOo"), "`.
77 :~~~-.", fgred("oOo"), " o`.
78 {} : {}`. \\ ~-. ", fgred("oOOo"), ".
79 {} : {}`.", fgyellow(";"), " / ~. ", fgred("OO"), ":
80 {} : {}", fgyellow(".' ;"), "-- `.o.'
81 {} : {}", fgyellow(",' ;"), " ~~--'~
82 ", fgyellow("; ;"), "
83___________\\|/__________\\\\", fgyellow(";"), "_\\\\//___\\|/________");
84 defer free(ART);
85 fmt::printf(ART, USER, MACHINE, SHELL, SHELL_NAME, DISTRO, DISTRO_NAME, TERM, TERM_NAME, WM, WM_NAME)!;
86};