11#include  "fastfetch.h" 
2+ #include  "common/color.h" 
23#include  "common/jsonconfig.h" 
34#include  "common/printing.h" 
45#include  "common/io/io.h" 
@@ -181,12 +182,13 @@ static const char* printJsonConfig(bool prepare, yyjson_mut_doc* jsonDoc)
181182    if  (!modules ) return  NULL ;
182183    if  (!yyjson_is_arr (modules )) return  "Property 'modules' must be an array of strings or objects" ;
183184
185+     int32_t  thres  =  instance .config .display .stat ;
184186    yyjson_val *  item ;
185187    size_t  idx , max ;
186188    yyjson_arr_foreach (modules , idx , max , item )
187189    {
188-         uint64_t  ms  =  0 ;
189-         if (!prepare  &&  instance . config . display . stat )
190+         double  ms  =  0 ;
191+         if (!prepare  &&  thres  >=  0 )
190192            ms  =  ffTimeGetTick ();
191193
192194        yyjson_val *  module  =  item ;
@@ -208,19 +210,21 @@ static const char* printJsonConfig(bool prepare, yyjson_mut_doc* jsonDoc)
208210        else  if (!parseModuleJsonObject (type , module , jsonDoc ))
209211            return  "Unknown module type" ;
210212
211-         if (!prepare  &&  instance . config . display . stat )
213+         if (!prepare  &&  thres  >=  0 )
212214        {
213215            ms  =  ffTimeGetTick () -  ms ;
214216            if  (jsonDoc )
215217            {
216218                yyjson_mut_val *  moduleJson  =  yyjson_mut_arr_get_last (jsonDoc -> root );
217-                 yyjson_mut_obj_add_uint (jsonDoc , moduleJson , "stat" , ms );
219+                 yyjson_mut_obj_add_real (jsonDoc , moduleJson , "stat" , ms );
218220            }
219221            else 
220222            {
221-                 char  str [32 ];
222-                 int  len  =  snprintf (str , sizeof  str , "%"  PRIu64  "ms" , ms );
223-                 printf ("\033[s\033[1A\033[9999999C\033[%dD%s\033[u" , len , str ); // Save; Up 1; Right 9999999; Left <len>; Print <str>; Load 
223+                 char  str [64 ];
224+                 int  len  =  snprintf (str , sizeof  str , "%.3fms" , ms );
225+                 if  (thres  >  0 )
226+                     snprintf (str , sizeof  str , "\e[%sm%.3fms\e[m" , (ms  <= thres  ? FF_COLOR_FG_GREEN  : ms  <= 2  *  thres  ? FF_COLOR_FG_YELLOW  : FF_COLOR_FG_RED ), ms );
227+                 printf ("\e[s\e[1A\e[9999999C\e[%dD%s\e[u" , len , str ); // Save; Up 1; Right 9999999; Left <len>; Print <str>; Load 
224228            }
225229        }
226230
0 commit comments