| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package main |
| 16 |
|
| 17 |
import ( |
| 18 |
"sync" |
| 19 |
"testing" |
| 20 |
"time" |
| 21 |
|
| 22 |
"github.com/gdamore/tcell/v3" |
| 23 |
"github.com/gdamore/tcell/v3/vt" |
| 24 |
) |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
func TestStyles(t *testing.T) { |
| 30 |
|
| 31 |
mt := vt.NewMockTerm() |
| 32 |
scr, err := tcell.NewTerminfoScreenFromTty(mt) |
| 33 |
if err != nil { |
| 34 |
t.Fatalf("failed to create screen: %v", err) |
| 35 |
} |
| 36 |
tcell.ShimScreen(scr) |
| 37 |
var wg sync.WaitGroup |
| 38 |
wg.Add(1) |
| 39 |
|
| 40 |
go func() { |
| 41 |
defer wg.Done() |
| 42 |
main() |
| 43 |
}() |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
time.Sleep(time.Millisecond * 50) |
| 48 |
|
| 49 |
mt.Drain() |
| 50 |
|
| 51 |
|
| 52 |
mt.KeyTap(vt.KeyRCtrl, vt.KeyL) |
| 53 |
|
| 54 |
attrs := 0 |
| 55 |
var lastAttr vt.Attr |
| 56 |
for y := range vt.Row(24) { |
| 57 |
for x := range vt.Col(80) { |
| 58 |
if attr := mt.GetCell(vt.Coord{X: vt.Col(x), Y: vt.Row(y)}).S.Attr(); attr != lastAttr { |
| 59 |
attrs++ |
| 60 |
lastAttr = attr |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
mt.KeyTap(vt.KeyRCtrl, vt.KeyQ) |
| 66 |
|
| 67 |
wg.Wait() |
| 68 |
if attrs < 8 { |
| 69 |
t.Errorf("Not enough attribute changes changes: %d", attrs) |
| 70 |
} |
| 71 |
} |