GithubHelp home page GithubHelp logo

aymanbagabas / go-pty Goto Github PK

View Code? Open in Web Editor NEW
21.0 3.0 0.0 136 KB

Cross platform Go Pty interface

License: MIT License

Go 100.00%
go golang pseudoterminal pty ssh tty terminal cross-platform

go-pty's People

Contributors

aymanbagabas avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

go-pty's Issues

Issue with Shell Example

Hey, so I came across this and it looks like a really cool library (thanks for making it!), and I was hoping to use it in a project I'm working on.

Basically, what I'm trying to implement is very similar to your shell example, except that the example isn't behaving the way I expected it to. Essentially, I'm looking to use this package from a background service on my system, and have that background service spawn a pty that a user can connect to and use normally by running screen /dev/ttys002 or similar.

When I run the shell example though, it seems to effectively run it in my current TTY, which is obviously not too helpful in my case. It seems this might be intended given the code, particularly with regard to the io.Copy routines reading/writing os.Stdout/os.Stdin, as well as the fact ptmx.Name() isn't outputted at all.

// Set stdin in raw mode.
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
if err != nil {
panic(err)
}
defer func() { _ = term.Restore(int(os.Stdin.Fd()), oldState) }() // Best effort.
// Copy stdin to the pty and the pty to stdout.
// NOTE: The goroutine will keep reading until the next keystroke before returning.
go io.Copy(ptmx, os.Stdin)
go io.Copy(os.Stdout, ptmx)

I tried to play with the arguments to the IO functions and replace os.Std* with a handle to ptmx.Name(), and that got the shell to seem to not use the current TTY, but I still can't seem to do anything at all inside the screen connected to ptmx.Name(). No data echos no matter what I type (stty shows echo enabled though), and typing exit doesn't seem to reach bash because it doesn't exit.

I feel like I can't be far off at all from getting this to work, but I can't figure out what I'm missing. I'm also confused as to how the shell example was supposed to work in the first place. If you could point me in the right direction I'd really appreciate it.

Thanks so much

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.