Skip to content

fix(repl): interactive exit/logout accept optional status and end the session - #541

Merged
caomengxuan666 merged 1 commit into
unixwin:masterfrom
Catapult291:fix/repl-exit-status-argument
Oct 23, 2026
Merged

caomengxuan666 merged 1 commit into
unixwin:masterfrom
Catapult291:fix/repl-exit-status-argument

Conversation

@Catapult291

Copy link
Copy Markdown
Collaborator

Summary

Interactive REPL only treated a line that was exactly exit / logout as session end. exit 3 ran the engine builtin (printed exit) but the host loop kept the session alive.

Changes

  • repl_exit_status(): first-word exit/logout, optional -- and one numeric status (rem_euclid(256)), tolerate trailing ;; invalid forms stay in REPL for engine diagnostics (exit abc, exit 3 4).
  • end_repl_session(): EXIT trap → flush history → flush output → std::process::exit(code).
  • Share is_exit_word() with reserved-word highlighter.
  • Unit tests for accepted and diagnosed shapes.

Related closed issues #399/#402/#404 are startup rc exit, not interactive exit N.

Test plan (ConPTY / real interactive)

Input After
exit 3 session ends, host rc=3
exit / logout rc=0
exit 300 rc=44
exit abc, exit 3 4 stay in REPL + diagnostic
niu -c / -i -c unchanged

Niubash defect log D1 (2026-10-23). Known residual (out of scope): true; exit 3 / alias bye=exit; bye 3.

…026-10-23)

Interactive exit N / logout N now ends the session with the host exit
code; bare exit stays rc 0; exit abc / exit 3 4 stay in the REPL and
defer to the engine diagnostics. Shared is_exit_word() keeps the
reserved-word highlighter aligned with the intercept.
@caomengxuan666
caomengxuan666 merged commit 1fc999b into unixwin:master Oct 23, 2026
11 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member

Nice catch — exit 3 killing the engine builtin but not the host loop is exactly the kind of split-brain this architecture invites, and the rem_euclid(256) status handling matches what a real shell does on Windows. Invalid forms falling back to engine diagnostics is the right boundary. Merged.

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.

2 participants