From fb3659df9fc4ea80537ebf3a78ca9c943930df7b Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 4 Dec 2023 07:48:27 -0800 Subject: [PATCH] refactoring: use common LockRegion implementation --- console_win.go | 15 --------------- screen.go | 17 ++++++++++++++++- simulation.go | 15 --------------- tscreen.go | 15 --------------- wscreen.go | 15 --------------- 5 files changed, 16 insertions(+), 61 deletions(-) diff --git a/console_win.go b/console_win.go index 3c47f90b..a7c263c9 100644 --- a/console_win.go +++ b/console_win.go @@ -1291,21 +1291,6 @@ func (s *cScreen) Resume() error { return s.engage() } -func (s *cScreen) LockRegion(x, y, width, height int, lock bool) { - s.Lock() - defer s.Unlock() - for j := y; j < (y + height); j += 1 { - for i := x; i < (x + width); i += 1 { - switch lock { - case true: - s.cells.LockCell(i, j) - case false: - s.cells.UnlockCell(i, j) - } - } - } -} - func (s *cScreen) Tty() (Tty, bool) { return nil, false } diff --git a/screen.go b/screen.go index a8fc0965..c87f284c 100644 --- a/screen.go +++ b/screen.go @@ -339,7 +339,6 @@ type screenImpl interface { Resume() error Beep() error SetSize(int, int) - LockRegion(x, y, width, height int, lock bool) Tty() (Tty, bool) // Following methods are not part of the Screen api, but are used for interaction with @@ -402,3 +401,19 @@ func (b *baseScreen) GetContent(x, y int) (rune, []rune, Style, int) { b.Unlock() return primary, combining, style, width } + +func (b *baseScreen) LockRegion(x, y, width, height int, lock bool) { + cells := b.GetCells() + b.Lock() + for j := y; j < (y + height); j += 1 { + for i := x; i < (x + width); i += 1 { + switch lock { + case true: + cells.LockCell(i, j) + case false: + cells.UnlockCell(i, j) + } + } + } + b.Unlock() +} diff --git a/simulation.go b/simulation.go index 59ed7c12..61814cf0 100644 --- a/simulation.go +++ b/simulation.go @@ -516,21 +516,6 @@ func (s *simscreen) Resume() error { return nil } -func (s *simscreen) LockRegion(x, y, width, height int, lock bool) { - s.Lock() - defer s.Unlock() - for j := y; j < (y + height); j += 1 { - for i := x; i < (x + width); i += 1 { - switch lock { - case true: - s.back.LockCell(i, j) - case false: - s.back.UnlockCell(i, j) - } - } - } -} - func (s *simscreen) Tty() (Tty, bool) { return nil, false } diff --git a/tscreen.go b/tscreen.go index 35ca147b..5774eee4 100644 --- a/tscreen.go +++ b/tscreen.go @@ -1820,21 +1820,6 @@ func (t *tScreen) Resume() error { return t.engage() } -func (t *tScreen) LockRegion(x, y, width, height int, lock bool) { - t.Lock() - defer t.Unlock() - for j := y; j < (y + height); j += 1 { - for i := x; i < (x + width); i += 1 { - switch lock { - case true: - t.cells.LockCell(i, j) - case false: - t.cells.UnlockCell(i, j) - } - } - } -} - func (t *tScreen) Tty() (Tty, bool) { return t.tty, true } diff --git a/wscreen.go b/wscreen.go index 8c31b42c..12339b5c 100644 --- a/wscreen.go +++ b/wscreen.go @@ -531,21 +531,6 @@ func (t *wScreen) Beep() error { return nil } -func (t *wScreen) LockRegion(x, y, width, height int, lock bool) { - t.Lock() - defer t.Unlock() - for j := y; j < (y + height); j += 1 { - for i := x; i < (x + width); i += 1 { - switch lock { - case true: - t.cells.LockCell(i, j) - case false: - t.cells.UnlockCell(i, j) - } - } - } -} - func (t *wScreen) Tty() (Tty, bool) { return nil, false }