mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Global: better handling locales
This commit is contained in:
+8
-1
@@ -8,9 +8,9 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <locale.h>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <locale.h>
|
||||
#include "util/windows/unicode.h"
|
||||
#else
|
||||
#include <signal.h>
|
||||
@@ -51,6 +51,13 @@ void ffInitInstance(void)
|
||||
#ifdef WIN32
|
||||
//https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setlocale-wsetlocale?source=recommendations&view=msvc-170#utf-8-support
|
||||
setlocale(LC_ALL, ".UTF8");
|
||||
#else
|
||||
// Never use `setlocale(LC_ALL, "")`
|
||||
setlocale(LC_TIME, "");
|
||||
setlocale(LC_NUMERIC, "");
|
||||
#ifdef LC_MESSAGES
|
||||
setlocale(LC_MESSAGES, "");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
initState(&instance.state);
|
||||
|
||||
@@ -12,12 +12,11 @@ void ffDetectLocale(FFstrbuf* result)
|
||||
if(result->length > 0)
|
||||
return;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
#ifdef LC_MESSAGES
|
||||
ffStrbufAppendS(result, setlocale(LC_MESSAGES, NULL));
|
||||
|
||||
if(result->length == 0)
|
||||
ffStrbufAppendS(result, setlocale(LC_ALL, NULL));
|
||||
if(result->length > 0)
|
||||
return;
|
||||
#endif
|
||||
setlocale(LC_ALL, "C");
|
||||
|
||||
ffStrbufAppendS(result, setlocale(LC_TIME, NULL));
|
||||
}
|
||||
|
||||
@@ -33,8 +33,7 @@ static inline uint32_t getWcsWidth(const FFstrbuf* mbstr, wchar_t* wstr, mbstate
|
||||
|
||||
void ffPrintSeparator(FFSeparatorOptions* options)
|
||||
{
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
setlocale(LC_CTYPE, "");
|
||||
mbstate_t state = {};
|
||||
bool fqdn = instance.config.modules.title.fqdn;
|
||||
const FFPlatform* platform = &instance.state.platform;
|
||||
@@ -90,8 +89,7 @@ void ffPrintSeparator(FFSeparatorOptions* options)
|
||||
}
|
||||
}
|
||||
putchar('\n');
|
||||
|
||||
setlocale(LC_ALL, "C");
|
||||
setlocale(LC_CTYPE, "C");
|
||||
}
|
||||
|
||||
bool ffParseSeparatorCommandOptions(FFSeparatorOptions* options, const char* key, const char* value)
|
||||
|
||||
Reference in New Issue
Block a user