mirror of
https://github.com/aristocratos/btop.git
synced 2024-09-28 14:11:35 +02:00
More fixes for UTF-8 detection
This commit is contained in:
parent
5273a62856
commit
94feb4e16e
23
src/btop.cpp
23
src/btop.cpp
@ -718,27 +718,30 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//? Try to find and set a UTF-8 locale
|
//? Try to find and set a UTF-8 locale
|
||||||
if (bool found = false; std::setlocale(LC_ALL, NULL) != NULL and not str_to_upper(s_replace((string)std::setlocale(LC_ALL, NULL), "-", "")).ends_with("UTF8")) {
|
if (bool found = false; std::setlocale(LC_ALL, NULL) == NULL or not str_to_upper(s_replace((string)std::setlocale(LC_ALL, NULL), "-", "")).ends_with("UTF8")) {
|
||||||
if (getenv("LANG") != NULL and str_to_upper(s_replace((string)getenv("LANG"), "-", "")).ends_with("UTF8")) {
|
if (getenv("LANG") != NULL and str_to_upper(s_replace((string)getenv("LANG"), "-", "")).ends_with("UTF8")) {
|
||||||
if (std::setlocale(LC_ALL, getenv("LANG")) != NULL) {
|
if (std::setlocale(LC_ALL, getenv("LANG")) != NULL) {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setenv("LANG", "", 1);
|
if (setenv("LANG", "", 1) == 0) {
|
||||||
try {
|
try {
|
||||||
if (const auto loc = std::locale("").name(); not loc.empty()) {
|
if (const auto loc = std::locale("").name(); not loc.empty() and loc != "*") {
|
||||||
for (auto& l : ssplit(loc, ';')) {
|
for (auto& l : ssplit(loc, ';')) {
|
||||||
if (str_to_upper(s_replace(l, "-", "")).ends_with("UTF8")) {
|
if (str_to_upper(s_replace(l, "-", "")).ends_with("UTF8")) {
|
||||||
if (std::setlocale(LC_ALL, l.substr(l.find('=') + 1).c_str()) != NULL)
|
if (std::setlocale(LC_ALL, l.substr(l.find('=') + 1).c_str()) != NULL) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (...) { found = false; }
|
||||||
}
|
}
|
||||||
catch (...) { found = false; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not found and Global::utf_force)
|
if (not found and Global::utf_force)
|
||||||
Logger::warning("No UTF-8 locale detected! Forcing start with --utf-force argument.");
|
Logger::warning("No UTF-8 locale detected! Forcing start with --utf-force argument.");
|
||||||
else if (not found) {
|
else if (not found) {
|
||||||
|
Loading…
Reference in New Issue
Block a user