Skip to content
Myr

fix: program renderer commands (#1030)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Using program commands like p.EnableMouseCellMotion and p.SetWindowTitle _before_ the program starts can panic the application since `renderer` hasn't been initialized yet. Use program options to enable and set these options if `renderer` is not initialized.

authored by Ayman Bagabas · committed by GitHub · parent 5331b83 · Browse files · 2 files+38 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Fixes: https://github.com/charmbracelet/bubbletea/issues/1029

Diff stats

2 files+38 added−5 removed

  • other:+38 added−5 removed

2 files+38 added−5 removed

modified:screen.go+31 added-5 removed
149 unmodified lines
150// Deprecated: Use the WithAltScreen ProgramOption instead.151func (p *Program) EnterAltScreen() {152 if p.renderer != nil {153 p.renderer.enterAltScreen()154 } else {155 p.startupOptions |= withAltScreen156 }157}158159// ExitAltScreen exits the alternate screen buffer.
1 unmodified line
161// Deprecated: The altscreen will exited automatically when the program exits.162func (p *Program) ExitAltScreen() {163 if p.renderer != nil {164 p.renderer.exitAltScreen()165 } else {166 p.startupOptions &^= withAltScreen167 }168}169170// EnableMouseCellMotion enables mouse click, release, wheel and motion events171// if a mouse button is pressed (i.e., drag events).172//173// Deprecated: Use the WithMouseCellMotion ProgramOption instead.174func (p *Program) EnableMouseCellMotion() {175 if p.renderer != nil {171 p.renderer.enableMouseCellMotion()176 p.renderer.enableMouseCellMotion()177 } else {178 p.startupOptions |= withMouseCellMotion179 }180}181182// DisableMouseCellMotion disables Mouse Cell Motion tracking. This will be183// called automatically when exiting a Bubble Tea program.184//185// Deprecated: The mouse will automatically be disabled when the program exits.186func (p *Program) DisableMouseCellMotion() {187 if p.renderer != nil {179 p.renderer.disableMouseCellMotion()188 p.renderer.disableMouseCellMotion()189 } else {190 p.startupOptions &^= withMouseCellMotion191 }192}193194// EnableMouseAllMotion enables mouse click, release, wheel and motion events,195// regardless of whether a mouse button is pressed. Many modern terminals196// support this, but not all.197//198// Deprecated: Use the WithMouseAllMotion ProgramOption instead.199func (p *Program) EnableMouseAllMotion() {200 if p.renderer != nil {188 p.renderer.enableMouseAllMotion()201 p.renderer.enableMouseAllMotion()202 } else {203 p.startupOptions |= withMouseAllMotion204 }205}206207// DisableMouseAllMotion disables All Motion mouse tracking. This will be208// called automatically when exiting a Bubble Tea program.209//210// Deprecated: The mouse will automatically be disabled when the program exits.211func (p *Program) DisableMouseAllMotion() {212 if p.renderer != nil {196 p.renderer.disableMouseAllMotion()213 p.renderer.disableMouseAllMotion()214 } else {215 p.startupOptions &^= withMouseAllMotion216 }217}218219// SetWindowTitle sets the terminal window title.220//221// Deprecated: Use the SetWindowTitle command instead.222func (p *Program) SetWindowTitle(title string) {223 if p.renderer != nil {201 p.renderer.setWindowTitle(title)224 p.renderer.setWindowTitle(title)225 } else {226 p.startupTitle = title227 }228}
modified:tea.go+7 added
129 unmodified lines
130 // Configuration options that will set as the program is initializing,131 // treated as bits. These options can be set via various ProgramOptions.132 startupOptions startupOptions133134 // startupTitle is the title that will be set on the terminal when the135 // program starts.136 startupTitle string137138 inputType inputType139140 ctx context.Context141 cancel context.CancelFunc
351 unmodified lines
493 return p.initialModel, err494 }495496 // Honor program startup options.497 if p.startupTitle != "" {498 p.renderer.setWindowTitle(p.startupTitle)499 }500 if p.startupOptions&withAltScreen != 0 {501 p.renderer.enterAltScreen()502 }503 if p.startupOptions&withoutBracketedPaste == 0 {
220 unmodified lines