Skip to content

Commit be3e2ba

Browse files
committed
Presets: improve 25.jsonc; add verbose comments [ci skip]
1 parent ccbb9e9 commit be3e2ba

1 file changed

Lines changed: 85 additions & 24 deletions

File tree

presets/examples/25.jsonc

Lines changed: 85 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
"keys": "blue"
77
},
88
"separator": "",
9+
// Constants are reusable strings referenced by {$1}, {$2}, etc.
10+
// These contain ANSI escape codes for cursor positioning
911
"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
1416
],
1517
"brightColor": false
1618
},
@@ -22,6 +24,24 @@
2224
},
2325
{
2426
"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.
2545
"key": "│ {icon} \u001b[s{sysname}\u001b[u\u001b[10C│{$3}│{$2}"
2646
},
2747
{
@@ -34,14 +54,19 @@
3454
"key": "│ {icon} Locale │{$3}│{$2}"
3555
},
3656

37-
// Hardware
57+
// Hardware section with cyan color theme
3858
{
3959
"type": "custom",
4060
"key": "│{#cyan}┌──────────────┬{$1}┐{#keys}│\u001b[37D",
4161
"format": "{#bright_cyan} Hardware "
4262
},
4363
{
4464
"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
4570
"key": "│{#cyan}│ {icon} Chassis │{$4}│{#keys}│{$2}"
4671
},
4772
{
@@ -76,7 +101,7 @@
76101
"format": ""
77102
},
78103

79-
// Desktop
104+
// Desktop section with green color theme
80105
{
81106
"type": "custom",
82107
"key": "│{#green}┌──────────────┬{$1}┐{#keys}│\u001b[37D",
@@ -106,7 +131,7 @@
106131
"format": ""
107132
},
108133

109-
// Terminal
134+
// Terminal section with yellow color theme
110135
{
111136
"type": "custom",
112137
"key": "│{#yellow}┌──────────────┬{$1}┐{#keys}│\u001b[37D",
@@ -138,39 +163,52 @@
138163
"format": ""
139164
},
140165

141-
// Development
166+
// Development section with red color theme
142167
{
143168
"type": "custom",
144169
"key": "│{#red}┌──────────────┬{$1}┐{#keys}│\u001b[39D",
145170
"format": "{#bright_red} Development "
146171
},
147172
{
148173
"type": "command",
149-
"keyIcon": "",
174+
"keyIcon": "", // Custom icon override
150175
"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)
153178
},
154179
{
155180
"type": "command",
181+
"condition": {
182+
"!system": "Windows" // Posix version
183+
},
156184
"keyIcon": "",
157185
"key": "│{#red}│ {icon} Clang │{$4}│{#keys}│{$2}",
158186
"text": "clang --version | head -1 | awk '{print $NF}'",
159187
"format": "clang {}"
160188
},
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+
},
161199
{
162200
"type": "command",
163201
"keyIcon": "",
164202
"key": "│{#red}│ {icon} NodeJS │{$4}│{#keys}│{$2}",
165203
"text": "node --version",
166-
"format": "node {~1}"
204+
"format": "node {~1}" // {~1} removes first character (v)
167205
},
168206
{
169207
"type": "command",
170208
"keyIcon": "",
171209
"key": "│{#red}│ {icon} Go │{$4}│{#keys}│{$2}",
172210
"text": "go version | cut -d' ' -f3",
173-
"format": "go {~2}"
211+
"format": "go {~2}" // {~2} removes first 2 characters (go)
174212
},
175213
{
176214
"type": "command",
@@ -200,7 +238,7 @@
200238
"format": ""
201239
},
202240

203-
// Uptime
241+
// Uptime section with magenta color theme
204242
{
205243
"type": "custom",
206244
"key": "│{#magenta}┌──────────────┬{$1}┐{#keys}│\u001b[36D",
@@ -212,28 +250,28 @@
212250
},
213251
{
214252
"type": "users",
215-
"myselfOnly": true,
253+
"myselfOnly": true, // Only show current user
216254
"keyIcon": "",
217255
"key": "│{#magenta}│ {icon} Login │{$4}│{#keys}│{$2}"
218256
},
219257
{
220-
"condition": {
258+
"condition": { // Conditional module: only show on non-macOS
221259
"!system": "macOS"
222260
},
223261
"type": "disk",
224262
"keyIcon": "",
225263
"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
228266
},
229267
{
230-
"condition": {
268+
"condition": { // Conditional module: only show on macOS
231269
"system": "macOS"
232270
},
233271
"type": "disk",
234272
"keyIcon": "",
235273
"key": "│{#magenta}│ {icon} OS Age │{$4}│{#keys}│{$2}",
236-
"folders": "/System/Volumes/VM",
274+
"folders": "/System/Volumes/VM", // Work around for APFS on macOS
237275
"format": "{create-time:10} [{days} days]"
238276
},
239277
{
@@ -243,12 +281,35 @@
243281
},
244282
{
245283
"type": "custom",
246-
"key": "└─────────────────{$1}┘",
284+
"key": "└─────────────────{$1}┘", // Bottom border of the entire layout
247285
"format": ""
248286
},
249287

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
253291
]
254292
}
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

Comments
 (0)