/
process_unix.go
56 lines (47 loc) · 1.16 KB
/
process_unix.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
//go:build !windows && !plan9 && !js
// +build !windows,!plan9,!js
package lang
import (
"io"
"os"
"os/signal"
"syscall"
"github.com/creack/pty"
"github.com/lmorg/murex/builtins/pipes/psuedotty"
"github.com/lmorg/murex/builtins/pipes/streams"
"github.com/lmorg/murex/lang/stdio"
"github.com/lmorg/murex/lang/types"
"github.com/lmorg/murex/utils/readline"
)
func ttys(p *Process) {
if p.CCExists != nil && p.CCExists(p.Name.String()) {
p.Stderr, p.CCErr = streams.NewTee(p.Stderr)
p.CCErr.SetDataType(types.Generic)
if p.Stdout.IsTTY() {
width, height, err := readline.GetSize(int(p.Stdout.File().Fd()))
if err != nil {
width, height = 80, 25
}
var tee stdio.Io
p.Stdout, tee, p.CCOut, err = psuedotty.NewTeePTY(width, height)
if err != nil {
p.Stdout, p.CCOut = streams.NewTee(p.Stdout)
return
}
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGWINCH)
go func() {
for range ch {
_ = pty.InheritSize(os.Stdout, p.Stdout.File())
}
}()
go func() {
_, _ = io.Copy(os.Stdout, tee)
signal.Stop(ch)
close(ch)
}()
} else {
p.Stdout, p.CCOut = streams.NewTee(p.Stdout)
}
}
}