Skip to content

Commit 707e7a0

Browse files
committed
feat: add utility to get write only TTY file
1 parent 6bad82f commit 707e7a0

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/util/noop.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package util
2+
3+
func noop() {}
4+
5+
func noopNilError() error {
6+
return nil
7+
}

src/util/tty_unix.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
package util
5+
6+
import "os"
7+
8+
func GetTTYFile() (file *os.File, teardown func() error) {
9+
tty, err := os.OpenFile("/dev/tty", os.O_WRONLY, 0220)
10+
if err == nil {
11+
return tty, tty.Close
12+
}
13+
14+
return os.Stdout, noopNilError
15+
}

src/util/tty_windows.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//go:build windows
2+
// +build windows
3+
4+
package util
5+
6+
import "os"
7+
8+
func GetTTYFile() (*os.File, func() error) {
9+
return os.Stdout, noopNilError
10+
}

0 commit comments

Comments
 (0)