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

Crossterm works partially for MSYS, CGWIN, Mintty, CI/CD on Windows. #580

Open
TimonPost opened this issue Jul 1, 2021 · 5 comments
Open

Comments

@TimonPost
Copy link
Member

TimonPost commented Jul 1, 2021

Describe the bug
MSYS, CGWIN, Mintty (e.g. gitbash, windows ssh-terminals) have in common that they are tools that do not have access to the internal WinAPI of windows. This is a problem when they try to do operations that are implemented with system calls (not via ANSI codes). This is the case for retrieving operations like input, terminal size, cursor position. Operations that use ANSI codes work perfectly fine.

  • Cygwin a large collection of GNU and Open Source tools that provide functionality similar to a Linux distribution on Windows.The unixy tools in MSYS2 are directly based on Cygwin, so there is some overlap there.
  • While Cygwin focuses on building Unix software on Windows as is, MSYS2 focuses on building native software built against the Windows APIs.
  • Mintty is an open-source terminal emulator for Cygwin, a Unix-like environment for Windows.
  • Most CI systems will not have access to a native terminal device.

According to the creator of winapi rust crate, he said:

For MinTTY the handles are pipes, not consoles
if you have a pipe, you use ReadFile and WriteFile
regardless of whether it is just a pipe, or actually a TTY like git bash
if you have a console then you use the console functions like WriteConsoleW and ReadConsoleW
you never ever use libc stuff on windows

So apparently crossterm will have not access to the console handles in the mentioned emulators. And perhaps a workaround is to use read/write file instead for read/write console. But this solution is different for each type of retrieving operation. I am not sure how to go about this, if one has any ideas on the best way to go around this, feel free to leave a comment.

Related issues:

@TimonPost TimonPost changed the title Crossterm not working for MSYS, CGWIN, Mintty, CI/CD Crossterm works partially for MSYS, CGWIN, Mintty, CI/CD on Windows. Jul 1, 2021
@TimonPost TimonPost pinned this issue Jul 1, 2021
@natbraun
Copy link
Contributor

For terminal size, on Git Bash (which uses MSYS2 behind the scenes), tput cols and tput lines seem to work.

@rashil2000
Copy link

rashil2000 commented Aug 29, 2021

Hi @TimonPost

Just wanted to add something to the discussion here - someone might find it useful.
(I tried many TUI programs that use the crossterm-rs backend - listed below.)

For mintty terminal

Most Windows-native, non-MSYS2 apps don't work inside mintty, You need to set the environment variable MSYS to enable_pcon, and then launch mintty - to make Windows-native apps work fully. More info can be found in this discussion mintty/wsltty#271.

For conhost, or (newer) Windows terminal

When using Git Bash, you need to launch the TUI apps with the TERM variable unset (MSYS2 sets it to xterm-256color), like so:

alias ttyper='TERM= ttyper'
alias lapin='TERM= lapin'
alias btm='TERM= btm'
alias rusty-rain='TERM= rusty-rain'
alias gping='TERM= gping'
alias pipes-rs='TERM= pipes-rs'

@glenmurphy
Copy link

FWIW, in MINGW64, if I build+run my crossterm app with "cargo run", it works great, but if I try to directly run the same generated exe, it creates the console spew outlined above.

Running "./target/debug/myexe.exe | cat" works (but slowly)

@sigoden
Copy link

sigoden commented Apr 11, 2022

In MSYS2 (git bash), directly run exe not works, but run with npm run or cargo run works.

@Kreijstal
Copy link

trick: when on mintty, try "shell command" instead of command, shell in msys2, uses dark magic to make it work better, sometimes, at least on windows 8 where there is no conpty

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

6 participants