File tree Expand file tree Collapse file tree 3 files changed +11
-13
lines changed Expand file tree Collapse file tree 3 files changed +11
-13
lines changed Original file line number Diff line number Diff line change 1
1
module github.com/hellflame/argparse
2
2
3
3
go 1.16
4
+
5
+ require golang.org/x/term v0.1.0
Original file line number Diff line number Diff line change
1
+ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4 =
2
+ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 /go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg =
3
+ golang.org/x/term v0.1.0 h1:g6Z6vPFA9dYBAF7DWcH6sCcOntplXsDKcliusYijMlw =
4
+ golang.org/x/term v0.1.0 /go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8 =
Original file line number Diff line number Diff line change @@ -3,23 +3,15 @@ package argparse
3
3
import (
4
4
"fmt"
5
5
"os"
6
- "os/exec"
7
- "strconv"
8
6
"strings"
7
+
8
+ "golang.org/x/term"
9
9
)
10
10
11
11
func decideTerminalWidth () int {
12
- // decide terminal width
13
- cmd := exec .Command ("stty" , "size" )
14
- cmd .Stdin = os .Stdin // this is important
15
- result , e := cmd .Output ()
16
- if e != nil {
17
- result = []byte ("0 80" )
18
- }
19
- width := 80
20
- parse := strings .Split (strings .TrimRight (string (result ), "\n " ), " " )
21
- if w , e := strconv .Atoi (parse [1 ]); e == nil {
22
- width = w
12
+ width , _ , err := term .GetSize (int (os .Stdout .Fd ()))
13
+ if err != nil {
14
+ return 80
23
15
}
24
16
return width
25
17
}
You can’t perform that action at this time.
0 commit comments