forked from pterm/pterm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
terminal_test.go
54 lines (48 loc) · 1.42 KB
/
terminal_test.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
package pterm_test
import (
"os"
"testing"
"github.com/MarvinJWendt/testza"
"github.com/forvitinn/pterm"
"golang.org/x/term"
)
func TestSetForcedTerminalSize(t *testing.T) {
pterm.SetForcedTerminalSize(1, 1)
w, h, _ := pterm.GetTerminalSize()
testza.AssertEqual(t, w, 1)
testza.AssertEqual(t, h, 1)
w = pterm.GetTerminalWidth()
h = pterm.GetTerminalHeight()
testza.AssertEqual(t, w, 1)
testza.AssertEqual(t, h, 1)
}
func autodetectTerminalSize() (int, int) {
expectedW, expectedH, _ := term.GetSize(int(os.Stdout.Fd()))
// CI goes to fallback values
if expectedW <= 0 {
expectedW = pterm.FallbackTerminalWidth
expectedH = pterm.FallbackTerminalHeight
}
return expectedW, expectedH
}
func TestGetTerminalSizeAutodetect(t *testing.T) {
// enable autodetection
pterm.SetForcedTerminalSize(0, 0)
expectedW, expectedH := autodetectTerminalSize()
w, h, _ := pterm.GetTerminalSize()
testza.AssertEqual(t, expectedW, w)
testza.AssertEqual(t, expectedH, h)
// disable autodetection
pterm.SetForcedTerminalSize(terminalWidth, terminalHeight)
}
func TestGetTerminalSizeAutodetect2(t *testing.T) {
// enable autodetection
pterm.SetForcedTerminalSize(0, 0)
expectedW, expectedH := autodetectTerminalSize()
w := pterm.GetTerminalWidth()
h := pterm.GetTerminalHeight()
testza.AssertEqual(t, expectedW, w)
testza.AssertEqual(t, expectedH, h)
// disable autodetection
pterm.SetForcedTerminalSize(terminalWidth, terminalHeight)
}