diff --git a/event_test.go b/event_test.go index 7908d261..c9f2415a 100644 --- a/event_test.go +++ b/event_test.go @@ -19,7 +19,7 @@ import ( "time" ) -func eventLoop(s SimulationScreen, evch chan Event) { +func eventLoop(s Screen, evch chan Event) { for { ev := s.PollEvent() if ev == nil { @@ -35,11 +35,11 @@ func eventLoop(s SimulationScreen, evch chan Event) { func TestMouseEvents(t *testing.T) { - s := mkTestScreen(t, "") + s, ss := mkTestScreen(t, "") defer s.Fini() s.EnableMouse() - s.InjectMouse(4, 9, Button1, ModCtrl) + ss.InjectMouse(4, 9, Button1, ModCtrl) evch := make(chan Event) em := &EventMouse{} done := false @@ -71,11 +71,11 @@ func TestMouseEvents(t *testing.T) { func TestChannelMouseEvents(t *testing.T) { - s := mkTestScreen(t, "") + s, ss := mkTestScreen(t, "") defer s.Fini() s.EnableMouse() - s.InjectMouse(4, 9, Button1, ModCtrl) + ss.InjectMouse(4, 9, Button1, ModCtrl) evch := make(chan Event) quit := make(chan struct{}) em := new(EventMouse) diff --git a/runes_test.go b/runes_test.go index 88bca5df..36fc78f9 100644 --- a/runes_test.go +++ b/runes_test.go @@ -19,7 +19,7 @@ import ( ) func TestCanDisplayUTF8(t *testing.T) { - s := mkTestScreen(t, "UTF-8") + s, _ := mkTestScreen(t, "UTF-8") defer s.Fini() if s.CharacterSet() != "UTF-8" { @@ -39,7 +39,7 @@ func TestCanDisplayUTF8(t *testing.T) { } } func TestCanDisplayASCII(t *testing.T) { - s := mkTestScreen(t, "US-ASCII") + s, _ := mkTestScreen(t, "US-ASCII") defer s.Fini() if s.CharacterSet() != "US-ASCII" { @@ -60,7 +60,7 @@ func TestCanDisplayASCII(t *testing.T) { } func TestRuneFallbacks(t *testing.T) { - s := mkTestScreen(t, "US-ASCII") + s, _ := mkTestScreen(t, "US-ASCII") defer s.Fini() if s.CharacterSet() != "US-ASCII" { t.Errorf("Wrong character set: %v", s.CharacterSet()) diff --git a/sim_test.go b/sim_test.go index 8cd73708..cf992bbe 100644 --- a/sim_test.go +++ b/sim_test.go @@ -1,4 +1,4 @@ -// Copyright 2018 The TCell Authors +// Copyright 2023 The TCell Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use file except in compliance with the License. @@ -18,20 +18,20 @@ import ( "testing" ) -func mkTestScreen(t *testing.T, charset string) SimulationScreen { - s := NewSimulationScreen(charset) - if s == nil { +func mkTestScreen(t *testing.T, charset string) (Screen, SimulationScreen) { + s, ss := NewSimulationScreen(charset) + if s == nil || ss == nil { t.Fatalf("Failed to get simulation screen") } if e := s.Init(); e != nil { t.Fatalf("Failed to initialize screen: %v", e) } - return s + return s, ss } func TestInitScreen(t *testing.T) { - s := mkTestScreen(t, "") + s, ss := mkTestScreen(t, "") defer s.Fini() if x, y := s.Size(); x != 80 || y != 25 { @@ -40,16 +40,16 @@ func TestInitScreen(t *testing.T) { if s.CharacterSet() != "UTF-8" { t.Fatalf("Character Set (%v) not UTF-8", s.CharacterSet()) } - if b, x, y := s.GetContents(); len(b) != x*y || x != 80 || y != 25 { + if b, x, y := ss.GetContents(); len(b) != x*y || x != 80 || y != 25 { t.Fatalf("Contents (%v, %v, %v) wrong", len(b), x, y) } } func TestClearScreen(t *testing.T) { - s := mkTestScreen(t, "") + s, ss := mkTestScreen(t, "") defer s.Fini() s.Clear() - b, x, y := s.GetContents() + b, x, y := ss.GetContents() if len(b) != x*y || x != 80 || y != 25 { t.Fatalf("Contents (%v, %v, %v) wrong", len(b), x, y) } @@ -65,10 +65,10 @@ func TestClearScreen(t *testing.T) { func TestSetCell(t *testing.T) { st := StyleDefault.Background(ColorRed).Blink(true) - s := mkTestScreen(t, "") + s, ss := mkTestScreen(t, "") defer s.Fini() s.SetCell(2, 5, st, '@') - b, _, _ := s.GetContents() + b, _, _ := ss.GetContents() s.Show() if len(b) != 80*25 { t.Fatalf("Wrong content size") @@ -83,10 +83,10 @@ func TestSetCell(t *testing.T) { func TestResize(t *testing.T) { st := StyleDefault.Background(ColorYellow).Underline(true) - s := mkTestScreen(t, "") + s, ss := mkTestScreen(t, "") defer s.Fini() s.SetCell(2, 5, st, '&') - b, x, y := s.GetContents() + b, x, y := ss.GetContents() s.Show() cell := &b[5*80+2] @@ -97,7 +97,7 @@ func TestResize(t *testing.T) { } s.SetSize(30, 10) s.Show() - b2, x2, y2 := s.GetContents() + b2, x2, y2 := ss.GetContents() if len(b2) == len(b) || x2 == x || y2 == y { t.Errorf("Screen parameters should not match") } @@ -111,17 +111,17 @@ func TestResize(t *testing.T) { } func TestBeep(t *testing.T) { - s := mkTestScreen(t, "") + s, ss := mkTestScreen(t, "") defer s.Fini() - b0, x0, y0 := s.GetContents() + b0, x0, y0 := ss.GetContents() if err := s.Beep(); err != nil { t.Errorf("could not beep: %v", err) } s.Show() - b1, x1, y1 := s.GetContents() + b1, x1, y1 := ss.GetContents() if x0 != x1 { t.Fatalf("screen width changed unexpectedly from %d to %d", x0, x1) } diff --git a/simulation.go b/simulation.go index 9620b6ac..ba7f441c 100644 --- a/simulation.go +++ b/simulation.go @@ -23,12 +23,13 @@ import ( // NewSimulationScreen returns a SimulationScreen. Note that // SimulationScreen is also a Screen. -func NewSimulationScreen(charset string) SimulationScreen { +func NewSimulationScreen(charset string) (Screen, SimulationScreen) { if charset == "" { charset = "UTF-8" } - s := &simscreen{charset: charset} - return s + ss := &simscreen{charset: charset} + s := &baseScreen{screenImpl: ss} + return s, ss } // SimulationScreen represents a screen simulation. This is intended to @@ -57,8 +58,6 @@ type SimulationScreen interface { // GetCursor returns the cursor details. GetCursor() (x int, y int, visible bool) - - Screen } // SimCell represents a simulated screen cell. The purpose of this @@ -150,25 +149,12 @@ func (s *simscreen) SetStyle(style Style) { s.Unlock() } -func (s *simscreen) Clear() { - s.Fill(' ', s.style) -} - func (s *simscreen) Fill(r rune, style Style) { s.Lock() s.back.Fill(r, style) s.Unlock() } -func (s *simscreen) SetCell(x, y int, style Style, ch ...rune) { - - if len(ch) > 0 { - s.SetContent(x, y, ch[0], ch[1:], style) - } else { - s.SetContent(x, y, ' ', nil, style) - } -} - func (s *simscreen) SetContent(x, y int, mainc rune, combc []rune, st Style) { s.Lock() diff --git a/style_test.go b/style_test.go index 861c65fc..9d23b4c5 100644 --- a/style_test.go +++ b/style_test.go @@ -19,7 +19,7 @@ import ( ) func TestStyle(t *testing.T) { - s := mkTestScreen(t, "") + s, _ := mkTestScreen(t, "") defer s.Fini() style := StyleDefault