Skip to content

fix(prompt): write PS0 expansion to stderr, matching GNU (eval.c:176) - #233

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/ps0-stream
Oct 9, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/ps0-stream

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

PS0's decoded expansion was written to stdout; GNU bash writes it to stderr (eval.c:164-176, fprintf (stderr, ...)). Redirected pipelines observed the opposite shape: niu 2>/dev/null kept the PS0 bytes, niu > file captured them. This aligns the PS0 output channel with GNU.

Changes

  • crates/niubash-runtime/src/shell.rs (run_bash_ps0_preexec): emit the decoded PS0 through a new shell_channel_write(ShellChannel::Stderr, ...) seam instead of raw stdout writes.
  • The PS1 rendering channel is untouched: prompt output still flows through the PromptBackend/reedline editor path, and the BashPrompt marker-stripping behavior documented in prompt.rs (a different channel from PS0) is unchanged.
  • Regression test bash_ps0_expansion_targets_stderr_and_stdout_stays_clean: non-tty, captures the channel choice via a cfg(test) seam and asserts the decoded PS0 bytes land on the stderr channel exactly once with zero stdout-channel writes.

Testing

  • cargo test -p niubash-runtime --lib -- ps0 prompt: 47 passed (includes the new test and the existing bash_ps0_runs_before_interactive_command).
  • cargo test -p niubash-runtime --lib: 383 passed; the only 3 failures are the pre-existing network-dependent plugins::distros git-clone tests (verified failing on the unmodified baseline — environment network resets, unrelated).
  • Integration suites theme_preview_channel (6), issue117_foreign_ps1 (5), smoke (13): all green.

Closes #190

niu's PS0 pre-exec output went to stdout while GNU bash writes the
decoded PS0 string to stderr (eval.c:164-176 fprintf). For redirected
pipelines the captured shape differed: `niu 2>/dev/null` kept the PS0
bytes on stdout and `niu > file` captured them, the opposite of GNU.

Route the write through a ShellChannel seam (Stdout/Stderr) and emit
PS0 on Stderr. The PS1 rendering channel is untouched: prompt rendering
still flows through the PromptBackend/reedline editor path, and the
existing BashPrompt marker-stripping behavior (a different channel,
per prompt.rs) is unchanged.

Regression test: bash_ps0_expansion_targets_stderr_and_stdout_stays_clean
captures the channel choice non-interactively and asserts the decoded
PS0 bytes land on stderr exactly once with stdout clean.

Closes #190.
@caomengxuan666
caomengxuan666 merged commit 3606dda into master Oct 9, 2026
3 of 9 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/ps0-stream branch October 9, 2026 13:25
caomengxuan666 added a commit that referenced this pull request Oct 10, 2026
- Delete docs/eco-harvest-resume-wt97b.md: point-in-time lane resume/handoff snapshot; the harvest/test line now runs on GitHub Actions (eco-harvest-ci.yml) and the diagnosis lives in git history.
- CHANGELOG: add Unreleased entries for strip (#228), setup help/non-tty banner (#229), bundled niugit/ripgrep/fd + setup detection (#230/#231), PROMPT_COMMAND exit jump (#232), PS0 stderr (#233), bracketed paste (#234).

Co-authored-by: docs-audit <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P2] PS0 输出流差异:niu 写 stdout,GNU 写 stderr(eval.c:176)——wt99 审计记录

1 participant