forked from charmbracelet/bubbletea
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen_test.go
More file actions
109 lines (101 loc) Β· 2.38 KB
/
screen_test.go
File metadata and controls
109 lines (101 loc) Β· 2.38 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package tea
import (
"bytes"
"image/color"
"runtime"
"testing"
"github.com/charmbracelet/colorprofile"
"github.com/charmbracelet/x/exp/golden"
)
func TestClearMsg(t *testing.T) {
type test struct {
name string
cmds sequenceMsg
}
tests := []test{
{
name: "clear_screen",
cmds: []Cmd{ClearScreen},
},
{
name: "altscreen",
cmds: []Cmd{EnterAltScreen, ExitAltScreen},
},
{
name: "altscreen_autoexit",
cmds: []Cmd{EnterAltScreen},
},
{
name: "mouse_cellmotion",
cmds: []Cmd{EnableMouseCellMotion},
},
{
name: "mouse_allmotion",
cmds: []Cmd{EnableMouseAllMotion},
},
{
name: "mouse_disable",
cmds: []Cmd{EnableMouseAllMotion, DisableMouse},
},
{
name: "cursor_hide",
cmds: []Cmd{HideCursor},
},
{
name: "cursor_hideshow",
cmds: []Cmd{HideCursor, ShowCursor},
},
{
name: "bp_stop_start",
cmds: []Cmd{DisableBracketedPaste, EnableBracketedPaste},
},
{
name: "read_set_clipboard",
cmds: []Cmd{ReadClipboard, SetClipboard("success")},
},
{
name: "bg_fg_cur_color",
cmds: []Cmd{RequestForegroundColor, RequestBackgroundColor, RequestCursorColor},
},
{
name: "bg_set_color",
cmds: []Cmd{SetBackgroundColor(color.RGBA{255, 255, 255, 255})},
},
{
name: "grapheme_clustering",
cmds: []Cmd{EnableGraphemeClustering},
},
}
if runtime.GOOS == "windows" {
// Windows supports enhanced keyboard features through the Windows API, not through ANSI sequences.
tests = append(tests, test{
name: "kitty_start_windows",
cmds: []Cmd{DisableKeyboardEnhancements, RequestKeyboardEnhancements(WithKeyReleases)},
})
} else {
tests = append(tests, test{
name: "kitty_start_other",
cmds: []Cmd{DisableKeyboardEnhancements, RequestKeyboardEnhancements(WithKeyReleases)},
})
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var buf bytes.Buffer
var in bytes.Buffer
m := &testModel{}
p := NewProgram(m, WithInput(&in), WithOutput(&buf),
WithEnvironment([]string{
"TERM=xterm-256color", // always use xterm and 256 colors for tests
}),
// Use ANSI256 to increase test coverage.
WithColorProfile(colorprofile.ANSI256),
// Set the initial window size for the program.
WithWindowSize(80, 24))
go p.Send(append(test.cmds, Quit))
if _, err := p.Run(); err != nil {
t.Fatal(err)
}
golden.RequireEqual(t, buf.Bytes())
})
}
}