/
out.go
78 lines (59 loc) · 1.5 KB
/
out.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//go:build !js
// +build !js
package term
import (
"os"
"github.com/lmorg/murex/lang/stdio"
"github.com/lmorg/murex/utils"
)
// Terminal: Standard Out
// Out is the Stdout interface for term
type Out struct {
term
}
func (t *Out) File() *os.File {
return os.Stdout
}
func OutSetDataTypeIPC() {
/*murexPid, exists := os.LookupEnv(consts.EnvMurexPid)
if !exists {
return
}
if strconv.Itoa(os.Getppid()) != murexPid {
return
}
outSetDataTypeFd3 = true*/
}
//var OutSetDataTypeIPC bool
// SetDataType writes the data type to a special pipe when run under murex
func (t *Out) SetDataType(dt string) {
/*if !OutSetDataTypeIPC || len(dt) == 0 || dt == types.Null {
return
}
f := os.NewFile(3, "dt")
_, err := f.WriteString(dt + "\n")
if err != nil && debug.Enabled {
tty.Stderr.WriteString("Error writing data type: " + err.Error() + "\n")
}
OutSetDataTypeIPC = false
f.Close()*/
}
// Write is the io.Writer() interface for term
func (t *Out) Write(b []byte) (i int, err error) {
t.mutex.Lock()
t.bWritten += uint64(len(b))
t.mutex.Unlock()
i, err = os.Stdout.Write(b)
if err != nil {
os.Stderr.WriteString(err.Error())
}
return
}
// Writeln writes an OS-specific terminated line to the stdout
func (t *Out) Writeln(b []byte) (int, error) {
return t.Write(appendBytes(b, utils.NewLineByte...))
}
// WriteArray performs data type specific buffered writes to an stdio.Io interface
func (t *Out) WriteArray(dataType string) (stdio.ArrayWriter, error) {
return stdio.WriteArray(t, dataType)
}