Fix a bug in macOS terminal where stuff could get sucked into the scroll area
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Christian Rocha · committed by Christian Rocha · parent 8025748 · Browse files · 2 files·+37 added−13 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+37 added−13 removed
- other:+37 added−13 removed
Provenance
- Commit
2f53eeb- Tree
2974be7- Author
Christian Rocha <christian@rocha.is>- Committer
Christian Rocha <christian@rocha.is>- Parent
8025748
2 files changed+37 added−13 removed
modified:renderer.go+11 added-1 removed
27 unmodified lines28 done chan struct{}29 lastRender string30 linesRendered int31 32+ // essentially whether or not we're using the full size of the terminal33+ altScreenActive bool34+35 // renderer dimensions; usually the size of the window36 width int37 height int38 119 unmodified lines158 }159 160 // Make sure the cursor is at the start of the last line to keep rendering161 // behavior consistent.162+ if r.altScreenActive {163+ // We need this case to fix a bug in macOS terminal. In other terminals164+ // the below case seems to do the job regardless of whether or not we're165+ // using the full terminal window.166+ moveCursor(out, r.linesRendered, 0)167+ } else {159- cursorBack(out, r.width)168+ cursorBack(out, r.width)169+ }170 171 _, _ = r.out.Write(out.Bytes())172 r.lastRender = r.buf.String()173 r.buf.Reset()220 unmodified linesmodified:tea.go+26 added-12 removed
51 unmodified lines52 init Init53 update Update54 view View55 56- mtx sync.Mutex57- output *os.File // where to send output. this will usually be os.Stdout.56+ mtx sync.Mutex57+ output *os.File // where to send output. this will usually be os.Stdout.58+ renderer *renderer59+ altScreenActive bool60 }61 62 // Quit is a special command that tells the program to exit.63 func Quit() Msg {28 unmodified lines92 93 // Start initializes the program.94 func (p *Program) Start() error {95 var (94- cmds = make(chan Cmd)95- msgs = make(chan Msg)96- errs = make(chan error)97- done = make(chan struct{})98- mrRenderer = newRenderer(p.output, &p.mtx)96+ cmds = make(chan Cmd)97+ msgs = make(chan Msg)98+ errs = make(chan error)99+ done = make(chan struct{})100 )101 102+ p.renderer = newRenderer(p.output, &p.mtx)103+104 err := initTerminal()105 if err != nil {106 return err107 }7 unmodified lines115 }()116 }117 118 // Start renderer116- mrRenderer.start()119+ p.renderer.start()120+ p.renderer.altScreenActive = p.altScreenActive121 122 // Render initial view119- mrRenderer.write(p.view(model))123+ p.renderer.write(p.view(model))124 125 // Subscribe to user input126 go func() {127 for {42 unmodified lines170 case msg := <-msgs:171 172 // Handle quit message173 if _, ok := msg.(quitMsg); ok {170- mrRenderer.stop()174+ p.renderer.stop()175 close(done)176 return nil177 }178 5 unmodified lines184 continue185 }186 187 // Process internal messages for the renderer184- mrRenderer.handleMessages(msg)188+ p.renderer.handleMessages(msg)189 var cmd Cmd190 model, cmd = p.update(msg, model) // run update191 cmds <- cmd // process command (if any)188- mrRenderer.write(p.view(model)) // send view to renderer192+ p.renderer.write(p.view(model)) // send view to renderer193 }194 }195 }196 2 unmodified lines199 p.mtx.Lock()200 defer p.mtx.Unlock()201 fmt.Fprintf(p.output, te.CSI+te.AltScreenSeq)202 moveCursor(p.output, 0, 0)203+204+ p.altScreenActive = true205+ if p.renderer != nil {206+ p.renderer.altScreenActive = p.altScreenActive207+ }208 }209 210 // ExitAltScreen exits the alternate screen buffer.211 func (p *Program) ExitAltScreen() {212 p.mtx.Lock()213 defer p.mtx.Unlock()214 fmt.Fprintf(p.output, te.CSI+te.ExitAltScreenSeq)215+216+ p.altScreenActive = false217+ if p.renderer != nil {218+ p.renderer.altScreenActive = p.altScreenActive219+ }220 }221 222 // EnableMouseCellMotion enables mouse click, release, wheel and motion events if a223 // button is pressed.32 unmodified lines