mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 08:13:44 +01:00
Chore: run clang-format
```bash find . -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.hpp" \) ! -path "src/3rdparty/*" -print0 | xargs -0 clang-format -i ```
This commit is contained in:
@@ -2,8 +2,7 @@
|
||||
|
||||
#include "common/option.h"
|
||||
|
||||
typedef struct FFSeparatorOptions
|
||||
{
|
||||
typedef struct FFSeparatorOptions {
|
||||
FFstrbuf string;
|
||||
FFstrbuf outputColor;
|
||||
uint32_t times;
|
||||
|
||||
@@ -10,113 +10,102 @@
|
||||
#include <locale.h>
|
||||
|
||||
#if __SIZEOF_WCHAR_T__ == 4
|
||||
static inline size_t mbrtoc32(uint32_t* restrict pc32, const char* restrict s, size_t n, mbstate_t* restrict ps)
|
||||
{
|
||||
return mbrtowc((wchar_t*) pc32, s, n, ps);
|
||||
}
|
||||
static inline size_t mbrtoc32(uint32_t* restrict pc32, const char* restrict s, size_t n, mbstate_t* restrict ps) {
|
||||
return mbrtowc((wchar_t*) pc32, s, n, ps);
|
||||
}
|
||||
#else
|
||||
#include <uchar.h>
|
||||
# include <uchar.h>
|
||||
#endif
|
||||
|
||||
static uint8_t getMbrWidth(const char* mbstr, uint32_t length, const char** next, mbstate_t* state)
|
||||
{
|
||||
static uint8_t getMbrWidth(const char* mbstr, uint32_t length, const char** next, mbstate_t* state) {
|
||||
if (__builtin_expect((uint8_t) *mbstr < 0x80, true)) // ASCII fast path
|
||||
{
|
||||
if (next) *next = mbstr + 1;
|
||||
if (next) {
|
||||
*next = mbstr + 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32_t c32;
|
||||
uint32_t len = (uint32_t) mbrtoc32(&c32, mbstr, length, state);
|
||||
if (len >= (uint32_t) -3)
|
||||
{
|
||||
if (len >= (uint32_t) -3) {
|
||||
// Invalid or incomplete multibyte sequence
|
||||
if (next) *next = mbstr + 1;
|
||||
if (next) {
|
||||
*next = mbstr + 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (next) *next = mbstr + len;
|
||||
if (next) {
|
||||
*next = mbstr + len;
|
||||
}
|
||||
int width = mk_wcwidth(c32);
|
||||
return width < 0 ? 0 : (uint8_t) width;
|
||||
}
|
||||
|
||||
static uint32_t getWcsWidth(const FFstrbuf* mbstr)
|
||||
{
|
||||
static uint32_t getWcsWidth(const FFstrbuf* mbstr) {
|
||||
mbstate_t state = {};
|
||||
uint32_t remainLength = mbstr->length;
|
||||
uint32_t result = 0;
|
||||
|
||||
const char* ptr = mbstr->chars;
|
||||
while (remainLength > 0 && *ptr != '\0')
|
||||
{
|
||||
while (remainLength > 0 && *ptr != '\0') {
|
||||
const char* lastPtr = NULL;
|
||||
result += getMbrWidth(ptr, remainLength, &lastPtr, &state);
|
||||
remainLength -= (uint32_t)(lastPtr - ptr);
|
||||
remainLength -= (uint32_t) (lastPtr - ptr);
|
||||
ptr = lastPtr;
|
||||
}
|
||||
|
||||
return result > 0 ? (uint32_t) result : mbstr->length;
|
||||
}
|
||||
|
||||
bool ffPrintSeparator(FFSeparatorOptions* options)
|
||||
{
|
||||
bool ffPrintSeparator(FFSeparatorOptions* options) {
|
||||
ffLogoPrintLine();
|
||||
|
||||
if(options->outputColor.length && !instance.config.display.pipe)
|
||||
if (options->outputColor.length && !instance.config.display.pipe) {
|
||||
ffPrintColor(&options->outputColor);
|
||||
}
|
||||
|
||||
if (options->times > 0)
|
||||
{
|
||||
if(__builtin_expect(options->string.length == 1, 1))
|
||||
if (options->times > 0) {
|
||||
if (__builtin_expect(options->string.length == 1, 1)) {
|
||||
ffPrintCharTimes(options->string.chars[0], options->times);
|
||||
else
|
||||
{
|
||||
for (uint32_t i = 0; i < options->times; i++)
|
||||
{
|
||||
} else {
|
||||
for (uint32_t i = 0; i < options->times; i++) {
|
||||
fputs(options->string.chars, stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
setlocale(LC_CTYPE, "");
|
||||
const FFPlatform* platform = &instance.state.platform;
|
||||
|
||||
uint32_t titleLength = 1 // @
|
||||
+ getWcsWidth(&platform->userName) // user name
|
||||
uint32_t titleLength = 1 // @
|
||||
+ getWcsWidth(&platform->userName) // user name
|
||||
+ (instance.state.titleFqdn ? platform->hostName.length : ffStrbufFirstIndexC(&platform->hostName, '.')); // host name
|
||||
|
||||
if(__builtin_expect(options->string.length == 1, 1))
|
||||
{
|
||||
if (__builtin_expect(options->string.length == 1, 1)) {
|
||||
ffPrintCharTimes(options->string.chars[0], titleLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
uint32_t wcsLength = getWcsWidth(&options->string);
|
||||
|
||||
int remaining = (int) titleLength;
|
||||
//Write the whole separator as often as it fits fully into titleLength
|
||||
for (; remaining >= (int) wcsLength; remaining -= (int) wcsLength)
|
||||
// Write the whole separator as often as it fits fully into titleLength
|
||||
for (; remaining >= (int) wcsLength; remaining -= (int) wcsLength) {
|
||||
ffStrbufWriteTo(&options->string, stdout);
|
||||
}
|
||||
|
||||
if (remaining > 0)
|
||||
{
|
||||
//Write as much of the separator as needed to fill titleLength
|
||||
if (wcsLength != options->string.length)
|
||||
{
|
||||
if (remaining > 0) {
|
||||
// Write as much of the separator as needed to fill titleLength
|
||||
if (wcsLength != options->string.length) {
|
||||
// Unicode chars
|
||||
const char* ptr = options->string.chars;
|
||||
mbstate_t state = {};
|
||||
const char* next = NULL;
|
||||
while (remaining > 0 && *ptr != '\0')
|
||||
{
|
||||
remaining -= (int) getMbrWidth(ptr, (uint32_t)(options->string.length - (ptr - options->string.chars)), &next, &state);
|
||||
while (remaining > 0 && *ptr != '\0') {
|
||||
remaining -= (int) getMbrWidth(ptr, (uint32_t) (options->string.length - (ptr - options->string.chars)), &next, &state);
|
||||
ptr = next;
|
||||
}
|
||||
fwrite(options->string.chars, (size_t) (ptr - options->string.chars), 1, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fwrite(options->string.chars, (size_t) remaining, 1, stdout);
|
||||
}
|
||||
}
|
||||
@@ -124,42 +113,38 @@ bool ffPrintSeparator(FFSeparatorOptions* options)
|
||||
setlocale(LC_CTYPE, "C");
|
||||
}
|
||||
|
||||
if(options->outputColor.length && !instance.config.display.pipe)
|
||||
if (options->outputColor.length && !instance.config.display.pipe) {
|
||||
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
|
||||
}
|
||||
putchar('\n');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffParseSeparatorJsonObject(FFSeparatorOptions* options, yyjson_val* module)
|
||||
{
|
||||
void ffParseSeparatorJsonObject(FFSeparatorOptions* options, yyjson_val* module) {
|
||||
yyjson_val *key, *val;
|
||||
size_t idx, max;
|
||||
yyjson_obj_foreach(module, idx, max, key, val)
|
||||
{
|
||||
if (unsafe_yyjson_equals_str(key, "type") || unsafe_yyjson_equals_str(key, "condition"))
|
||||
yyjson_obj_foreach (module, idx, max, key, val) {
|
||||
if (unsafe_yyjson_equals_str(key, "type") || unsafe_yyjson_equals_str(key, "condition")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (unsafe_yyjson_equals_str(key, "string"))
|
||||
{
|
||||
if (unsafe_yyjson_equals_str(key, "string")) {
|
||||
ffStrbufSetJsonVal(&options->string, val);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (unsafe_yyjson_equals_str(key, "outputColor"))
|
||||
{
|
||||
if (unsafe_yyjson_equals_str(key, "outputColor")) {
|
||||
ffOptionParseColor(yyjson_get_str(val), &options->outputColor);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (unsafe_yyjson_equals_str(key, "times"))
|
||||
{
|
||||
if (unsafe_yyjson_equals_str(key, "times")) {
|
||||
options->times = (uint32_t) yyjson_get_uint(val);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (unsafe_yyjson_equals_str(key, "length"))
|
||||
{
|
||||
if (unsafe_yyjson_equals_str(key, "length")) {
|
||||
ffPrintError(FF_SEPARATOR_MODULE_NAME, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "The option length has been renamed to times.");
|
||||
continue;
|
||||
}
|
||||
@@ -168,22 +153,19 @@ void ffParseSeparatorJsonObject(FFSeparatorOptions* options, yyjson_val* module)
|
||||
}
|
||||
}
|
||||
|
||||
void ffGenerateSeparatorJsonConfig(FFSeparatorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
void ffGenerateSeparatorJsonConfig(FFSeparatorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
||||
yyjson_mut_obj_add_strbuf(doc, module, "string", &options->string);
|
||||
yyjson_mut_obj_add_strbuf(doc, module, "outputColor", &options->outputColor);
|
||||
yyjson_mut_obj_add_uint(doc, module, "times", options->times);
|
||||
}
|
||||
|
||||
void ffInitSeparatorOptions(FFSeparatorOptions* options)
|
||||
{
|
||||
void ffInitSeparatorOptions(FFSeparatorOptions* options) {
|
||||
ffStrbufInitStatic(&options->string, "-");
|
||||
ffStrbufInit(&options->outputColor);
|
||||
options->times = 0;
|
||||
}
|
||||
|
||||
void ffDestroySeparatorOptions(FFSeparatorOptions* options)
|
||||
{
|
||||
void ffDestroySeparatorOptions(FFSeparatorOptions* options) {
|
||||
ffStrbufDestroy(&options->string);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user