Description
I'm trying to build a little terminal application with golang.org/x/term. Until now I only had one terminal which was started when I ran ssh user@localhost
. But if SSH is given a command while starting the connection, the terminals no longer work (terminal.ReadLine()
and .ReadPassword("...")
never return and don't react to newlines).
This is a minimal example to reproduce this:
package main
import (
"io"
"github.com/gliderlabs/ssh"
"golang.org/x/term"
)
func main() {
handler := func(s ssh.Session) {
term := term.NewTerminal(s, "Enter your name: ")
line, err := term.ReadLine()
if err != nil {
panic(err)
}
io.WriteString(s, "Your name is: "+line+"\n")
}
server := ssh.Server{
Addr: ":2222",
Handler: handler,
}
server.SetOption(ssh.HostKeyFile("./id_ed25519"))
panic(server.ListenAndServe())
}
When I run ssh user@localhost -p 2222
, it works:
But when a append any command to SSH nothing happens at ReadLine()
, no matter how often I press Enter: However, my input is somehow "reflected" into the SSH window, which is not the case without the command (maybe this is the reason, why ReadLine()
never returns?):
This is my go.mod
if required:
module my-turn
go 1.20
require (
github.com/gliderlabs/ssh v0.3.7
golang.org/x/term v0.23.0
)
require (
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/sys v0.24.0 // indirect
)
I tried debugging this for some time now, but I don't get why this is not working. Any ideas how to fix this? Or is this a bug?