fix(wasix): preserve CR and LF in noncanonical tty mode - #6863
Open
theduke wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes WASIX TTY raw-mode behavior on Unix by preventing host-side carriage-return translation when switching to non-canonical (raw-ish) input, and restoring canonical CR→LF handling when returning to cooked mode. This addresses interactive apps that need to distinguish Enter (\r) from other newline-like inputs (e.g. LF).
Changes:
- Centralizes canonical/raw toggling via
set_line_buffering, including input-flag handling (ICRNL/IGNCR). - Restores canonical CR-to-LF translation when re-enabling line buffering or resetting the terminal.
- Adds flag-level tests and a PTY regression test to validate CR/LF behavior.
Suppressed comments (2)
lib/wasix/src/os/tty/tty_sys.rs:255
- The unit test for raw input only asserts that
ICRNL/IGNCRare cleared. IfINLCRis set, LF can still be translated to CR, so it would be good for the test to cover that flag as well (especially since the comment mentions Shift+Enter behavior).
state.c_iflag = ICRNL | IGNCR | IXON;
lib/wasix/src/os/tty/tty_sys.rs:268
- Similarly, the cooked-mode flag test could include
INLCRto ensure it’s cleared when returning to canonical mode (so LF isn’t unexpectedly mapped to CR).
state.c_iflag = IGNCR | IXON;
theduke
marked this pull request as draft
August 6, 2026 20:30
theduke
marked this pull request as ready for review
August 7, 2026 10:24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
When a WASIX guest disables canonical input, the host terminal now disables all three CR/LF input translations:
ICRNL,INLCR, andIGNCR. Re-enabling canonical input restores the conventional cooked mapping (ICRNLon,INLCRandIGNCRoff). Terminal reset uses the same cooked configuration.Why
Interactive programs need to distinguish Enter (
CR, byte0x0d) from line feed (LF, byte0x0a). WASIX previously disabledICANONbut leftICRNLenabled on the host terminal. The terminal driver therefore converted Enter to LF before the guest could read it.This showed up in the Pi coding agent running through EdgeJS: pressing Enter inserted a newline instead of submitting the prompt. Pi was acting on the byte it received; the conversion happened in the WASIX host TTY bridge. Running with
stty -icrnlconfirmed the source of the problem.This change is intentionally limited to newline translation. Noncanonical mode is not necessarily full raw mode, and the current WASIX TTY ABI does not carry enough termios state to infer or reproduce
cfmakeraw(). Flags such asISIG,IXON, andOPOSTare therefore left unchanged.Tests
The flag-level tests cover both mode transitions and verify that unrelated signal, flow-control, echo, and output settings are preserved. A real pseudoterminal regression test sends CR and LF through the kernel terminal driver, verifies that they remain distinct in noncanonical mode, and then verifies that cooked mode maps CR to LF again. PTY reads use a timeout so a regression fails instead of hanging.
nix develop -c cargo test -p wasmer-wasix --features sys --lib— 226 passed, 2 ignorednix develop -c cargo fmt --all -- --checkgit diff --check