Files
coder/pty/pty_other.go
T
Kyle Carberry 587cbac498 fix: Swap height and width for TTY size (#1161)
This was causing the TTY to be real wonky on Windows.
It didn't seem to have an effect on Linux, but I suspect
that's because of escape codes.
2022-04-25 15:30:02 -05:00

69 lines
933 B
Go

//go:build !windows
// +build !windows
package pty
import (
"io"
"os"
"sync"
"github.com/creack/pty"
)
func newPty() (PTY, error) {
ptyFile, ttyFile, err := pty.Open()
if err != nil {
return nil, err
}
return &otherPty{
pty: ptyFile,
tty: ttyFile,
}, nil
}
type otherPty struct {
mutex sync.Mutex
pty, tty *os.File
}
func (p *otherPty) Input() io.ReadWriter {
return readWriter{
Reader: p.tty,
Writer: p.pty,
}
}
func (p *otherPty) Output() io.ReadWriter {
return readWriter{
Reader: p.pty,
Writer: p.tty,
}
}
func (p *otherPty) Resize(height uint16, width uint16) error {
p.mutex.Lock()
defer p.mutex.Unlock()
return pty.Setsize(p.pty, &pty.Winsize{
Rows: width,
Cols: height,
})
}
func (p *otherPty) Close() error {
p.mutex.Lock()
defer p.mutex.Unlock()
err := p.pty.Close()
if err != nil {
return err
}
err = p.tty.Close()
if err != nil {
return err
}
return nil
}