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

Shell prints input line when run with NewWithConfig on different terminal #116

Open
scotws opened this issue May 26, 2019 · 2 comments
Open

Comments

@scotws
Copy link

scotws commented May 26, 2019

Apols if I'm making a mistake here and this is not a bug - I would like to be able to access ishell through another terminal instance on Linux with go 1.12.5. So first, I set up a listener (leaving out error handling and defer here to keep the code short):

 listener, err := net.Listen("tcp", host)
 conn, err := listener.Accept()

where host is "localhost:8000" for testing. Next, I've imported "github.com/abiosoft/readline" to be able to run the shell with the listener's connection parameters in the configuration for NewWithConfig:

termCfg := &readline.Config{
        Stdin:       io.ReadCloser(conn),
        Stdout:      io.Writer(conn),
        StdinWriter: io.Writer(conn),
        Stderr:      io.Writer(conn),
}

Then I start the shell in a second terminal window through the listener:

shell := ishell.NewWithConfig(termCfg)
shell.Run()

This works fine when I open another shell and connect with nc localhost 8000 - except for the fact that after I type in a command such as help, the input line is not only echoed character for character as expected, but then printed again, giving me stuff like

> help
> help

Commands:
  clear        clear the screen
  exit         exit the program
  help         display help

I'm wondering if StdinWriter is the problem here, but changing that doesn't seem to help. I can't find an example for NewWithConfig in the docs. Is this a bug or am I missing something obvious? Thanks!

@abiosoft
Copy link
Owner

I actually haven't tried this before. It's most likely a bug. I'll look into it.

@scotws
Copy link
Author

scotws commented May 27, 2019

@abiosoft Thank you! In case it helps, the long version of the code is https://github.com/scotws/angua-go/blob/ttyswitch/cli/cli.go (very alpha, though, I'm in the middle of rebuilding the basic code structure).

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

2 participants