Skip to content

Commit

Permalink
refactoring: use common LockRegion implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed Dec 4, 2023
1 parent 92c4f48 commit fb3659d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 61 deletions.
15 changes: 0 additions & 15 deletions console_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
17 changes: 16 additions & 1 deletion screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
15 changes: 0 additions & 15 deletions simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 0 additions & 15 deletions tscreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 0 additions & 15 deletions wscreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit fb3659d

Please sign in to comment.