aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2022-01-13 10:48:03 +0000
committerDaniel Eklöf <daniel@ekloef.se>2022-01-13 10:48:03 +0000
commit69ec74a605dc87b6f28a816b59648989ca057815 (patch)
tree1041e0eb1b9f670b74ace46512418d6682f43f77
parentMerge branch 'improve-mouse-button-multi-click' (diff)
parentmain: log locale errors (in addition to adding a user notification) (diff)
Merge branch 'bad-locale'
-rw-r--r--CHANGELOG.md5
-rw-r--r--main.c52
2 files changed, 54 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 85906524..07205da0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -47,6 +47,7 @@
* [SGR-Pixels (1016) mouse extended coordinates](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Extended-coordinates) is now supported
(https://codeberg.org/dnkl/foot/issues/762).
+
### Changed
* PaperColorDark and PaperColorLight themes renamed to
@@ -58,6 +59,10 @@
* The width of the block cursor’s outline in an unfocused window is
now scaled by the output scaling factor (“desktop
scaling”). Previously, it was always 1px.
+* Foot will now try to change the locale to either “C.UTF-8” or
+ “en_US.UTF-8” if started with a non-UTF8 locale. If this fails, foot
+ will start, but only to display a window with an error (user’s shell
+ is not executed).
### Deprecated
diff --git a/main.c b/main.c
index 34f72a7c..7d57c641 100644
--- a/main.c
+++ b/main.c
@@ -424,10 +424,48 @@ main(int argc, char *const *argv)
LOG_ERR("setlocale() failed");
return ret;
}
+
LOG_INFO("locale: %s", locale);
- if (!locale_is_utf8()) {
- LOG_ERR("locale is not UTF-8");
- return ret;
+
+ bool bad_locale = !locale_is_utf8();
+ if (bad_locale) {
+ static const char fallback_locales[][12] = {
+ "C.UTF-8",
+ "en_US.UTF-8",
+ };
+
+ /*
+ * Try to force an UTF-8 locale. If we succeed, launch the
+ * user’s shell as usual, but add a user-notification saying
+ * the locale has been changed.
+ */
+ for (size_t i = 0; i < ALEN(fallback_locales); i++) {
+ const char *const fallback_locale = fallback_locales[i];
+
+ if (setlocale(LC_CTYPE, fallback_locale) != NULL) {
+ LOG_WARN("locale '%s' is not UTF-8, using '%s' instead",
+ locale, fallback_locale);
+
+ user_notification_add_fmt(
+ &user_notifications, USER_NOTIFICATION_WARNING,
+ "locale '%s' is not UTF-8, using '%s' instead",
+ locale, fallback_locale);
+
+ bad_locale = false;
+ break;
+ }
+ }
+
+ if (bad_locale) {
+ LOG_ERR("locale '%s' is not UTF-8, "
+ "and failed to enable a fallback locale", locale);
+
+ user_notification_add_fmt(
+ &user_notifications, USER_NOTIFICATION_ERROR,
+ "locale '%s' is not UTF-8, "
+ "and failed to enable a fallback locale",
+ locale);
+ }
}
struct config conf = {NULL};
@@ -502,6 +540,14 @@ main(int argc, char *const *argv)
conf.fonts[0].arr[0].pattern, &conf.notifications);
}
+
+ if (bad_locale) {
+ static char *const bad_locale_fake_argv[] = {"/bin/sh", "-c", "", NULL};
+ argc = 1;
+ argv = bad_locale_fake_argv;
+ conf.hold_at_exit = true;
+ }
+
struct fdm *fdm = NULL;
struct reaper *reaper = NULL;
struct wayland *wayl = NULL;