windows: Use alt screen by default (supress with TCELL_ALTSCREEN=disable)

The alternate screen buffer right now only works in VT mode.
This commit is contained in:
Garrett D'Amore 2024-03-02 12:44:10 -08:00
parent 5a591d4275
commit 552bf3cec1
1 changed files with 15 additions and 0 deletions

View File

@ -41,6 +41,7 @@ type cScreen struct {
vten bool
truecolor bool
running bool
disableAlt bool // disable the alternate screen
w int
h int
@ -161,6 +162,8 @@ const (
vtCursorSteadyBar = "\x1b[6 q"
vtDisableAm = "\x1b[?7l"
vtEnableAm = "\x1b[?7h"
vtEnterCA = "\x1b[?1049h\x1b[22;0;0t"
vtExitCA = "\x1b[?1049l\x1b[23;0;0t"
)
var vtCursorStyles = map[CursorStyle]string{
@ -239,6 +242,12 @@ func (s *cScreen) Init() error {
case "enable":
tryVt = true
}
switch os.Getenv("TCELL_ALTSCREEN") {
case "enable":
s.disableAlt = false // also the default
case "disable":
s.disableAlt = true
}
if tryVt {
s.setOutMode(modeVtOutput | modeNoAutoNL | modeCookedOut | modeUnderline)
var om uint32
@ -337,6 +346,9 @@ func (s *cScreen) disengage() {
_, _, _ = procSetConsoleTextAttribute.Call(
uintptr(s.out),
uintptr(s.mapStyle(StyleDefault)))
if s.vten && !s.disableAlt {
s.emitVtString(vtExitCA)
}
}
func (s *cScreen) engage() error {
@ -360,6 +372,9 @@ func (s *cScreen) engage() error {
if s.vten {
s.setOutMode(modeVtOutput | modeNoAutoNL | modeCookedOut | modeUnderline)
if !s.disableAlt {
s.emitVtString(vtEnterCA)
}
s.emitVtString(vtDisableAm)
} else {
s.setOutMode(0)