-
Notifications
You must be signed in to change notification settings - Fork 38
/
term_windows.go
56 lines (49 loc) · 1.02 KB
/
term_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package terminal
import (
"io"
"log"
"os"
"os/exec"
"syscall"
"github.com/ActiveState/termtest/conpty"
)
func (t *Terminal) updatePTYSize() {
if t.pty == nil { // during load
return
}
_ = t.pty.(*conpty.ConPty).Resize(uint16(t.config.Columns), uint16(t.config.Rows))
}
func (t *Terminal) startPTY() (io.WriteCloser, io.Reader, io.Closer, error) {
cpty, err := conpty.New(80, 25)
if err != nil {
return nil, nil, nil, err
}
pid, _, err := cpty.Spawn(
"C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
[]string{},
&syscall.ProcAttr{
Env: os.Environ(),
Dir: t.startingDir(),
},
)
if err != nil {
return nil, nil, nil, err
}
t.cmd = &exec.Cmd{}
process, err := os.FindProcess(pid)
if err != nil {
return nil, nil, nil, err
}
go func() {
ps, err := process.Wait()
if err != nil {
log.Fatalf("Error waiting for process: %v", err)
}
t.cmd.ProcessState = ps
if t.pty != nil {
t.pty = nil
_ = cpty.Close()
}
}()
return cpty.InPipe(), cpty.OutPipe(), cpty, nil
}