mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
* 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
69 lines
933 B
Go
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
|
|
}
|