feat: add supervisor prototype with embedded frontend

This commit is contained in:
root
2026-03-09 19:15:53 +01:00
parent 96c4ce1697
commit 84de557052
56 changed files with 4044 additions and 10 deletions

View File

@ -0,0 +1,53 @@
package session
import (
"os"
"os/exec"
"syscall"
"github.com/creack/pty"
)
type DefaultPTYFactory struct{}
type shellProcess struct {
cmd *exec.Cmd
pty *os.File
}
func (f DefaultPTYFactory) Start(command string) (PTYProcess, error) {
cmd := exec.Command("bash", "-lc", command)
cmd.Env = os.Environ()
ptmx, err := pty.Start(cmd)
if err != nil {
return nil, err
}
return &shellProcess{cmd: cmd, pty: ptmx}, nil
}
func (p *shellProcess) Read(b []byte) (int, error) {
return p.pty.Read(b)
}
func (p *shellProcess) Write(b []byte) (int, error) {
return p.pty.Write(b)
}
func (p *shellProcess) Close() error {
return p.pty.Close()
}
func (p *shellProcess) Wait() error {
return p.cmd.Wait()
}
func (p *shellProcess) Resize(cols, rows uint16) error {
return pty.Setsize(p.pty, &pty.Winsize{Cols: cols, Rows: rows})
}
func (p *shellProcess) SignalStop() error {
if p.cmd.Process == nil {
return nil
}
return p.cmd.Process.Signal(syscall.SIGTERM)
}