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

screen: extend interface with Tty method

Extend the Screen interface with a new Tty method, which returns the
underlying tty when the screen is a terminal. This enables direct
drawing to the Tty.

Implement the interface for the three screen implementatinos included in
the library.
This commit is contained in:
Tim Culverhouse 2023-03-18 20:03:54 -05:00 committed by Garrett D'Amore
parent ae2c4a8044
commit fa6cd3ec5b
4 changed files with 17 additions and 0 deletions

View File

@ -259,6 +259,11 @@ type Screen interface {
// 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)
// Tty returns the underlying Tty. If the screen is not a terminal, the
// returned bool will be false
Tty() (Tty, bool)
}
// NewScreen returns a default Screen suitable for the user's terminal

View File

@ -568,3 +568,7 @@ func (s *simscreen) LockRegion(x, y, width, height int, lock bool) {
}
}
}
func (s *simscreen) Tty() (Tty, bool) {
return nil, false
}

View File

@ -1868,6 +1868,10 @@ func (t *tScreen) LockRegion(x, y, width, height int, lock bool) {
}
}
func (t *tScreen) Tty() (Tty, bool) {
return t.tty, true
}
// 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

@ -577,6 +577,10 @@ func (t *wScreen) LockRegion(x, y, width, height int, lock bool) {
}
}
func (t *wScreen) Tty() (Tty, bool) {
return nil, false
}
// WebKeyNames maps string names reported from HTML
// (KeyboardEvent.key) to tcell accepted keys.
var WebKeyNames = map[string]Key{