Skip to content

Commit

Permalink
doc: add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Sep 22, 2023
1 parent ddb8a05 commit 9b0c9ea
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Go Pty

<p>
<a href="https://github.com/aymanbagabas/go-pty/releases"><img src="https://img.shields.io/github/release/aymanbagabas/go-pty.svg" alt="Latest Release"></a>
<a href="https://pkg.go.dev/github.com/aymanbagabas/go-pty?tab=doc"><img src="https://godoc.org/github.com/golang/gddo?status.svg" alt="GoDoc"></a>
<a href="https://github.com/aymanbagabas/go-pty/actions"><img src="https://github.com/aymanbagabas/go-pty/workflows/build/badge.svg" alt="Build Status"></a>
</p>

Go-Pty is a package for using pseudo-terminal interfaces in Go. It supports Unix PTYs and Windows through [ConPty](https://learn.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session).

## Usage

```sh
go get github.com/aymanbagabas/go-pty
```

Example running `grep`

```go
package main

import (
"io"
"log"
"os"

"github.com/aymanbagabas/go-pty"
)

func main() {
pty, err := pty.New()
if err != nil {
log.Fatalf("failed to open pty: %s", err)
}

defer pty.Close()
c := pty.Command("grep", "--color=auto", "bar")
if err := c.Start(); err != nil {
log.Fatalf("failed to start: %s", err)
}

go func() {
pty.Write([]byte("foo\n"))
pty.Write([]byte("bar\n"))
pty.Write([]byte("baz\n"))
pty.Write([]byte{4}) // EOT
}()
go io.Copy(os.Stdout, pty)

if err := c.Wait(); err != nil {
panic(err)
}
}
```

Refer to [./examples](./examples) for more examples.

## Credits

- [creack/pty](https://github.com/creack/pty/): support for Unix PTYs
- [microsoft/hcsshim](https://github.com/microsoft/hcsshim): Windows ConPty implementation

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) for details.

0 comments on commit 9b0c9ea

Please sign in to comment.