screen.go

  1package tea
  2
  3import "github.com/charmbracelet/x/ansi"
  4
  5// WindowSizeMsg is used to report the terminal size. It's sent to Update once
  6// initially and then on every terminal resize. Note that Windows does not
  7// have support for reporting when resizes occur as it does not support the
  8// SIGWINCH signal.
  9type WindowSizeMsg struct {
 10	Width  int
 11	Height int
 12}
 13
 14// ClearScreen is a special command that tells the program to clear the screen
 15// before the next update. This can be used to move the cursor to the top left
 16// of the screen and clear visual clutter when the alt screen is not in use.
 17//
 18// Note that it should never be necessary to call ClearScreen() for regular
 19// redraws.
 20func ClearScreen() Msg {
 21	return clearScreenMsg{}
 22}
 23
 24// clearScreenMsg is an internal message that signals to clear the screen.
 25// You can send a clearScreenMsg with ClearScreen.
 26type clearScreenMsg struct{}
 27
 28// EnterAltScreen is a special command that tells the Bubble Tea program to
 29// enter the alternate screen buffer.
 30//
 31// Because commands run asynchronously, this command should not be used in your
 32// model's Init function. To initialize your program with the altscreen enabled
 33// use the WithAltScreen ProgramOption instead.
 34func EnterAltScreen() Msg {
 35	return enableModeMsg{ansi.AltScreenSaveCursorMode}
 36}
 37
 38// ExitAltScreen is a special command that tells the Bubble Tea program to exit
 39// the alternate screen buffer. This command should be used to exit the
 40// alternate screen buffer while the program is running.
 41//
 42// Note that the alternate screen buffer will be automatically exited when the
 43// program quits.
 44func ExitAltScreen() Msg {
 45	return disableModeMsg{ansi.AltScreenSaveCursorMode}
 46}
 47
 48// enableMouseCellMotionMsg is an internal message that signals to enable mouse cell
 49// motion events.
 50type enableMouseCellMotionMsg struct{}
 51
 52// EnableMouseCellMotion is a special command that enables mouse click,
 53// release, and wheel events. Mouse movement events are also captured if
 54// a mouse button is pressed (i.e., drag events).
 55//
 56// Because commands run asynchronously, this command should not be used in your
 57// model's Init function. Use the WithMouseCellMotion ProgramOption instead.
 58func EnableMouseCellMotion() Msg {
 59	return enableMouseCellMotionMsg{}
 60}
 61
 62// enableMouseAllMotionMsg is an internal message that signals to enable mouse
 63// all motion events.
 64type enableMouseAllMotionMsg struct{}
 65
 66// EnableMouseAllMotion is a special command that enables mouse click, release,
 67// wheel, and motion events, which are delivered regardless of whether a mouse
 68// button is pressed, effectively enabling support for hover interactions.
 69//
 70// Many modern terminals support this, but not all. If in doubt, use
 71// EnableMouseCellMotion instead.
 72//
 73// Because commands run asynchronously, this command should not be used in your
 74// model's Init function. Use the WithMouseAllMotion ProgramOption instead.
 75func EnableMouseAllMotion() Msg {
 76	return enableMouseAllMotionMsg{}
 77}
 78
 79// disableMouse motionMsg is an internal message that signals to disable mouse
 80// motion events.
 81type disableMouseMotionMsg struct{}
 82
 83// DisableMouse is a special command that stops listening for mouse events.
 84func DisableMouse() Msg {
 85	return disableMouseMotionMsg{}
 86}
 87
 88// HideCursor is a special command for manually instructing Bubble Tea to hide
 89// the cursor. In some rare cases, certain operations will cause the terminal
 90// to show the cursor, which is normally hidden for the duration of a Bubble
 91// Tea program's lifetime. You will most likely not need to use this command.
 92func HideCursor() Msg {
 93	return disableModeMsg{ansi.TextCursorEnableMode}
 94}
 95
 96// ShowCursor is a special command for manually instructing Bubble Tea to show
 97// the cursor.
 98func ShowCursor() Msg {
 99	return enableModeMsg{ansi.TextCursorEnableMode}
100}
101
102// EnableBracketedPaste is a special command that tells the Bubble Tea program
103// to accept bracketed paste input.
104//
105// Note that bracketed paste will be automatically disabled when the
106// program quits.
107func EnableBracketedPaste() Msg {
108	return enableModeMsg{ansi.BracketedPasteMode}
109}
110
111// DisableBracketedPaste is a special command that tells the Bubble Tea program
112// to accept bracketed paste input.
113//
114// Note that bracketed paste will be automatically disabled when the
115// program quits.
116func DisableBracketedPaste() Msg {
117	return disableModeMsg{ansi.BracketedPasteMode}
118}
119
120// EnableGraphemeClustering is a special command that tells the Bubble Tea
121// program to enable grapheme clustering. This is enabled by default.
122func EnableGraphemeClustering() Msg {
123	return enableModeMsg{ansi.GraphemeClusteringMode}
124}
125
126// DisableGraphemeClustering is a special command that tells the Bubble Tea
127// program to disable grapheme clustering. This mode will be disabled
128// automatically when the program quits.
129func DisableGraphemeClustering() Msg {
130	return disableModeMsg{ansi.GraphemeClusteringMode}
131}
132
133// EnableReportFocus is a special command that tells the Bubble Tea program to
134// enable focus reporting.
135func EnableReportFocus() Msg { return enableModeMsg{ansi.FocusEventMode} }
136
137// DisableReportFocus is a special command that tells the Bubble Tea program to
138// disable focus reporting.
139func DisableReportFocus() Msg { return disableModeMsg{ansi.FocusEventMode} }
140
141// enableModeMsg is an internal message that signals to set a terminal mode.
142type enableModeMsg struct{ ansi.Mode }
143
144// disableModeMsg is an internal message that signals to unset a terminal mode.
145type disableModeMsg struct{ ansi.Mode }
146
147// LayerHitMsg is a message that is sent to the program when a layer is hit by
148// a mouse event. This is used to determine which layer in a compostable view
149// was hit by the mouse event. The layer is identified by its ID, which is a
150// string that is unique to the layer.
151type LayerHitMsg struct {
152	ID    string
153	Mouse MouseMsg
154}