|
1 |
| -#define OS_NAME "$TX+CX,"TempleOS",D="DD_OS_NAME_VERSION"$" |
2 |
| - |
3 |
| -U8 buf[256]; |
4 |
| -U8* screenfetch_dir = __DIR__; |
5 |
| - |
6 |
| -U0 Line(U8* label=NULL, U8* value=NULL) { |
7 |
| - " "; |
8 |
| - |
9 |
| - if (label) |
10 |
| - "$FG,3$%s", label; |
11 |
| - |
12 |
| - if (label && value) |
13 |
| - "" ": "; |
14 |
| - |
15 |
| - if (value) |
16 |
| - "$FG,8$%s", value; |
17 |
| - |
18 |
| - '' '\n'; |
19 |
| -} |
20 |
| - |
21 |
| -I64 GetNumFilesInDirectory(U8* dir) { |
22 |
| - CDirEntry* de; |
23 |
| - try { |
24 |
| - de = FilesFind(dir); |
25 |
| - } |
26 |
| - catch { |
27 |
| - de = NULL; |
28 |
| - } |
29 |
| - |
30 |
| - if (!de) |
31 |
| - return -1; |
32 |
| - |
33 |
| - I64 count = 0; |
34 |
| - |
35 |
| - CDirEntry* de2 = de; |
36 |
| - while (de2) { |
37 |
| - if (!(de2->attr & RS_ATTR_DIR)) { |
38 |
| - count++; |
39 |
| - } |
40 |
| - de2 = de2->next; |
41 |
| - } |
42 |
| - |
43 |
| - DirTreeDel(de); |
44 |
| - return count; |
45 |
| -} |
46 |
| - |
47 |
| -CHashFun* FindFunction(U8* name) { |
48 |
| - CHash* result = HashFind(name, Fs->hash_table, HTT_FUN); |
49 |
| - |
50 |
| - if (result && (result->type & HTT_FUN) != 0) |
51 |
| - return result(CHashFun *); |
52 |
| - else |
53 |
| - return NULL; |
54 |
| -} |
55 |
| - |
56 |
| -U8* DetectCPU() { |
57 |
| - StrPrint(buf, "%d core(s)", mp_cnt); |
58 |
| - return buf; |
59 |
| -} |
60 |
| - |
61 |
| -U8* DetectFont() { |
62 |
| - // FIXME: Actually detect - but how? |
63 |
| - // If there was something like a global hash-table, |
64 |
| - // we could use it to mark user Fonts & Palettes |
65 |
| - return "FontStd.HC"; |
66 |
| -} |
67 |
| - |
68 |
| -U8* DetectNumPackages() { |
69 |
| - I64 num_packages = GetNumFilesInDirectory("::/Misc/Packages"); |
70 |
| - |
71 |
| - if (num_packages < 0) |
72 |
| - num_packages = 0; |
73 |
| - |
74 |
| - StrPrint(buf, "%d", num_packages); |
75 |
| - return buf; |
76 |
| -} |
77 |
| - |
78 |
| -U8* DetectRAM() { |
79 |
| - I64 ram_used = sys_code_bp->used_u8s; |
80 |
| - I64 ram_total = sys_code_bp->alloced_u8s; |
81 |
| - if (sys_data_bp) { |
82 |
| - ram_used += sys_data_bp->used_u8s; |
83 |
| - ram_total += sys_data_bp->alloced_u8s; |
84 |
| - } |
85 |
| - StrPrint(buf, "%dMiB / %dMiB", ram_used / (1024 * 1024), ram_total / (1024 * 1024)); |
86 |
| - return buf; |
87 |
| -} |
88 |
| - |
89 |
| -U8* DetectPalette() { |
90 |
| - // FIXME: Actually detect - but how? |
91 |
| - // See comment in DetectFont |
92 |
| - return "PalUbuntu.HC"; |
93 |
| -} |
94 |
| - |
95 |
| -U8* DetectShell() { |
96 |
| - if (FindFunction("Lsh")) |
97 |
| - return "Lsh"; |
98 |
| - else if (FindFunction("TempleShell")) |
99 |
| - return "TempleShell"; |
100 |
| - else if (FindFunction("UserCmdLine")) |
101 |
| - return "UserCmdLine"; |
102 |
| - else |
103 |
| - return "unknown"; |
104 |
| -} |
105 |
| - |
106 |
| -U8* DetectUptime() { |
107 |
| - F64 uptime = tS; |
108 |
| - I64 uptime_min = ToI64(uptime) / 60; |
109 |
| - I64 uptime_sec = ToI64(uptime) % 60; |
110 |
| - StrPrint(buf, "%dm %ds", uptime_min, uptime_sec); |
111 |
| - return buf; |
112 |
| -} |
113 |
| - |
114 |
| -U0 Screenfetch() { |
115 |
| - Line(); |
116 |
| - |
117 |
| - U8* logo_path = MStrPrint("%s/Logo128x152.bmp", screenfetch_dir); |
118 |
| - DocBMP(DocPut, logo_path); |
119 |
| - Free(logo_path); |
120 |
| - |
121 |
| - Line(); |
122 |
| - Line(); |
123 |
| - StrPrint(buf, "singleuser@%s", DirCur); |
124 |
| - Line(buf, ""); |
125 |
| - Line(); |
126 |
| - Line(); |
127 |
| - Line("OS", OS_NAME); |
128 |
| - Line("Kernel", "TempleOS"); |
129 |
| - Line("Uptime", DetectUptime()); |
130 |
| - Line("Packages", DetectNumPackages()); |
131 |
| - Line("Shell", DetectShell()); |
132 |
| - Line("Resolution", "640x480"); |
133 |
| - Line("DE", "Not Present"); |
134 |
| - Line("WM", "Default"); |
135 |
| - Line("Palette", DetectPalette()); |
136 |
| - Line("Font", DetectFont()); |
137 |
| - Line("CPU", DetectCPU()); |
138 |
| - Line("RAM", DetectRAM()); |
139 |
| - Line(); |
140 |
| - Line(); |
141 |
| - Line(); |
142 |
| -} |
| 1 | +// vim: set ft=cpp: |
| 2 | + |
| 3 | +#define OS_NAME "$TX+CX,"TempleOS",D="DD_OS_NAME_VERSION"$" |
| 4 | + |
| 5 | +U8 buf[256]; |
| 6 | +U8* screenfetch_dir = __DIR__; |
| 7 | + |
| 8 | +U0 Line(U8* label=NULL, U8* value=NULL) { |
| 9 | + " "; |
| 10 | + |
| 11 | + if (label) |
| 12 | + "$FG,3$%s", label; |
| 13 | + |
| 14 | + if (label && value) |
| 15 | + "" ": "; |
| 16 | + |
| 17 | + if (value) |
| 18 | + "$FG,8$%s", value; |
| 19 | + |
| 20 | + '' '\n'; |
| 21 | +} |
| 22 | + |
| 23 | +I64 GetNumFilesInDirectory(U8* dir) { |
| 24 | + CDirEntry* de; |
| 25 | + try { |
| 26 | + de = FilesFind(dir); |
| 27 | + } |
| 28 | + catch { |
| 29 | + de = NULL; |
| 30 | + } |
| 31 | + |
| 32 | + if (!de) |
| 33 | + return -1; |
| 34 | + |
| 35 | + I64 count = 0; |
| 36 | + |
| 37 | + CDirEntry* de2 = de; |
| 38 | + while (de2) { |
| 39 | + if (!(de2->attr & RS_ATTR_DIR)) { |
| 40 | + count++; |
| 41 | + } |
| 42 | + de2 = de2->next; |
| 43 | + } |
| 44 | + |
| 45 | + DirTreeDel(de); |
| 46 | + return count; |
| 47 | +} |
| 48 | + |
| 49 | +CHashFun* FindFunction(U8* name) { |
| 50 | + CHash* result = HashFind(name, Fs->hash_table, HTT_FUN); |
| 51 | + |
| 52 | + if (result && (result->type & HTT_FUN) != 0) |
| 53 | + return result(CHashFun *); |
| 54 | + else |
| 55 | + return NULL; |
| 56 | +} |
| 57 | + |
| 58 | +U8* DetectCPU() { |
| 59 | + StrPrint(buf, "%d core(s)", mp_cnt); |
| 60 | + return buf; |
| 61 | +} |
| 62 | + |
| 63 | +U8* DetectFont() { |
| 64 | + // FIXME: Actually detect - but how? |
| 65 | + // If there was something like a global hash-table, |
| 66 | + // we could use it to mark user Fonts & Palettes |
| 67 | + return "FontStd.HC"; |
| 68 | +} |
| 69 | + |
| 70 | +U8* DetectNumPackages() { |
| 71 | + I64 num_packages = GetNumFilesInDirectory("::/Misc/Packages"); |
| 72 | + |
| 73 | + if (num_packages < 0) |
| 74 | + num_packages = 0; |
| 75 | + |
| 76 | + StrPrint(buf, "%d", num_packages); |
| 77 | + return buf; |
| 78 | +} |
| 79 | + |
| 80 | +U8* DetectRAM() { |
| 81 | + I64 ram_used = sys_code_bp->used_u8s; |
| 82 | + I64 ram_total = sys_code_bp->alloced_u8s; |
| 83 | + if (sys_data_bp) { |
| 84 | + ram_used += sys_data_bp->used_u8s; |
| 85 | + ram_total += sys_data_bp->alloced_u8s; |
| 86 | + } |
| 87 | + StrPrint(buf, "%dMiB / %dMiB", ram_used / (1024 * 1024), ram_total / (1024 * 1024)); |
| 88 | + return buf; |
| 89 | +} |
| 90 | + |
| 91 | +U8* DetectPalette() { |
| 92 | + // FIXME: Actually detect - but how? |
| 93 | + // See comment in DetectFont |
| 94 | + return "PalUbuntu.HC"; |
| 95 | +} |
| 96 | + |
| 97 | +U8* DetectShell() { |
| 98 | + if (FindFunction("Lsh")) |
| 99 | + return "Lsh"; |
| 100 | + else if (FindFunction("TempleShell")) |
| 101 | + return "TempleShell"; |
| 102 | + else if (FindFunction("UserCmdLine")) |
| 103 | + return "UserCmdLine"; |
| 104 | + else |
| 105 | + return "unknown"; |
| 106 | +} |
| 107 | + |
| 108 | +U8* DetectUptime() { |
| 109 | + F64 uptime = tS; |
| 110 | + I64 uptime_min = ToI64(uptime) / 60; |
| 111 | + I64 uptime_sec = ToI64(uptime) % 60; |
| 112 | + StrPrint(buf, "%dm %ds", uptime_min, uptime_sec); |
| 113 | + return buf; |
| 114 | +} |
| 115 | + |
| 116 | +U0 Screenfetch() { |
| 117 | + Line(); |
| 118 | + |
| 119 | + U8* logo_path = MStrPrint("%s/Logo128x152.bmp", screenfetch_dir); |
| 120 | + DocBMP(DocPut, logo_path); |
| 121 | + Free(logo_path); |
| 122 | + |
| 123 | + Line(); |
| 124 | + Line(); |
| 125 | + StrPrint(buf, "singleuser@%s", DirCur); |
| 126 | + Line(buf, ""); |
| 127 | + Line(); |
| 128 | + Line(); |
| 129 | + Line("OS", OS_NAME); |
| 130 | + Line("Kernel", "TempleOS"); |
| 131 | + Line("Uptime", DetectUptime()); |
| 132 | + Line("Packages", DetectNumPackages()); |
| 133 | + Line("Shell", DetectShell()); |
| 134 | + Line("Resolution", "640x480"); |
| 135 | + Line("DE", "Not Present"); |
| 136 | + Line("WM", "Default"); |
| 137 | + Line("Palette", DetectPalette()); |
| 138 | + Line("Font", DetectFont()); |
| 139 | + Line("CPU", DetectCPU()); |
| 140 | + Line("RAM", DetectRAM()); |
| 141 | + Line(); |
| 142 | + Line(); |
| 143 | + Line(); |
| 144 | +} |
0 commit comments