auto-fallback to UTF-8 locale when MB_CUR_MAX exceeds limit #86

Open
opened 2026-02-06 11:16:28 +00:00 by jabber.developer2 · 0 comments
Collaborator

Summary

Currently, when MB_CUR_MAX exceeds PROF_MB_CUR_MAX, we show an error and disable the input window. The user must manually run export LC_ALL=C.UTF-8 before starting profanity.

Proposal

Automatically attempt to switch to a safe UTF-8 locale at runtime and notify the user.

Implementation

if (MB_CUR_MAX > PROF_MB_CUR_MAX) {
    const char* fallbacks[] = {"C.UTF-8", "en_US.UTF-8", "POSIX", NULL};
    for (int i = 0; fallbacks[i]; i++) {
        if (setlocale(LC_ALL, fallbacks[i])) {
            cons_show_warn("Locale auto-switched to %s (original MB_CUR_MAX exceeded limit)", fallbacks[i]);
            break;
        }
    }
    if (MB_CUR_MAX > PROF_MB_CUR_MAX) {
        cons_show_error("Unsupported locale...");
        return;
    }
}

Benefits

  • Better UX: works out-of-the-box on exotic locales
  • User is informed about the fallback
  • Preserves current behavior if fallback fails

Considerations

  • setlocale() affects the entire process — document this
  • May want a config option to disable auto-fallback
  • Test on various distros with different locale availability

Dependencies

  • Requires #XX (cons_show_warn() implementation)
## Summary Currently, when `MB_CUR_MAX` exceeds `PROF_MB_CUR_MAX`, we show an error and disable the input window. The user must manually run `export LC_ALL=C.UTF-8` before starting profanity. ## Proposal Automatically attempt to switch to a safe UTF-8 locale at runtime and notify the user. ### Implementation ```c if (MB_CUR_MAX > PROF_MB_CUR_MAX) { const char* fallbacks[] = {"C.UTF-8", "en_US.UTF-8", "POSIX", NULL}; for (int i = 0; fallbacks[i]; i++) { if (setlocale(LC_ALL, fallbacks[i])) { cons_show_warn("Locale auto-switched to %s (original MB_CUR_MAX exceeded limit)", fallbacks[i]); break; } } if (MB_CUR_MAX > PROF_MB_CUR_MAX) { cons_show_error("Unsupported locale..."); return; } } ``` ### Benefits - Better UX: works out-of-the-box on exotic locales - User is informed about the fallback - Preserves current behavior if fallback fails ### Considerations - `setlocale()` affects the entire process — document this - May want a config option to disable auto-fallback - Test on various distros with different locale availability ### Dependencies - Requires #XX (`cons_show_warn()` implementation)
jabber.developer2 added the
Kind/Enhancement
Priority
Low
4
labels 2026-02-06 11:16:28 +00:00
jabber.developer2 added this to the Plans (2025-2026) project 2026-02-06 11:16:28 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: devs/cproof#86
No description provided.