Skip to content

Why mosh forces NCURSES_NO_UTF8_ACS to be 1? #1127

Closed

Description

@mrkn

This is just a question. I'd like to know the reason why mosh-server defines NCURSES_NO_UTF8_ACS to be 1 during the initialization phase.

By the way, I confirmed that tmux works well via mosh without defining NCURSES_NO_UTF8_ACS.

Activity

  1. keithw commented on Jan 26, 2021

    @keithw
    Member

    Hi -- the reason is that Mosh follows Kuhn's "UTF-8 and Unicode FAQ for Unix/Linux" rules and ignores ISO 2022 stateful "locking shifts" to switch into the Alternate Character Set (ACS). Instead, the application just uses Unicode coded characters for the desired symbols directly, rather than "switching" to an alternate charset that the terminal can get stuck in if nothing switches back. We advertise this on the Mosh homepage ("Mosh will never get stuck in hieroglyphs when a nasty program writes to the terminal.")

    Mosh is a newer, UTF-8-only, terminal so it has the luxury of only supporting the "new" behavior. The input to the Mosh terminal emulator state machine is always a UTF-8-encoded Unicode scalar value. But most terminal emulators originated in the "byte-by-byte" days, and so they support both "byte-by-byte" mode and "scalar-value-by-scalar-value" modes as input to the terminal state machine. Despite Kuhn's FAQ, most of them retained their legacy behavior, and continue to honor the ISO 2022 locking shifts, even in UTF-8 mode. (PuTTY is one exception that behaves more like Mosh.)

    Meanwhile, applications (and libraries like ncurses) have no portable way to tell if the input to the terminal emulator's state machine is bytes or Unicode scalar values. (The TERM values weren't updated in this transition, and things like "xterm-utf8" only came much later.)

    The NCURSES_NO_UTF8_ACS environment variable tells ncurses to use UTF-8 coded characters directly and not locking shifts to render the characters in the "alternate" charset.

    Some more info here: https://stackoverflow.com/questions/37845244/acs-characters-not-working-in-putty-even-with-export-ncurses-no-utf8-acs-1

  2. keithw commented on Jan 26, 2021

    @keithw
    Member

    Programs like screen, tmux, and luit can interpret the ISO 2022 locking shifts themselves and render them into ISO 10646 (Unicode) coded characters, so that's why these can show up okay in Mosh (and PuTTY) even if the application continues to use the ISO 2022 locking shifts! Of course then you can get stuck in hieroglyphs within the screen/tmux/luit session. Hope all this info is helpful!

  3. keithw commented on Jan 26, 2021

    @keithw
    Member
  4. mrkn commented on Jan 26, 2021

    @mrkn
    Author

    Thank you for explaining the reason in detail. It is very helpful for me.

  5. trysten commented on Aug 21, 2025

    @trysten

    Finding this thread, years after struggling with the issue, i finally completely understand. Thank you.

    For later visitors: if you are seeing issues when running commands with sudo, it's because you need to preserve the NCURSES_NO_UTF8_ACS with sudo -E

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions