1
0
mirror of https://github.com/gdamore/tcell.git synced 2025-04-24 13:48:51 +08:00

refactoring: use common LockRegion implementation

This commit is contained in:
Garrett D'Amore 2023-12-04 07:48:27 -08:00
parent 92c4f488a6
commit fb3659df9f
5 changed files with 16 additions and 61 deletions

View File

@ -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
}

View File

@ -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()
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}