Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 42987b3

Browse files
committed
finish from tty_size of iostreams in ios package
1 parent fd6cc0c commit 42987b3

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
99
github.com/rivo/tview v0.0.0-20211202162923-2a6de950f73b
1010
github.com/sirupsen/logrus v1.8.1
11+
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d
1112
)
1213

1314
require (
@@ -33,7 +34,6 @@ require (
3334
github.com/rivo/uniseg v0.2.0 // indirect
3435
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
3536
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
36-
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
3737
golang.org/x/text v0.3.6 // indirect
3838
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
3939
google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a // indirect

ios/tty_size.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
package ios
5+
6+
import (
7+
"os"
8+
9+
"golang.org/x/term"
10+
)
11+
12+
// ttySize measures the size of the controlling terminal for the current process
13+
func ttySize() (int, int, error) {
14+
f, err := os.Open("/dev/tty")
15+
16+
if err != nil {
17+
return -1, -1, err
18+
}
19+
20+
defer f.Close()
21+
22+
return term.GetSize(int(f.Fd()))
23+
}

ios/tty_size_windows.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package ios
2+
3+
import (
4+
"os"
5+
6+
"golang.org/x/term"
7+
)
8+
9+
func ttySize() (int, int, error) {
10+
f, err := os.Open("CONOUT$")
11+
12+
if err != nil {
13+
return -1, -1, err
14+
}
15+
16+
defer f.Close()
17+
18+
return term.GetSize(int(f.Fd()))
19+
}

0 commit comments

Comments
 (0)