diff options
| author | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
|---|---|---|
| committer | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
| commit | 76424950e373d3b04ac3dd13019151bfba3e8423 (patch) | |
| tree | 4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/common/percent.h | |
Add the files
Diffstat (limited to 'src/common/percent.h')
| -rw-r--r-- | src/common/percent.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/common/percent.h b/src/common/percent.h new file mode 100644 index 0000000..c2eeba6 --- /dev/null +++ b/src/common/percent.h @@ -0,0 +1,43 @@ +#pragma once + +#include "common/FFstrbuf.h" +#include "common/parsing.h" +#include "common/option.h" + +typedef enum FF_A_PACKED FFPercentageTypeFlags { + FF_PERCENTAGE_TYPE_NONE = 0, + FF_PERCENTAGE_TYPE_NUM_BIT = 1 << 0, + FF_PERCENTAGE_TYPE_BAR_BIT = 1 << 1, + FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT = 1 << 2, + FF_PERCENTAGE_TYPE_NUM_COLOR_BIT = 1 << 3, + FF_PERCENTAGE_TYPE_BAR_MONOCHROME_BIT = 1 << 4, + FF_PERCENTAGE_TYPE_FORCE_UNSIGNED_ = UINT8_MAX, +} FFPercentageTypeFlags; +static_assert(sizeof(FFPercentageTypeFlags) == 1, ""); + +typedef struct FFPercentageModuleConfig { + uint8_t green; + uint8_t yellow; + FFPercentageTypeFlags type; +} FFPercentageModuleConfig; + +// if (green <= yellow) +// [0, green]: print green +// (green, yellow]: print yellow +// (yellow, 100]: print red +// +// if (green > yellow) +// [green, 100]: print green +// [yellow, green): print yellow +// [0, yellow): print red + +void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentageModuleConfig config, const FFModuleArgs* module); +void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFPercentageModuleConfig config, bool parentheses, const FFModuleArgs* module); + +typedef struct yyjson_val yyjson_val; +typedef struct yyjson_mut_doc yyjson_mut_doc; +typedef struct yyjson_mut_val yyjson_mut_val; +bool ffPercentParseCommandOptions(const char* key, const char* subkey, const char* value, FFPercentageModuleConfig* config); +bool ffPercentParseJsonObject(yyjson_val* key, yyjson_val* value, FFPercentageModuleConfig* config); +void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFPercentageModuleConfig config); +const char* ffPercentParseTypeJsonConfig(yyjson_val* value, FFPercentageTypeFlags* result); |