Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rye mangles/strips escape sequences when run in cmd.exe with stdout redirected #1092

Open
mataha opened this issue May 18, 2024 · 0 comments

Comments

@mataha
Copy link
Contributor

mataha commented May 18, 2024

I've been hacking together an improvement to rye-up.com/get that would enable Windows users to install rye in the same way Linux and macOS users can (piping curl output to shell), though I've hit a wall - no matter what I do, the executable is unable to produce correct output with stdout redirected.

Steps to Reproduce

git clone -b feat/windows/install --single-branch https://github.com/mataha/rye
cd rye
::: Notice I'm redirecting stdout to `nul` here - this is necessary as `cmd.exe`
::: prints every command executed when evaluating piped input, prompts included
curl -fsSL "file:///%CD%/scripts/install.cmd" | cmd /d/x/k >nul

Expected Result

image

Actual Result

As expected - text is on stdout, which is redirected to nul (though the prompt remains visible):

image

Redirecting the binary's output to stderr makes the entire text get mangled:
::: This makes invoking the binary roughly equivalent to `rye self install >&2`
set "RYE_INSTALL_OPTIONS=>&2"

image

With the following change all ANSI escape sequences are stripped except those in prompts (last line):
diff --git a/rye/src/cli/rye.rs b/rye/src/cli/rye.rs
index 72d7ca357ff3..733710bad41e 100644
--- a/rye/src/cli/rye.rs
+++ b/rye/src/cli/rye.rs
@@ -525,6 +525,7 @@ fn perform_install(
         },
     };

+    let _guard = crate::tui::redirect_to_stderr(true);
     echo!("{}", style("Welcome to Rye!").bold());

     if matches!(mode, InstallMode::AutoInstall) {

image

I have no idea what's going on; why is dialoguer able to work correctly in every instance?
Admittedly I don't believe this is a bug in rye itself, but I have to start somewhere.

Version Info

rye 0.34.0
commit: 0.33.0+14 (761e4b583 2024-05-18)
platform: windows (x86_64)
self-python: cpython@3.12.3
symlink support: true
uv enabled: true
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

No branches or pull requests

1 participant