|
6 | 6 | "keys": "blue" |
7 | 7 | }, |
8 | 8 | "separator": "", |
| 9 | + // Constants are reusable strings referenced by {$1}, {$2}, etc. |
| 10 | + // These contain ANSI escape codes for cursor positioning |
9 | 11 | "constants": [ |
10 | | - "──────────────────────────────────────────────", |
11 | | - "\u001b[47D", |
12 | | - "\u001b[47C", |
13 | | - "\u001b[46C" |
| 12 | + "──────────────────────────────────────────────", // {$1} - horizontal line for borders |
| 13 | + "\u001b[47D", // {$2} - move cursor left 47 columns |
| 14 | + "\u001b[47C", // {$3} - move cursor right 47 columns |
| 15 | + "\u001b[46C" // {$4} - move cursor right 46 columns |
14 | 16 | ], |
15 | 17 | "brightColor": false |
16 | 18 | }, |
|
22 | 24 | }, |
23 | 25 | { |
24 | 26 | "type": "os", |
| 27 | + // Key format breakdown for OS module: |
| 28 | + // "│ {icon} \u001b[s{sysname}\u001b[u\u001b[10C│{$3}│{$2}" |
| 29 | + // |
| 30 | + // │ - Left border of key block |
| 31 | + // {icon} - OS icon (defined internally by fastfetch) |
| 32 | + // \u001b[s - ANSI escape: save cursor position (ESC[s) |
| 33 | + // {sysname} - Format variable: system name (e.g., "Linux", "Darwin") |
| 34 | + // \u001b[u - ANSI escape: restore cursor to saved position (ESC[u) |
| 35 | + // Necessary because the length of `{sysname}` differs between different platforms |
| 36 | + // \u001b[10C - ANSI escape: move cursor right 10 columns (ESC[10C) |
| 37 | + // │ - Right border of key block (always 10 columns from left border) |
| 38 | + // {$3} - Reference to constants[2]: move cursor right 47 columns |
| 39 | + // │ - Right border of value block |
| 40 | + // {$2} - Reference to constants[1]: move cursor left 47 columns |
| 41 | + // |
| 42 | + // This creates a fixed-width layout where the key block is exactly 10 columns wide, |
| 43 | + // regardless of the actual content length. The cursor manipulation ensures proper |
| 44 | + // alignment for the table-like structure. |
25 | 45 | "key": "│ {icon} \u001b[s{sysname}\u001b[u\u001b[10C│{$3}│{$2}" |
26 | 46 | }, |
27 | 47 | { |
|
34 | 54 | "key": "│ {icon} Locale │{$3}│{$2}" |
35 | 55 | }, |
36 | 56 |
|
37 | | - // Hardware |
| 57 | + // Hardware section with cyan color theme |
38 | 58 | { |
39 | 59 | "type": "custom", |
40 | 60 | "key": "│{#cyan}┌──────────────┬{$1}┐{#keys}│\u001b[37D", |
41 | 61 | "format": "{#bright_cyan} Hardware " |
42 | 62 | }, |
43 | 63 | { |
44 | 64 | "type": "chassis", |
| 65 | + // Similar structure but with cyan color formatting: |
| 66 | + // │{#cyan}│ - Left border with cyan color |
| 67 | + // {icon} - Chassis icon |
| 68 | + // Chassis - Fixed label text |
| 69 | + // │{$4}│{#keys}│{$2} - Positioning and borders for value area |
45 | 70 | "key": "│{#cyan}│ {icon} Chassis │{$4}│{#keys}│{$2}" |
46 | 71 | }, |
47 | 72 | { |
|
76 | 101 | "format": "" |
77 | 102 | }, |
78 | 103 |
|
79 | | - // Desktop |
| 104 | + // Desktop section with green color theme |
80 | 105 | { |
81 | 106 | "type": "custom", |
82 | 107 | "key": "│{#green}┌──────────────┬{$1}┐{#keys}│\u001b[37D", |
|
106 | 131 | "format": "" |
107 | 132 | }, |
108 | 133 |
|
109 | | - // Terminal |
| 134 | + // Terminal section with yellow color theme |
110 | 135 | { |
111 | 136 | "type": "custom", |
112 | 137 | "key": "│{#yellow}┌──────────────┬{$1}┐{#keys}│\u001b[37D", |
|
138 | 163 | "format": "" |
139 | 164 | }, |
140 | 165 |
|
141 | | - // Development |
| 166 | + // Development section with red color theme |
142 | 167 | { |
143 | 168 | "type": "custom", |
144 | 169 | "key": "│{#red}┌──────────────┬{$1}┐{#keys}│\u001b[39D", |
145 | 170 | "format": "{#bright_red} Development " |
146 | 171 | }, |
147 | 172 | { |
148 | 173 | "type": "command", |
149 | | - "keyIcon": "", |
| 174 | + "keyIcon": "", // Custom icon override |
150 | 175 | "key": "│{#red}│ {icon} Rust │{$4}│{#keys}│{$2}", |
151 | | - "text": "rustc --version | cut -d' ' -f2", |
152 | | - "format": "rustc {}" |
| 176 | + "text": "rustc --version", |
| 177 | + "format": "rustc {~6,13}" // Print 6th to 13th characters (version number) |
153 | 178 | }, |
154 | 179 | { |
155 | 180 | "type": "command", |
| 181 | + "condition": { |
| 182 | + "!system": "Windows" // Posix version |
| 183 | + }, |
156 | 184 | "keyIcon": "", |
157 | 185 | "key": "│{#red}│ {icon} Clang │{$4}│{#keys}│{$2}", |
158 | 186 | "text": "clang --version | head -1 | awk '{print $NF}'", |
159 | 187 | "format": "clang {}" |
160 | 188 | }, |
| 189 | + { |
| 190 | + "type": "command", |
| 191 | + "condition": { |
| 192 | + "system": "Windows" // Windows version |
| 193 | + }, |
| 194 | + "keyIcon": "", |
| 195 | + "key": "│{#red}│ {icon} Clang │{$4}│{#keys}│{$2}", |
| 196 | + "text": "clang --version | findstr version", // Finds the line with "version" |
| 197 | + "format": "clang {~-6}" // Prints the last 6 characters (version number) |
| 198 | + }, |
161 | 199 | { |
162 | 200 | "type": "command", |
163 | 201 | "keyIcon": "", |
164 | 202 | "key": "│{#red}│ {icon} NodeJS │{$4}│{#keys}│{$2}", |
165 | 203 | "text": "node --version", |
166 | | - "format": "node {~1}" |
| 204 | + "format": "node {~1}" // {~1} removes first character (v) |
167 | 205 | }, |
168 | 206 | { |
169 | 207 | "type": "command", |
170 | 208 | "keyIcon": "", |
171 | 209 | "key": "│{#red}│ {icon} Go │{$4}│{#keys}│{$2}", |
172 | 210 | "text": "go version | cut -d' ' -f3", |
173 | | - "format": "go {~2}" |
| 211 | + "format": "go {~2}" // {~2} removes first 2 characters (go) |
174 | 212 | }, |
175 | 213 | { |
176 | 214 | "type": "command", |
|
200 | 238 | "format": "" |
201 | 239 | }, |
202 | 240 |
|
203 | | - // Uptime |
| 241 | + // Uptime section with magenta color theme |
204 | 242 | { |
205 | 243 | "type": "custom", |
206 | 244 | "key": "│{#magenta}┌──────────────┬{$1}┐{#keys}│\u001b[36D", |
|
212 | 250 | }, |
213 | 251 | { |
214 | 252 | "type": "users", |
215 | | - "myselfOnly": true, |
| 253 | + "myselfOnly": true, // Only show current user |
216 | 254 | "keyIcon": "", |
217 | 255 | "key": "│{#magenta}│ {icon} Login │{$4}│{#keys}│{$2}" |
218 | 256 | }, |
219 | 257 | { |
220 | | - "condition": { |
| 258 | + "condition": { // Conditional module: only show on non-macOS |
221 | 259 | "!system": "macOS" |
222 | 260 | }, |
223 | 261 | "type": "disk", |
224 | 262 | "keyIcon": "", |
225 | 263 | "key": "│{#magenta}│ {icon} OS Age │{$4}│{#keys}│{$2}", |
226 | | - "folders": "/", |
227 | | - "format": "{create-time:10} [{days} days]" |
| 264 | + "folders": "/", // Check root filesystem |
| 265 | + "format": "{create-time:10} [{days} days]" // Show creation time and age in days |
228 | 266 | }, |
229 | 267 | { |
230 | | - "condition": { |
| 268 | + "condition": { // Conditional module: only show on macOS |
231 | 269 | "system": "macOS" |
232 | 270 | }, |
233 | 271 | "type": "disk", |
234 | 272 | "keyIcon": "", |
235 | 273 | "key": "│{#magenta}│ {icon} OS Age │{$4}│{#keys}│{$2}", |
236 | | - "folders": "/System/Volumes/VM", |
| 274 | + "folders": "/System/Volumes/VM", // Work around for APFS on macOS |
237 | 275 | "format": "{create-time:10} [{days} days]" |
238 | 276 | }, |
239 | 277 | { |
|
243 | 281 | }, |
244 | 282 | { |
245 | 283 | "type": "custom", |
246 | | - "key": "└─────────────────{$1}┘", |
| 284 | + "key": "└─────────────────{$1}┘", // Bottom border of the entire layout |
247 | 285 | "format": "" |
248 | 286 | }, |
249 | 287 |
|
250 | | - // End |
251 | | - "break", |
252 | | - "colors" |
| 288 | + // End with color palette and line break |
| 289 | + "break", // Add a blank line |
| 290 | + "colors" // Display color palette |
253 | 291 | ] |
254 | 292 | } |
| 293 | + |
| 294 | +/* |
| 295 | +Key Format Structure Explanation: |
| 296 | +
|
| 297 | +The key format uses a combination of: |
| 298 | +1. Unicode box drawing characters (│ ┌ ┐ └ ┘ ┬ ┴) for borders |
| 299 | +2. ANSI escape codes for cursor positioning (\u001b[...) |
| 300 | +3. Format variables ({icon}, {sysname}, etc.) |
| 301 | +4. Constant references ({$1}, {$2}, etc.) |
| 302 | +5. Color formatting ({#color}) |
| 303 | +
|
| 304 | +ANSI Escape Codes Used: |
| 305 | +- \u001b[s - Save cursor position (ESC[s) |
| 306 | +- \u001b[u - Restore cursor position (ESC[u) |
| 307 | +- \u001b[nC - Move cursor right n columns (ESC[nC) |
| 308 | +- \u001b[nD - Move cursor left n columns (ESC[nD) |
| 309 | +
|
| 310 | +This creates a table-like layout with fixed column widths and proper alignment, |
| 311 | +regardless of the actual content length in each field. |
| 312 | +
|
| 313 | +For more ANSI escape code reference, see: |
| 314 | +https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797#cursor-controls |
| 315 | +*/ |
0 commit comments