fix: support Windows by selecting the correct default shell#66
Conversation
Ratty unconditionally fell back to `/bin/sh` when no shell was configured
and `$SHELL` was unset, which always fails on Windows:
Error: failed to spawn shell
Caused by:
CreateProcessW `"/bin/sh\0"` ... (os error 3)
Make the fallback platform-aware: on Windows prefer `%COMSPEC%` (the
resolved command processor) and fall back to `cmd.exe`. Other platforms
keep the existing `/bin/sh` fallback.
Verified on Windows 11 (RTX 5090, Vulkan): ratty.exe now launches
out-of-the-box, spawns `cmd.exe` as the PTY child via ConPTY, and the
3D rat cursor renders normally.
Fixes orhun#44
|
Hey, thanks for the PR! Maybe it also makes sense to default to git-bash exe if it exists on the system? see #44 |
Per @orhun's review on orhun#66: most users running terminal apps on Windows want a POSIX shell so the Ratatui demos behave the same as on Linux/macOS. The default-shell lookup now walks, in order: 1. `$SHELL` (already supported — useful when launching from Git Bash so the inherited shell is honoured). 2. Git for Windows `bash.exe` in well-known install locations: - `%ProgramW6432%\Git\{bin,usr/bin}\bash.exe` - `%ProgramFiles%\Git\{bin,usr/bin}\bash.exe` - `%ProgramFiles(x86)%\Git\{bin,usr/bin}\bash.exe` - `%LOCALAPPDATA%\Programs\Git\{bin,usr/bin}\bash.exe` 3. `bash.exe` anywhere on `PATH` (covers scoop / chocolatey installs). 4. `%COMSPEC%` (typically resolves to `cmd.exe`). 5. Literal `cmd.exe` as the final fallback. Verified on Windows 11 with Git for Windows installed at the default location — `bash.exe` is now the spawned PTY child: ProcessId : 204736 Name : bash.exe CommandLine : "C:\Program Files\Git/bin/bash.exe" Removing the Git install reverts to the `%COMSPEC%` / `cmd.exe` fallback verified by the previous commit.
|
Thanks! Just pushed b521537 on top — Verified on Windows 11 — with Git installed it now spawns |
|
Investigated the RGP examples on Windows next — wanted to flag what I found before scope-creeping this PR. TL;DR: the path-/payload-handling code in How I confirmed it: wrote a tiny Only the bash-init CSIs survive — the APC body and ST terminator are dropped by conhost. (Same outcome when running The fix lives upstream in Proposed path forward:
Happy to file a tracking issue against Ratty in the meantime so this doesn't get lost. |
Per @orhun's review on orhun#66: most users running terminal apps on Windows want a POSIX shell so the Ratatui demos behave the same as on Linux/macOS. The default-shell lookup now walks, in order: 1. `$SHELL` (already supported — useful when launching from Git Bash so the inherited shell is honoured). 2. Git for Windows `bash.exe` in well-known install locations: - `%ProgramW6432%\Git\{bin,usr/bin}\bash.exe` - `%ProgramFiles%\Git\{bin,usr/bin}\bash.exe` - `%ProgramFiles(x86)%\Git\{bin,usr/bin}\bash.exe` - `%LOCALAPPDATA%\Programs\Git\{bin,usr/bin}\bash.exe` 3. `bash.exe` anywhere on `PATH` (covers scoop / chocolatey installs). 4. `%COMSPEC%` (typically resolves to `cmd.exe`). 5. Literal `cmd.exe` as the final fallback. Verified on Windows 11 with Git for Windows installed at the default location — `bash.exe` is now the spawned PTY child: ProcessId : 204736 Name : bash.exe CommandLine : "C:\Program Files\Git/bin/bash.exe" Removing the Git install reverts to the `%COMSPEC%` / `cmd.exe` fallback verified by the previous commit.
b521537 to
fbc8e2d
Compare
|
Pushed fbc8e2d (force-update of b521537) — refactored Heads-up on the RGP follow-up — my earlier comment was wrong. I pulled a vendored Result: ConPTY still strips APC sequences even with So bash emits the APC correctly, and ConPTY drops it regardless of the passthrough flag. The I'm going to take this back to the drawing board (OSC-wrapped RGP / side-loaded openconsole |
|
Side-load test: latest Pulled Same APC-emitting bash script, both with and without Cross-checked against an upstream research dive (Microsoft Terminal PR #17510, issue #17313, Ecosystem Roadmap):
So both ConPTY hypotheses are dead:
This makes OSC-wrapped RGP the only viable path on Windows. It's not pretty, but it's the path that works without waiting for Microsoft to add APC to the passthrough roadmap (which it isn't on). I'll update #67 with the full evidence and start sketching what an OSC wrapping might look like that survives ConPTY's ordering quirk. The shell-default work in this PR remains fully independent of this rabbit-hole. |
orhun
left a comment
There was a problem hiding this comment.
LGTM, thanks!
Let's discuss the proper windows support in another issue
Summary
Fixes #44 — Ratty fails to start on Windows because
runtime.rsunconditionally falls back to/bin/shwhen no shell is configured and$SHELLis unset:This makes the fallback platform-aware:
%COMSPEC%(the resolved command processor — typicallyC:\Windows\System32\cmd.exe), fall back tocmd.exe./bin/sh.User-set
[shell] program = "..."inratty.tomland an inherited$SHELLenv var (e.g. when launching from Git Bash) still take priority — those paths are untouched.The change
A single 16-line
default_shell()helper insrc/runtime.rs, gated with#[cfg(windows)]/#[cfg(not(windows))]. No new dependencies, no public API changes, no behavior change on Linux/macOS.Verification on Windows 11
Tested on Windows 11 Pro 26200.6457, RTX 5090 (Vulkan backend), Rust 1.x stable.
Before this PR (reproduced cleanly with
$env:SHELL=$nullin PowerShell):After this PR (same conditions, no config file, no
$SHELL):Verified end-to-end:
ratty.exelaunches without errors with no$SHELLand no config file.cmd.exeis spawned as the PTY child (confirmed viaWin32_Processparent-child lookup).CairoSpinyMouse.obj.Checks
Run on Windows from the project root:
cargo fmt --all -- --check— passescargo check— passescargo clippy --all-targets --all-features -- -D warnings— passescargo build --release— passes