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

Hi! I was tackling a similar problem and creack's pty might be a bit too abstracted for what you want. I just used the golang standard xterm terminal emulator https://pkg.go.dev/golang.org/x/term and a pipe. #1

Open
sskyblue1010 opened this issue Jan 25, 2025 · 0 comments
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request wontfix This will not be worked on

Comments

@sskyblue1010
Copy link
Owner

Hi! I was tackling a similar problem and creack's pty might be a bit too abstracted for what you want. I just used the golang standard xterm terminal emulator https://pkg.go.dev/golang.org/x/term and a pipe.

Here's a partial snippet as an example of what I mean. Your stdin stream is fed into the stdin_writer and your stdout is written to the writer, don't forget to Flush()!

stdin_reader, stdin_writer := io.Pipe()
reader := bufio.NewReader(stdin_reader)

stdout_writer := bytes.Buffer{}
writer := bufio.NewWriter(&stdout_writer)

rw := bufio.NewReadWriter(reader, writer)
t := term.NewTerminal(rw, prompt)

// constantly be reading lines
go func() {
	for {
		line, err := t.ReadLine()
		if err == io.EOF {
			log.Printf("got EOF")
		}
		if err != nil {
			log.Printf("got err")
		}
		if line == "" {
			continue
		}
		log.Printf("LINE: %s", line)
	}
}()

Originally posted by @lgmugnier in creack/pty#153 (comment)

@sskyblue1010 sskyblue1010 added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request wontfix This will not be worked on labels Jan 25, 2025
@sskyblue1010 sskyblue1010 self-assigned this Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant