Skip to content

fix(cli): prevent carriage returns (^M) in help menu on Windows - #19629

Merged
fdncred merged 3 commits into
nushell:mainfrom
abdul-karim-mia:fix/help-menu-carriage-returns
Nov 23, 2026
Merged

fdncred merged 3 commits into
nushell:mainfrom
abdul-karim-mia:fix/help-menu-carriage-returns

Conversation

@abdul-karim-mia

@abdul-karim-mia abdul-karim-mia commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

In crates/nu-cli/src/menus/help_completions.rs, NuHelpCompleter was hardcoding \r\n line separators and transforming command examples with .replace('\n', "\r\n"). In raw terminal mode, reedline splits completion descriptions by \n, leaving behind unstripped carriage returns (\r) at the end of each line which render as literal ^M glyphs in the F1 help menu. Furthermore, multiline examples sourced from CRLF files preserved \r\n.

This PR standardizes NuHelpCompleter on \n line endings, normalizes multiline examples via .replace("\r\n", "\n"), and adds a comprehensive test asserting that no command's completion description or example contains carriage returns.

User-facing changes (Release notes)

  • Fixed literal ^M characters in the F1 help menu.

Additional notes

closes #19617

@fdncred

fdncred commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

@kronberger-droid I thought we already fixed this?

@kronberger-droid

Copy link
Copy Markdown
Contributor

Yeah I thought so too... but might be another case, where escaping showed a parser bug.

@kronberger-droid

Copy link
Copy Markdown
Contributor

Well that seems more like hardcoded ones.

@kronberger-droid

Copy link
Copy Markdown
Contributor

I am fine with landing this after you make clippy happy. But it opened up an issue in reedline, that should fix why we had to print /r/n in the first place.

@abdul-karim-mia

Copy link
Copy Markdown
Contributor Author

@kronberger-droid Clippy is happy now! Replaced write! with writeln! in help_completions.rs to address write_with_newline. Ready for review.

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review overview

🟡 Changes recommended

The fix works for the built-in help text: on macOS, F1 on cd shows 21 ^Ms on main and none on the branch. A multi-line @example from a CRLF file still shows one, and the new test passes with three of the changed lines reverted.

Findings: 0 High severity · 1 Medium severity · 2 Low severity

Open (3)

Notes from my clanker, checked on f665096. Built the branch on Windows 10 and on macOS, and drove the F1 menu on both for cd, attr complete and a command sourced from a CRLF file: against 0.117.1 on Windows (over ssh, through ConPTY) and main (e3bf397) in a pty on macOS. Multi-line examples line up on both. On both, cargo test -p nu-cli --lib -- menus::help_completions passed 4, still passed 4 with three changed lines reverted to \r\n, and the suggested test failed with the revert and passed on the head. I didn't rerun clippy or the full tests, since CI is green on this head.

@abdul-karim-mia

Copy link
Copy Markdown
Contributor Author

@fdncred Thank you so much for the thorough review and testing! All three recommendations have been addressed in commit 2260f5f:

  1. Normalized multiline examples via .replace("\r\n", "\n") in help_completions.rs.
  2. Added the comprehensive help_menu_text_has_no_carriage_returns test iterating over all command suggestions to verify descriptions and examples are free of carriage returns.
  3. Updated the release notes and PR description to reflect that the fix resolves literal ^M across all platforms.

Ready for re-review whenever you have time, thanks!

@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Nov 23, 2026
@fdncred
fdncred merged commit 976d894 into nushell:main Nov 23, 2026
14 checks passed
@fdncred

fdncred commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Thanks

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

Labels

notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

F1 help viewer displays literal carriage returns (^M) in help output on Windows (0.117.0)

3 participants