main
1package tea
2
3// WindowSizeMsg is used to report the terminal size. It's sent to Update once
4// initially and then on every terminal resize. Note that Windows does not
5// have support for reporting when resizes occur as it does not support the
6// SIGWINCH signal.
7type WindowSizeMsg struct {
8 Width int
9 Height int
10}
11
12// ClearScreen is a special command that tells the program to clear the screen
13// before the next update. This can be used to move the cursor to the top left
14// of the screen and clear visual clutter when the alt screen is not in use.
15//
16// Note that it should never be necessary to call ClearScreen() for regular
17// redraws.
18func ClearScreen() Msg {
19 return clearScreenMsg{}
20}
21
22// clearScreenMsg is an internal message that signals to clear the screen.
23// You can send a clearScreenMsg with ClearScreen.
24type clearScreenMsg struct{}
25
26// EnterAltScreen is a special command that tells the Bubble Tea program to
27// enter the alternate screen buffer.
28//
29// Because commands run asynchronously, this command should not be used in your
30// model's Init function. To initialize your program with the altscreen enabled
31// use the WithAltScreen ProgramOption instead.
32func EnterAltScreen() Msg {
33 return enterAltScreenMsg{}
34}
35
36// enterAltScreenMsg in an internal message signals that the program should
37// enter alternate screen buffer. You can send a enterAltScreenMsg with
38// EnterAltScreen.
39type enterAltScreenMsg struct{}
40
41// ExitAltScreen is a special command that tells the Bubble Tea program to exit
42// the alternate screen buffer. This command should be used to exit the
43// alternate screen buffer while the program is running.
44//
45// Note that the alternate screen buffer will be automatically exited when the
46// program quits.
47func ExitAltScreen() Msg {
48 return exitAltScreenMsg{}
49}
50
51// exitAltScreenMsg in an internal message signals that the program should exit
52// alternate screen buffer. You can send a exitAltScreenMsg with ExitAltScreen.
53type exitAltScreenMsg struct{}
54
55// EnableMouseCellMotion is a special command that enables mouse click,
56// release, and wheel events. Mouse movement events are also captured if
57// a mouse button is pressed (i.e., drag events).
58//
59// Because commands run asynchronously, this command should not be used in your
60// model's Init function. Use the WithMouseCellMotion ProgramOption instead.
61func EnableMouseCellMotion() Msg {
62 return enableMouseCellMotionMsg{}
63}
64
65// enableMouseCellMotionMsg is a special command that signals to start
66// listening for "cell motion" type mouse events (ESC[?1002l). To send an
67// enableMouseCellMotionMsg, use the EnableMouseCellMotion command.
68type enableMouseCellMotionMsg struct{}
69
70// EnableMouseAllMotion is a special command that enables mouse click, release,
71// wheel, and motion events, which are delivered regardless of whether a mouse
72// button is pressed, effectively enabling support for hover interactions.
73//
74// Many modern terminals support this, but not all. If in doubt, use
75// EnableMouseCellMotion instead.
76//
77// Because commands run asynchronously, this command should not be used in your
78// model's Init function. Use the WithMouseAllMotion ProgramOption instead.
79func EnableMouseAllMotion() Msg {
80 return enableMouseAllMotionMsg{}
81}
82
83// enableMouseAllMotionMsg is a special command that signals to start listening
84// for "all motion" type mouse events (ESC[?1003l). To send an
85// enableMouseAllMotionMsg, use the EnableMouseAllMotion command.
86type enableMouseAllMotionMsg struct{}
87
88// DisableMouse is a special command that stops listening for mouse events.
89func DisableMouse() Msg {
90 return disableMouseMsg{}
91}
92
93// disableMouseMsg is an internal message that signals to stop listening
94// for mouse events. To send a disableMouseMsg, use the DisableMouse command.
95type disableMouseMsg struct{}
96
97// HideCursor is a special command for manually instructing Bubble Tea to hide
98// the cursor. In some rare cases, certain operations will cause the terminal
99// to show the cursor, which is normally hidden for the duration of a Bubble
100// Tea program's lifetime. You will most likely not need to use this command.
101func HideCursor() Msg {
102 return hideCursorMsg{}
103}
104
105// hideCursorMsg is an internal command used to hide the cursor. You can send
106// this message with HideCursor.
107type hideCursorMsg struct{}
108
109// ShowCursor is a special command for manually instructing Bubble Tea to show
110// the cursor.
111func ShowCursor() Msg {
112 return showCursorMsg{}
113}
114
115// showCursorMsg is an internal command used to show the cursor. You can send
116// this message with ShowCursor.
117type showCursorMsg struct{}
118
119// EnableBracketedPaste is a special command that tells the Bubble Tea program
120// to accept bracketed paste input.
121//
122// Note that bracketed paste will be automatically disabled when the
123// program quits.
124func EnableBracketedPaste() Msg {
125 return enableBracketedPasteMsg{}
126}
127
128// enableBracketedPasteMsg in an internal message signals that
129// bracketed paste should be enabled. You can send an
130// enableBracketedPasteMsg with EnableBracketedPaste.
131type enableBracketedPasteMsg struct{}
132
133// DisableBracketedPaste is a special command that tells the Bubble Tea program
134// to accept bracketed paste input.
135//
136// Note that bracketed paste will be automatically disabled when the
137// program quits.
138func DisableBracketedPaste() Msg {
139 return disableBracketedPasteMsg{}
140}
141
142// disableBracketedPasteMsg in an internal message signals that
143// bracketed paste should be disabled. You can send an
144// disableBracketedPasteMsg with DisableBracketedPaste.
145type disableBracketedPasteMsg struct{}
146
147// enableReportFocusMsg is an internal message that signals to enable focus
148// reporting. You can send an enableReportFocusMsg with EnableReportFocus.
149type enableReportFocusMsg struct{}
150
151// EnableReportFocus is a special command that tells the Bubble Tea program to
152// report focus events to the program.
153func EnableReportFocus() Msg {
154 return enableReportFocusMsg{}
155}
156
157// disableReportFocusMsg is an internal message that signals to disable focus
158// reporting. You can send an disableReportFocusMsg with DisableReportFocus.
159type disableReportFocusMsg struct{}
160
161// DisableReportFocus is a special command that tells the Bubble Tea program to
162// stop reporting focus events to the program.
163func DisableReportFocus() Msg {
164 return disableReportFocusMsg{}
165}
166
167// EnterAltScreen enters the alternate screen buffer, which consumes the entire
168// terminal window. ExitAltScreen will return the terminal to its former state.
169//
170// Deprecated: Use the WithAltScreen ProgramOption instead.
171func (p *Program) EnterAltScreen() {
172 if p.renderer != nil {
173 p.renderer.enterAltScreen()
174 } else {
175 p.startupOptions |= withAltScreen
176 }
177}
178
179// ExitAltScreen exits the alternate screen buffer.
180//
181// Deprecated: The altscreen will exited automatically when the program exits.
182func (p *Program) ExitAltScreen() {
183 if p.renderer != nil {
184 p.renderer.exitAltScreen()
185 } else {
186 p.startupOptions &^= withAltScreen
187 }
188}
189
190// EnableMouseCellMotion enables mouse click, release, wheel and motion events
191// if a mouse button is pressed (i.e., drag events).
192//
193// Deprecated: Use the WithMouseCellMotion ProgramOption instead.
194func (p *Program) EnableMouseCellMotion() {
195 if p.renderer != nil {
196 p.renderer.enableMouseCellMotion()
197 } else {
198 p.startupOptions |= withMouseCellMotion
199 }
200}
201
202// DisableMouseCellMotion disables Mouse Cell Motion tracking. This will be
203// called automatically when exiting a Bubble Tea program.
204//
205// Deprecated: The mouse will automatically be disabled when the program exits.
206func (p *Program) DisableMouseCellMotion() {
207 if p.renderer != nil {
208 p.renderer.disableMouseCellMotion()
209 } else {
210 p.startupOptions &^= withMouseCellMotion
211 }
212}
213
214// EnableMouseAllMotion enables mouse click, release, wheel and motion events,
215// regardless of whether a mouse button is pressed. Many modern terminals
216// support this, but not all.
217//
218// Deprecated: Use the WithMouseAllMotion ProgramOption instead.
219func (p *Program) EnableMouseAllMotion() {
220 if p.renderer != nil {
221 p.renderer.enableMouseAllMotion()
222 } else {
223 p.startupOptions |= withMouseAllMotion
224 }
225}
226
227// DisableMouseAllMotion disables All Motion mouse tracking. This will be
228// called automatically when exiting a Bubble Tea program.
229//
230// Deprecated: The mouse will automatically be disabled when the program exits.
231func (p *Program) DisableMouseAllMotion() {
232 if p.renderer != nil {
233 p.renderer.disableMouseAllMotion()
234 } else {
235 p.startupOptions &^= withMouseAllMotion
236 }
237}
238
239// SetWindowTitle sets the terminal window title.
240//
241// Deprecated: Use the SetWindowTitle command instead.
242func (p *Program) SetWindowTitle(title string) {
243 if p.renderer != nil {
244 p.renderer.setWindowTitle(title)
245 } else {
246 p.startupTitle = title
247 }
248}