| 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 |
func verifyCursor(t *testing.T, term vt.MockTerm, expected vt.CursorStyle) { |
| 27 |
t.Helper() |
| 28 |
if actual := term.Backend().GetCursor(); actual != expected { |
| 29 |
t.Errorf("wrong cursor style %x != %x", actual, expected) |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
func TestDemo(t *testing.T) { |
| 35 |
|
| 36 |
mt := vt.NewMockTerm() |
| 37 |
scr, err := tcell.NewTerminfoScreenFromTty(mt, tcell.OptColors(8), tcell.OptTerm("ansi")) |
| 38 |
if err != nil { |
| 39 |
t.Fatalf("failed to create screen: %v", err) |
| 40 |
} |
| 41 |
tcell.ShimScreen(scr) |
| 42 |
var wg sync.WaitGroup |
| 43 |
wg.Add(1) |
| 44 |
|
| 45 |
go func() { |
| 46 |
defer wg.Done() |
| 47 |
main() |
| 48 |
}() |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
time.Sleep(time.Millisecond * 50) |
| 53 |
|
| 54 |
mt.KeyTap(vt.Key1) |
| 55 |
time.Sleep(time.Millisecond * 20) |
| 56 |
verifyCursor(t, mt, vt.BlinkingBlock) |
| 57 |
|
| 58 |
mt.KeyTap(vt.Key2) |
| 59 |
time.Sleep(time.Millisecond * 20) |
| 60 |
verifyCursor(t, mt, vt.SteadyBlock) |
| 61 |
|
| 62 |
mt.KeyTap(vt.Key3) |
| 63 |
time.Sleep(time.Millisecond * 20) |
| 64 |
verifyCursor(t, mt, vt.BlinkingUnderline) |
| 65 |
|
| 66 |
mt.KeyTap(vt.Key4) |
| 67 |
time.Sleep(time.Millisecond * 20) |
| 68 |
verifyCursor(t, mt, vt.SteadyUnderline) |
| 69 |
|
| 70 |
mt.KeyTap(vt.Key5) |
| 71 |
time.Sleep(time.Millisecond * 20) |
| 72 |
verifyCursor(t, mt, vt.BlinkingBar) |
| 73 |
|
| 74 |
mt.KeyTap(vt.Key6) |
| 75 |
time.Sleep(time.Millisecond * 20) |
| 76 |
verifyCursor(t, mt, vt.SteadyBar) |
| 77 |
|
| 78 |
mt.KeyTap(vt.Key0) |
| 79 |
time.Sleep(time.Millisecond * 20) |
| 80 |
verifyCursor(t, mt, vt.BlinkingBlock) |
| 81 |
|
| 82 |
mt.KeyTap(vt.KeyRCtrl, vt.KeyL) |
| 83 |
mt.Drain() |
| 84 |
mt.KeyTap(vt.KeyRCtrl, vt.KeyQ) |
| 85 |
mt.Backend().GetSize() |
| 86 |
wg.Wait() |
| 87 |
} |