-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
cannot read escape code response with ReadRune() on Windows with Mintty #22
Comments
You might want to ignore '\000' . // foo.go
package main
import (
"fmt"
"github.com/mattn/go-tty"
)
func main(){
fmt.Println("----")
fmt.Println("\033[0c")
fmt.Println("----")
fmt.Println("Hit 'q' to quit")
tty1,err := tty.Open()
if err != nil {
panic(err.Error())
}
defer tty1.Close()
for{
r,err := tty1.ReadRune()
if err != nil { panic(err.Error()) }
if r == 'q' { break }
if r == '\000' { continue }
if r < ' ' {
fmt.Printf("<%X>",r)
}else{
fmt.Printf("%c",r)
}
}
fmt.Println()
} On Windows 10 machine, I executed
It looks that there are some responses. |
The response |
Hi zetamatta, thanks for the answer. I never noticed the \000 chars but they are not the problem. I forgot to mention the important part (wasn't really aware of it): conhost.exe from the regular windows console and ConEmu DO catch the response but other terminals like mintty (Cygwin terminal) does not. This is visible in the posted image: ConEmu is in the upper left corner, mintty in the upper right and conhost at the bottom. |
perhaps somewhat related: mattn/go-isatty#8 mattn/go-isatty#13 go-tty should support Mintty too. |
Currently, when using `ReadRune` on windows OSes, the input comes prefixed with 'empty' characters (as described here: mattn/go-tty#22)
Update: this problem exists for the Cygwin terminal mintty
See the latest comment
I am trying to read the terminal response on escape code queries on Windows.
The code always queries successfully on Linux but sometimes messes the terminal up (I have to type
stty echo
then). On Windows however the terminal answer is not caught by the program and gets written as text.How do I read such a terminal response? What am I doing wrong here?
demo code
The text was updated successfully, but these errors were encountered: