11#include "common/printing.h"
22#include "common/jsonconfig.h"
33#include "common/textModifier.h"
4- #include "common/stringUtils .h"
4+ #include "common/color .h"
55#include "logo/logo.h"
66#include "modules/colors/colors.h"
77
@@ -23,20 +23,23 @@ bool ffPrintColors(FFColorsOptions* options)
2323
2424 if (options -> symbol == FF_COLORS_SYMBOL_BLOCK || options -> symbol == FF_COLORS_SYMBOL_BACKGROUND )
2525 {
26- // 3%d: Set the foreground color
27- for (uint8_t i = options -> block .range [0 ]; i <= min (options -> block .range [1 ], 7 ); i ++ )
26+ if (options -> brightness != FF_COLORS_BRIGHTNESS_LIGHT )
2827 {
29- if (options -> symbol == FF_COLORS_SYMBOL_BLOCK )
28+ // 3%d: Set the foreground color
29+ for (uint8_t i = options -> block .range [0 ]; i <= min (options -> block .range [1 ], 7 ); i ++ )
3030 {
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 , ' ' );
31+ if (options -> symbol == FF_COLORS_SYMBOL_BLOCK )
32+ {
33+ if (!instance .config .display .pipe )
34+ ffStrbufAppendF (& result , "\e[3%dm" , i );
35+ for (uint8_t j = 0 ; j < options -> block .width ; j ++ )
36+ ffStrbufAppendS (& result , "█" );
37+ }
38+ else
39+ {
40+ ffStrbufAppendF (& result , "\e[4%dm" , i );
41+ ffStrbufAppendNC (& result , options -> block .width , ' ' );
42+ }
4043 }
4144 }
4245 if (result .length > 0 )
@@ -64,20 +67,23 @@ bool ffPrintColors(FFColorsOptions* options)
6467 }
6568 #endif
6669
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 ++ )
70+ if (options -> brightness != FF_COLORS_BRIGHTNESS_NORMAL )
6971 {
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
72+ // 9%d: Set the foreground to the bright color
73+ for (uint8_t i = max (options -> block .range [0 ], 8 ); i <= options -> block .range [1 ]; i ++ )
7874 {
79- ffStrbufAppendF (& result , "\e[10%dm" , i - 8 );
80- ffStrbufAppendNC (& result , options -> block .width , ' ' );
75+ if (options -> symbol == FF_COLORS_SYMBOL_BLOCK )
76+ {
77+ if (!instance .config .display .pipe )
78+ ffStrbufAppendF (& result , "\e[9%dm" , i - 8 );
79+ for (uint8_t j = 0 ; j < options -> block .width ; j ++ )
80+ ffStrbufAppendS (& result , "█" );
81+ }
82+ else
83+ {
84+ ffStrbufAppendF (& result , "\e[10%dm" , i - 8 );
85+ ffStrbufAppendNC (& result , options -> block .width , ' ' );
86+ }
8187 }
8288 }
8389 }
@@ -93,11 +99,23 @@ bool ffPrintColors(FFColorsOptions* options)
9399 case FF_COLORS_SYMBOL_STAR : symbol = "★ " ; break ;
94100 default : symbol = "███ " ; break ;
95101 }
96- for ( int i = 8 ; i >= 1 ; -- i )
102+ if ( options -> brightness == FF_COLORS_BRIGHTNESS_DEFAULT )
97103 {
98- if (!instance .config .display .pipe )
99- ffStrbufAppendF (& result , "\e[3%dm" , i );
100- ffStrbufAppendS (& result , symbol );
104+ for (int i = 8 ; i >= 1 ; -- i )
105+ {
106+ if (!instance .config .display .pipe )
107+ ffStrbufAppendF (& result , "\e[" FF_COLOR_FG_256 "%dm" , i );
108+ ffStrbufAppendS (& result , symbol );
109+ }
110+ }
111+ else
112+ {
113+ for (int i = 0 ; i <= 7 ; ++ i )
114+ {
115+ if (!instance .config .display .pipe )
116+ ffStrbufAppendF (& result , "\e[%c%dm" , options -> brightness == FF_COLORS_BRIGHTNESS_NORMAL ? '3' : '9' , i );
117+ ffStrbufAppendS (& result , symbol );
118+ }
101119 }
102120 ffStrbufTrimRight (& result , ' ' );
103121 }
@@ -112,9 +130,9 @@ bool ffPrintColors(FFColorsOptions* options)
112130 flag = true;
113131 }
114132
115- if (options -> paddingLeft > 0 )
133+ if (options -> paddingLeft > 0 )
116134 ffPrintCharTimes (' ' , options -> paddingLeft );
117- if (!instance .config .display .pipe || options -> symbol == FF_COLORS_SYMBOL_BACKGROUND )
135+ if (!instance .config .display .pipe || options -> symbol == FF_COLORS_SYMBOL_BACKGROUND )
118136 ffStrbufAppendS (& result , FASTFETCH_TEXT_MODIFIER_RESET );
119137 ffStrbufPutTo (& result , stdout );
120138 }
@@ -197,6 +215,22 @@ void ffParseColorsJsonObject(FFColorsOptions* options, yyjson_val* module)
197215 continue ;
198216 }
199217
218+ if (unsafe_yyjson_equals_str (key , "brightness" ))
219+ {
220+ int value ;
221+ const char * error = ffJsonConfigParseEnum (val , & value , (FFKeyValuePair []) {
222+ { "default" , FF_COLORS_BRIGHTNESS_DEFAULT },
223+ { "normal" , FF_COLORS_BRIGHTNESS_NORMAL },
224+ { "light" , FF_COLORS_BRIGHTNESS_LIGHT },
225+ {},
226+ });
227+ if (error )
228+ ffPrintError (FF_COLORS_MODULE_NAME , 0 , NULL , FF_PRINT_TYPE_NO_CUSTOM_KEY , "Invalid %s value: %s" , unsafe_yyjson_get_str (key ), error );
229+ else
230+ options -> brightness = (FFColorsBrightness ) value ;
231+ continue ;
232+ }
233+
200234 ffPrintError (FF_COLORS_MODULE_NAME , 0 , NULL , FF_PRINT_TYPE_NO_CUSTOM_KEY , "Unknown JSON key %s" , unsafe_yyjson_get_str (key ));
201235 }
202236}
@@ -240,6 +274,7 @@ void ffInitColorsOptions(FFColorsOptions* options)
240274 .width = 3 ,
241275 .range = { 0 , 15 },
242276 };
277+ options -> brightness = FF_COLORS_BRIGHTNESS_DEFAULT ;
243278}
244279
245280void ffDestroyColorsOptions (FFColorsOptions * options )
0 commit comments