11#include "common/printing.h"
22#include "common/jsonconfig.h"
33#include "common/textModifier.h"
4+ #include "common/color.h"
45#include "common/stringUtils.h"
56#include "logo/logo.h"
67#include "modules/colors/colors.h"
@@ -23,20 +24,23 @@ bool ffPrintColors(FFColorsOptions* options)
2324
2425 if (options -> symbol == FF_COLORS_SYMBOL_BLOCK || options -> symbol == FF_COLORS_SYMBOL_BACKGROUND )
2526 {
26- // 3%d: Set the foreground color
27- for (uint8_t i = options -> block .range [0 ]; i <= min (options -> block .range [1 ], 7 ); i ++ )
27+ if (options -> brightness != FF_COLORS_BRIGHTNESS_LIGHT )
2828 {
29- if (options -> symbol == FF_COLORS_SYMBOL_BLOCK )
29+ // 3%d: Set the foreground color
30+ for (uint8_t i = options -> block .range [0 ]; i <= min (options -> block .range [1 ], 7 ); i ++ )
3031 {
31- if (!instance .config .display .pipe )
32- ffStrbufAppendF (& result , "\e[3%dm" , i );
33- for (uint8_t j = 0 ; j < options -> block .width ; j ++ )
34- ffStrbufAppendS (& result , "█" );
35- }
36- else
37- {
38- ffStrbufAppendF (& result , "\e[4%dm" , i );
39- ffStrbufAppendNC (& result , options -> block .width , ' ' );
32+ if (options -> symbol == FF_COLORS_SYMBOL_BLOCK )
33+ {
34+ if (!instance .config .display .pipe )
35+ ffStrbufAppendF (& result , "\e[3%dm" , i );
36+ for (uint8_t j = 0 ; j < options -> block .width ; j ++ )
37+ ffStrbufAppendS (& result , "█" );
38+ }
39+ else
40+ {
41+ ffStrbufAppendF (& result , "\e[4%dm" , i );
42+ ffStrbufAppendNC (& result , options -> block .width , ' ' );
43+ }
4044 }
4145 }
4246 if (result .length > 0 )
@@ -64,20 +68,23 @@ bool ffPrintColors(FFColorsOptions* options)
6468 }
6569 #endif
6670
67- // 9%d: Set the foreground to the bright color
68- for (uint8_t i = max (options -> block .range [0 ], 8 ); i <= options -> block .range [1 ]; i ++ )
71+ if (options -> brightness != FF_COLORS_BRIGHTNESS_NORMAL )
6972 {
70- if (options -> symbol == FF_COLORS_SYMBOL_BLOCK )
71- {
72- if (!instance .config .display .pipe )
73- ffStrbufAppendF (& result , "\e[9%dm" , i - 8 );
74- for (uint8_t j = 0 ; j < options -> block .width ; j ++ )
75- ffStrbufAppendS (& result , "█" );
76- }
77- else
73+ // 9%d: Set the foreground to the bright color
74+ for (uint8_t i = max (options -> block .range [0 ], 8 ); i <= options -> block .range [1 ]; i ++ )
7875 {
79- ffStrbufAppendF (& result , "\e[10%dm" , i - 8 );
80- ffStrbufAppendNC (& result , options -> block .width , ' ' );
76+ if (options -> symbol == FF_COLORS_SYMBOL_BLOCK )
77+ {
78+ if (!instance .config .display .pipe )
79+ ffStrbufAppendF (& result , "\e[9%dm" , i - 8 );
80+ for (uint8_t j = 0 ; j < options -> block .width ; j ++ )
81+ ffStrbufAppendS (& result , "█" );
82+ }
83+ else
84+ {
85+ ffStrbufAppendF (& result , "\e[10%dm" , i - 8 );
86+ ffStrbufAppendNC (& result , options -> block .width , ' ' );
87+ }
8188 }
8289 }
8390 }
@@ -93,11 +100,23 @@ bool ffPrintColors(FFColorsOptions* options)
93100 case FF_COLORS_SYMBOL_STAR : symbol = "★ " ; break ;
94101 default : symbol = "███ " ; break ;
95102 }
96- for ( int i = 8 ; i >= 1 ; -- i )
103+ if ( options -> brightness == FF_COLORS_BRIGHTNESS_DEFAULT )
97104 {
98- if (!instance .config .display .pipe )
99- ffStrbufAppendF (& result , "\e[3%dm" , i );
100- ffStrbufAppendS (& result , symbol );
105+ for (int i = 8 ; i >= 1 ; -- i )
106+ {
107+ if (!instance .config .display .pipe )
108+ ffStrbufAppendF (& result , "\e[" FF_COLOR_FG_256 "%dm" , i );
109+ ffStrbufAppendS (& result , symbol );
110+ }
111+ }
112+ else
113+ {
114+ for (int i = 0 ; i <= 7 ; ++ i )
115+ {
116+ if (!instance .config .display .pipe )
117+ ffStrbufAppendF (& result , "\e[%c%dm" , options -> brightness == FF_COLORS_BRIGHTNESS_NORMAL ? '3' : '9' , i );
118+ ffStrbufAppendS (& result , symbol );
119+ }
101120 }
102121 ffStrbufTrimRight (& result , ' ' );
103122 }
@@ -112,9 +131,9 @@ bool ffPrintColors(FFColorsOptions* options)
112131 flag = true;
113132 }
114133
115- if (options -> paddingLeft > 0 )
134+ if (options -> paddingLeft > 0 )
116135 ffPrintCharTimes (' ' , options -> paddingLeft );
117- if (!instance .config .display .pipe || options -> symbol == FF_COLORS_SYMBOL_BACKGROUND )
136+ if (!instance .config .display .pipe || options -> symbol == FF_COLORS_SYMBOL_BACKGROUND )
118137 ffStrbufAppendS (& result , FASTFETCH_TEXT_MODIFIER_RESET );
119138 ffStrbufPutTo (& result , stdout );
120139 }
@@ -197,6 +216,22 @@ void ffParseColorsJsonObject(FFColorsOptions* options, yyjson_val* module)
197216 continue ;
198217 }
199218
219+ if (unsafe_yyjson_equals_str (key , "brightness" ))
220+ {
221+ int value ;
222+ const char * error = ffJsonConfigParseEnum (val , & value , (FFKeyValuePair []) {
223+ { "default" , FF_COLORS_BRIGHTNESS_DEFAULT },
224+ { "normal" , FF_COLORS_BRIGHTNESS_NORMAL },
225+ { "light" , FF_COLORS_BRIGHTNESS_LIGHT },
226+ {},
227+ });
228+ if (error )
229+ ffPrintError (FF_COLORS_MODULE_NAME , 0 , NULL , FF_PRINT_TYPE_NO_CUSTOM_KEY , "Invalid %s value: %s" , unsafe_yyjson_get_str (key ), error );
230+ else
231+ options -> brightness = (FFColorsBrightness ) value ;
232+ continue ;
233+ }
234+
200235 ffPrintError (FF_COLORS_MODULE_NAME , 0 , NULL , FF_PRINT_TYPE_NO_CUSTOM_KEY , "Unknown JSON key %s" , unsafe_yyjson_get_str (key ));
201236 }
202237}
@@ -240,6 +275,7 @@ void ffInitColorsOptions(FFColorsOptions* options)
240275 .width = 3 ,
241276 .range = { 0 , 15 },
242277 };
278+ options -> brightness = FF_COLORS_BRIGHTNESS_DEFAULT ;
243279}
244280
245281void ffDestroyColorsOptions (FFColorsOptions * options )
0 commit comments