Skip to content

Commit

Permalink
windows: Use alt screen by default (supress with TCELL_ALTSCREEN=disa…
Browse files Browse the repository at this point in the history
…ble)

The alternate screen buffer right now only works in VT mode.
  • Loading branch information
gdamore committed Mar 2, 2024
1 parent 5a591d4 commit 552bf3c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions console_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type cScreen struct {
vten bool
truecolor bool
running bool
disableAlt bool // disable the alternate screen

w int
h int
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 552bf3c

Please sign in to comment.