@@ -41,15 +41,18 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentageModuleConf
4141 }
4242 else
4343 {
44- const char * colorGreen = instance .config .display .percentColorGreen .chars ;
45- const char * colorYellow = instance .config .display .percentColorYellow .chars ;
46- const char * colorRed = instance .config .display .percentColorRed .chars ;
44+ const char * colorGreen = options -> percentColorGreen .chars ;
45+ const char * colorYellow = options -> percentColorYellow .chars ;
46+ const char * colorRed = options -> percentColorRed .chars ;
47+
48+ FFPercentageTypeFlags percentType = config .type == 0 ? options -> percentType : config .type ;
49+ bool monochrome = !!(percentType & FF_PERCENTAGE_TYPE_BAR_MONOCHROME_BIT );
4750
4851 for (uint32_t i = 0 ; i < blocksPercent ; ++ i )
4952 {
5053 if (!options -> pipe )
5154 {
52- if (options -> percentType & FF_PERCENTAGE_TYPE_BAR_MONOCHROME_BIT )
55+ if (monochrome )
5356 {
5457 const char * color = NULL ;
5558 if (green <= yellow )
@@ -110,8 +113,9 @@ void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFPercentageModuleConf
110113 assert (green <= 100 && yellow <= 100 );
111114
112115 const FFOptionsDisplay * options = & instance .config .display ;
116+ FFPercentageTypeFlags percentType = config .type == 0 ? options -> percentType : config .type ;
113117
114- bool colored = !!(options -> percentType & FF_PERCENTAGE_TYPE_NUM_COLOR_BIT );
118+ bool colored = !!(percentType & FF_PERCENTAGE_TYPE_NUM_COLOR_BIT );
115119
116120 if (parentheses )
117121 ffStrbufAppendC (buffer , '(' );
@@ -187,6 +191,12 @@ bool ffPercentParseCommandOptions(const char* key, const char* subkey, const cha
187191 return true;
188192 }
189193
194+ if (ffStrEqualsIgnCase (subkey , "type" ))
195+ {
196+ config -> type = (FFPercentageTypeFlags ) ffOptionParseUInt32 (key , value );
197+ return true;
198+ }
199+
190200 return false;
191201}
192202
@@ -225,6 +235,12 @@ bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFPercentageMo
225235 config -> yellow = (uint8_t ) num ;
226236 }
227237
238+ yyjson_val * typeVal = yyjson_obj_get (value , "type" );
239+ if (typeVal )
240+ {
241+ config -> type = (FFPercentageTypeFlags ) yyjson_get_int (typeVal );
242+ }
243+
228244 return true;
229245}
230246
@@ -238,4 +254,6 @@ void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FF
238254 yyjson_mut_obj_add_uint (doc , percent , "green" , config .green );
239255 if (config .yellow != defaultConfig .yellow )
240256 yyjson_mut_obj_add_uint (doc , percent , "yellow" , config .yellow );
257+ if (config .type != defaultConfig .type )
258+ yyjson_mut_obj_add_uint (doc , percent , "type" , config .type );
241259}
0 commit comments