screen: extend interface with LockRegion method

Extend the Screen interface with a new LockRegion method. This method
sets or unsets a lock on a region of cells. This will be used in
subsequent commits to enable direct drawing to the underlying TTY. The
locks are necessary in order to prevent cells from being drawn on top of
a directly drawn cell.

Implement this interface for the three screen implementations included
in the library.
This commit is contained in:
Tim Culverhouse 2023-03-18 19:58:58 -05:00 committed by Garrett D'Amore
parent 894250edb7
commit ae2c4a8044
4 changed files with 50 additions and 0 deletions

View File

@ -255,6 +255,10 @@ type Screen interface {
// does not support application-initiated resizing, whereas the legacy terminal does.
// Also, some emulators can support this but may have it disabled by default.
SetSize(int, int)
// LockRegion sets or unsets a lock on a region of cells. A lock on a
// cell prevents the cell from being redrawn.
LockRegion(x, y, width, height int, lock bool)
}
// NewScreen returns a default Screen suitable for the user's terminal

View File

@ -553,3 +553,18 @@ func (s *simscreen) Suspend() error {
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)
}
}
}
}

View File

@ -1852,6 +1852,22 @@ 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)
}
}
}
}
// engage is used to place the terminal in raw mode and establish screen size, etc.
// Think of this is as tcell "engaging" the clutch, as it's going to be driving the
// terminal interface.

View File

@ -562,6 +562,21 @@ 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)
}
}
}
}
// WebKeyNames maps string names reported from HTML
// (KeyboardEvent.key) to tcell accepted keys.
var WebKeyNames = map[string]Key{