Skip to content

Commit 25cdd99

Browse files
committed
Color: support {#keys} and {#title} in --<module>-format
1 parent bf17854 commit 25cdd99

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Features:
55
* Make it possible to shorten the theme and icons output (Theme / Icons)
66
* Support `-l '?'` to show a question mark
77
* Add new module `CPUCache` to display CPU cache sizes (CPUCache)
8+
* In `--<module>-format`, `{#keys}` and `{#title}` can be used to reference the color of keys and title
89

910
Bugfixes:
1011
* Remove shebangs from completions

presets/examples/16.jsonc

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,65 +7,63 @@
77
}
88
},
99
"display": {
10-
"separator": "",
11-
"keyWidth": 15
10+
"separator": " "
1211
},
1312
"modules": [
1413
{
1514
"key": "╔═══════════╗",
1615
"type": "custom"
1716
},
1817
{
19-
// draw borders first to make colors of left and right border consistant
20-
"key": "║ ║\u001b[11D{#31} user",
18+
"key": "║ {#31} user {#keys}║",
2119
"type": "title",
2220
"format": "{1}"
2321
},
2422
{
25-
"key": "\u001b[11D{#32}󰇅 hname",
23+
"key": "║ {#32}󰇅 hname {#keys}║",
2624
"type": "title",
2725
"format": "{2}"
2826
},
2927
{
30-
"key": "\u001b[11D{#33}󰅐 uptime",
28+
"key": "║ {#33}󰅐 uptime {#keys}║",
3129
"type": "uptime"
3230
},
3331
{
34-
"key": "\u001b[11D{#34}󰟾 distro",
32+
"key": "║ {#34}󰟾 distro {#keys}║",
3533
"type": "os"
3634
},
3735
{
38-
"key": "\u001b[11D{#35} kernel",
36+
"key": "║ {#35} kernel {#keys}║",
3937
"type": "kernel"
4038
},
4139
{
42-
"key": "\u001b[11D{#36}󰇄 desktop",
40+
"key": "║ {#36}󰇄 desktop {#keys}║",
4341
"type": "de"
4442
},
4543
{
46-
"key": " \u001b[11D{#31} term",
44+
"key": "{#31} term {#keys}║",
4745
"type": "terminal"
4846
},
4947
{
50-
"key": "\u001b[11D{#32} shell",
48+
"key": "║ {#32} shell {#keys}║",
5149
"type": "shell"
5250
},
5351
{
54-
"key": " \u001b[11D{#33}󰍛 cpu",
52+
"key": "{#33}󰍛 cpu {#keys}║",
5553
"type": "cpu",
5654
"showPeCoreCount": true
5755
},
5856
{
59-
"key": " \u001b[11D{#34}󰉉 disk",
57+
"key": "{#34}󰉉 disk {#keys}║",
6058
"type": "disk",
6159
"folders": "/"
6260
},
6361
{
64-
"key": "\u001b[11D{#35} memory",
62+
"key": "║ {#35} memory {#keys}║",
6563
"type": "memory"
6664
},
6765
{
68-
"key": "\u001b[11D{#36}󰩟 network",
66+
"key": "║ {#36}󰩟 network {#keys}║",
6967
"type": "localip",
7068
"format": "{1} ({4})"
7169
},
@@ -74,7 +72,7 @@
7472
"type": "custom"
7573
},
7674
{
77-
"key": "\u001b[11D{#39} colors",
75+
"key": "║ {#39} colors {#keys}║",
7876
"type": "colors",
7977
"symbol": "circle"
8078
},

src/common/option.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "fastfetch.h"
12
#include "common/option.h"
23
#include "common/color.h"
34
#include "util/stringUtils.h"
@@ -153,6 +154,8 @@ void ffOptionParseColorNoClear(const char* value, FFstrbuf* buffer)
153154
{
154155
#define FF_APPEND_COLOR_CODE_COND(prefix, code) \
155156
if(ffStrStartsWithIgnCase(value, #prefix)) { ffStrbufAppendS(buffer, code); value += strlen(#prefix); continue; }
157+
#define FF_APPEND_COLOR_PROP_COND(prefix, prop) \
158+
if(ffStrStartsWithIgnCase(value, #prefix)) { if (instance.config.display.prop.length) ffStrbufAppend(buffer, &instance.config.display.prop); else ffStrbufAppendS(buffer, FF_COLOR_FG_DEFAULT); value += strlen(#prefix); continue; }
156159

157160
if (ffCharIsEnglishAlphabet(value[0]))
158161
{
@@ -182,11 +185,16 @@ void ffOptionParseColorNoClear(const char* value, FFstrbuf* buffer)
182185
else FF_APPEND_COLOR_CODE_COND(light_magenta, FF_COLOR_FG_LIGHT_MAGENTA)
183186
else FF_APPEND_COLOR_CODE_COND(light_cyan, FF_COLOR_FG_LIGHT_CYAN)
184187
else FF_APPEND_COLOR_CODE_COND(light_white, FF_COLOR_FG_LIGHT_WHITE)
188+
else FF_APPEND_COLOR_PROP_COND(keys, colorKeys)
189+
else FF_APPEND_COLOR_PROP_COND(title, colorTitle)
190+
else FF_APPEND_COLOR_PROP_COND(output, colorOutput)
191+
else FF_APPEND_COLOR_PROP_COND(separator, colorSeparator)
185192
}
186193
ffStrbufAppendC(buffer, *value);
187194
++value;
188195

189196
#undef FF_APPEND_COLOR_CODE_COND
197+
#undef FF_APPEND_COLOR_PROP_COND
190198
}
191199
}
192200

src/data/help_color.txt

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
Usage: fastfetch --color <color>
22

3+
Shortcut of `fastfetch --color-keys <color> --color-title <color>`.
4+
If no color is set, the main color of the logo will be used.
5+
6+
Following information applies to all settings
7+
38
<color> must be a color encoding as ANSI escape sequences. It is inserted between "ESC[" and "m".
49
Infos about them can be found here: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters.
510
Examples:
6-
--color 35: sets the color to magenta. `--color magenta` is also supported
7-
--color 38;5;38: sets the color to 38th color of ANSI 256 colors
8-
--color 4;92: sets the color to bright Green with underline. `--color underline_green` is also supported
9-
--color 5;104: blinking text on a blue background
10-
If no color is set, the main color of the logo will be used.
11+
35: sets the color to magenta
12+
38;5;38: sets the color to 38th color of ANSI 256 colors
13+
4;92: sets the color to bright green with underline
14+
5;104: blinking text on a blue background
15+
16+
ANSI named colors are also supported:
17+
magenta: equivalent to `35`
18+
underline_bright_green: equivalent to `4;92`
19+
20+
After v2.15.0, some special keys can be used:
21+
keys: use the color set by `--color-keys`
22+
title: use the color set by `--color-title`
23+
output: use the color set by `--color-output`
24+
separator: use the color set by `--color-separator`

0 commit comments

Comments
 (0)