Skip to content

mintty.exe is a strange terminal #134

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

Open
gabyx opened this issue Jun 11, 2021 · 5 comments
Open

mintty.exe is a strange terminal #134

gabyx opened this issue Jun 11, 2021 · 5 comments

Comments

@gabyx
Copy link

gabyx commented Jun 11, 2021

It would be really nice if somebody could look at the following issue:
golang/go#46681

It demonstrates the fact that git-bash.exe and also mingw.exe really behave strange, when we want to the get the controlling terminal file input CONIN$ on windows.

This is basically done in GO with:

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"syscall"

	"golang.org/x/term"
)

func GetCttyIn() (io.Reader, error) {
	in, err := syscall.Open("CONIN$", syscall.O_RDWR, 0)
	if err != nil {
		return nil, err
	}

	fmt.Println("$CONIN Isterm: ", isatty.IsTerminal(uintptr(in)))

	return os.NewFile(uintptr(in), "/dev/tty"), nil
}

func main() {

	fmt.Println("In: ", term.IsTerminal(int(os.Stdin.Fd())))
	fmt.Println("Out: ", term.IsTerminal(int(os.Stdout.Fd())))

	in, err := GetCttyIn()
	if err != nil {
		panic(err)
	}
	scanner := bufio.NewScanner(in)

	success := scanner.Scan()
	if !success {
		panic(err)
	}
	fmt.Println("Res:", scanner.Text())
}

Running the above with echo "asd" | go run main.go
in vs code integrate terminal with bash.exe (MSYS2) **works **(suprisingly) but

running it in the git-bash.exe or msyswin64.exe (mintty.exe) does not work:

VS Code: (bash.exe)

In:  false
Out:  true
$CONIN Isterm:  true
asd
Res: asd

Correct!

Straight mintty.exe

In:  false      
Out:  false  // <<<< Thats wrong!
$CONIN Isterm:  true
                 //  <<<<--- STUCK at READ here!
@Biswa96
Copy link
Member

Biswa96 commented Jun 11, 2021

Technically speaking, there is something common between git-for-windows and msys2.

@jeremyd2019
Copy link
Member

jeremyd2019 commented Jun 11, 2021

winpty? conpty? Basically mintty uses "cygwin" ptys, not native Windows consoles, so trying to interact with the attached native Windows console from within it is usually doomed to failure. winpty is a program that tries to work around this, and conpty is a new thing that should help, but is still buggy so not enabled by default here (or in git bash).

@jeremyd2019
Copy link
Member

Personally, I don't use mintty because of this. I either run within the native console host, or now in Windows Terminal.

@gabyx gabyx changed the title msys.exe is a strange terminal mintty.exe is a strange terminal Jun 11, 2021
@Biswa96
Copy link
Member

Biswa96 commented Jun 13, 2021

@gabyx Can you provide equivalent code in C?

@julie777
Copy link

I suspect it is the same problem that I have which causes python to report that stdout is not a tty.
Add ConPTY=on to your minttyrc file.

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

4 participants