Skip to content
Myr

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

2 files+37 added−13 removed

modified:renderer.go+11 added-1 removed
27 unmodified lines
28 done chan struct{}29 lastRender string30 linesRendered int3132 // essentially whether or not we're using the full size of the terminal33 altScreenActive bool3435 // renderer dimensions; usually the size of the window36 width int37 height int38
119 unmodified lines
158 }159160 // 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 }170171 _, _ = r.out.Write(out.Bytes())172 r.lastRender = r.buf.String()173 r.buf.Reset()
220 unmodified lines
modified:tea.go+26 added-12 removed
51 unmodified lines
52 init Init53 update Update54 view View5556 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}6162// Quit is a special command that tells the program to exit.63func Quit() Msg {
28 unmodified lines
9293// Start initializes the program.94func (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 )101102 p.renderer = newRenderer(p.output, &p.mtx)103104 err := initTerminal()105 if err != nil {106 return err107 }
7 unmodified lines
115 }()116 }117118 // Start renderer116 mrRenderer.start()119 p.renderer.start()120 p.renderer.altScreenActive = p.altScreenActive121122 // Render initial view119 mrRenderer.write(p.view(model))123 p.renderer.write(p.view(model))124125 // Subscribe to user input126 go func() {127 for {
42 unmodified lines
170 case msg := <-msgs:171172 // Handle quit message173 if _, ok := msg.(quitMsg); ok {170 mrRenderer.stop()174 p.renderer.stop()175 close(done)176 return nil177 }178
5 unmodified lines
184 continue185 }186187 // 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 lines
199 p.mtx.Lock()200 defer p.mtx.Unlock()201 fmt.Fprintf(p.output, te.CSI+te.AltScreenSeq)202 moveCursor(p.output, 0, 0)203204 p.altScreenActive = true205 if p.renderer != nil {206 p.renderer.altScreenActive = p.altScreenActive207 }208}209210// ExitAltScreen exits the alternate screen buffer.211func (p *Program) ExitAltScreen() {212 p.mtx.Lock()213 defer p.mtx.Unlock()214 fmt.Fprintf(p.output, te.CSI+te.ExitAltScreenSeq)215216 p.altScreenActive = false217 if p.renderer != nil {218 p.renderer.altScreenActive = p.altScreenActive219 }220}221222// EnableMouseCellMotion enables mouse click, release, wheel and motion events if a223// button is pressed.
32 unmodified lines