-
Notifications
You must be signed in to change notification settings - Fork 8.5k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
How to disable ENABLE_LINE_INPUT in ConPTY? How to call GetConsoleMode for a PseudoConsole? #13201
Comments
If disable But I can't change the child process to disable Is there a way to disable
package main
import (
"bufio"
"fmt"
"os"
"golang.org/x/sys/windows"
)
func main() {
var st uint32
if err := windows.GetConsoleMode(windows.Handle(os.Stdin.Fd()), &st); err != nil {
fmt.Println(err)
return
}
// disable ENABLE_LINE_INPUT
raw := st &^ (windows.ENABLE_ECHO_INPUT | windows.ENABLE_LINE_INPUT)
fmt.Printf("st: %#x, raw: %#x\n", st, raw)
if err := windows.SetConsoleMode(windows.Handle(os.Stdin.Fd()), raw); err != nil {
fmt.Println(err)
return
}
// reset console mode
defer func() {
if err := windows.SetConsoleMode(windows.Handle(os.Stdin.Fd()), st); err != nil {
fmt.Println(err)
return
}
}()
// read line
line, err := bufio.NewReader(os.Stdin).ReadBytes('\r')
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("\nLength: %d\r\n", len(line))
}
package main
import (
"bufio"
"context"
"fmt"
"strings"
"time"
"github.com/UserExistsError/conpty"
)
func main() {
cpty, err := conpty.Start("readline.exe") // The child process have to disable ENABLE_LINE_INPUT first
if err != nil {
fmt.Printf("Failed to spawn a pty: %v", err)
return
}
defer cpty.Close()
go func() {
time.Sleep(1 * time.Second) // Wait the child process disable ENABLE_LINE_INPUT first
cpty.Write([]byte(strings.Repeat("A", 5000) + "\r\n"))
scanner := bufio.NewScanner(cpty)
for scanner.Scan() {
fmt.Println(scanner.Text())
}
if err := scanner.Err(); err != nil {
fmt.Println(err)
}
}()
if _, err := cpty.Wait(context.Background()); err != nil {
fmt.Printf("Error: %v", err)
}
} |
Huh. I think you might be stuck here then. I don't think we provide any sort of way to call the console APIs on a conpty you create. There might be some trickery possible. You might be able to attach some other helper |
Thanks for your help. I tried it before, it works. I disabled the Btw, the |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Windows Terminal version
1.12.10982.0
Windows build number
10.0.19043.0
Other Software
https://github.com/UserExistsError/conpty v0.1.0
Is it similar to https://stackoverflow.com/a/11439517/7696611 ?
Steps to reproduce
go run conptytest.go
Expected Behavior
Output: 3001
Actual Behavior
Output: 511
The text was updated successfully, but these errors were encountered: