Files
coder/pty/pty_other.go
Kyle Carberry 81577f120a feat: Add web terminal with reconnecting TTYs (#1186)
* feat: Add web terminal with reconnecting TTYs

This adds a web terminal that can reconnect to resume sessions!
No more disconnects, and no more bad bufferring!

* Add xstate service

* Add the webpage for accessing a web terminal

* Add terminal page tests

* Use Ticker instead of Timer

* Active Windows mode on Windows
2022-04-29 17:30:10 -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: height,
Cols: width,
})
}
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
}