diff --git a/screen.go b/screen.go new file mode 100644 index 0000000..2c7c771 --- /dev/null +++ b/screen.go @@ -0,0 +1,145 @@ +package tea + +// WindowSizeMsg is used to report the terminal size. It's sent to Update once +// initially and then on every terminal resize. Note that Windows does not +// have support for reporting when resizes occur as it does not support the +// SIGWINCH signal. +type WindowSizeMsg struct { + Width int + Height int +} + +// EnterAltScreen is a special command that tells the Bubble Tea program to +// enter the alternate screen buffer. +// +// Because commands run asynchronously, this command should not be used in your +// model's Init function. To initialize your program with the altscreen enabled +// use the WithAltScreen ProgramOption instead. +func EnterAltScreen() Msg { + return enterAltScreenMsg{} +} + +// enterAltScreenMsg in an internal message signals that the program should +// enter alternate screen buffer. You can send a enterAltScreenMsg with +// EnterAltScreen. +type enterAltScreenMsg struct{} + +// ExitAltScreen is a special command that tells the Bubble Tea program to exit +// the alternate screen buffer. This command should be used to exit the +// alternate screen buffer while the program is running. +// +// Note that the alternate screen buffer will be automatically exited when the +// program quits. +func ExitAltScreen() Msg { + return exitAltScreenMsg{} +} + +// exitAltScreenMsg in an internal message signals that the program should exit +// alternate screen buffer. You can send a exitAltScreenMsg with ExitAltScreen. +type exitAltScreenMsg struct{} + +// EnableMouseCellMotion is a special command that enables mouse click, +// release, and wheel events. Mouse movement events are also captured if +// a mouse button is pressed (i.e., drag events). +// +// Because commands run asynchronously, this command should not be used in your +// model's Init function. Use the WithMouseCellMotion ProgramOption instead. +func EnableMouseCellMotion() Msg { + return enableMouseCellMotionMsg{} +} + +// enableMouseCellMotionMsg is a special command that signals to start +// listening for "cell motion" type mouse events (ESC[?1002l). To send an +// enableMouseCellMotionMsg, use the EnableMouseCellMotion command. +type enableMouseCellMotionMsg struct{} + +// EnableMouseAllMotion is a special command that enables mouse click, release, +// wheel, and motion events, which are delivered regardless of whether a mouse +// button is pressed, effectively enabling support for hover interactions. +// +// Many modern terminals support this, but not all. If in doubt, use +// EnableMouseCellMotion instead. +// +// Because commands run asynchronously, this command should not be used in your +// model's Init function. Use the WithMouseAllMotion ProgramOption instead. +func EnableMouseAllMotion() Msg { + return enableMouseAllMotionMsg{} +} + +// enableMouseAllMotionMsg is a special command that signals to start listening +// for "all motion" type mouse events (ESC[?1003l). To send an +// enableMouseAllMotionMsg, use the EnableMouseAllMotion command. +type enableMouseAllMotionMsg struct{} + +// DisableMouse is a special command that stops listening for mouse events. +func DisableMouse() Msg { + return disableMouseMsg{} +} + +// disableMouseMsg is an internal message that that signals to stop listening +// for mouse events. To send a disableMouseMsg, use the DisableMouse command. +type disableMouseMsg struct{} + +// HideCursor is a special command for manually instructing Bubble Tea to hide +// the cursor. In some rare cases, certain operations will cause the terminal +// to show the cursor, which is normally hidden for the duration of a Bubble +// Tea program's lifetime. You will most likely not need to use this command. +func HideCursor() Msg { + return hideCursorMsg{} +} + +// hideCursorMsg is an internal command used to hide the cursor. You can send +// this message with HideCursor. +type hideCursorMsg struct{} + +// EnterAltScreen enters the alternate screen buffer, which consumes the entire +// terminal window. ExitAltScreen will return the terminal to its former state. +// +// Deprecated: Use the WithAltScreen ProgramOption instead. +func (p *Program) EnterAltScreen() { + if p.renderer != nil { + p.renderer.enterAltScreen() + } +} + +// ExitAltScreen exits the alternate screen buffer. +// +// Deprecated: The altscreen will exited automatically when the program exits. +func (p *Program) ExitAltScreen() { + if p.renderer != nil { + p.renderer.exitAltScreen() + } +} + +// EnableMouseCellMotion enables mouse click, release, wheel and motion events +// if a mouse button is pressed (i.e., drag events). +// +// Deprecated: Use the WithMouseCellMotion ProgramOption instead. +func (p *Program) EnableMouseCellMotion() { + p.renderer.enableMouseCellMotion() +} + +// DisableMouseCellMotion disables Mouse Cell Motion tracking. This will be +// called automatically when exiting a Bubble Tea program. +// +// Deprecated: The mouse will automatically be disabled when the program exits. +func (p *Program) DisableMouseCellMotion() { + p.renderer.disableMouseCellMotion() +} + +// EnableMouseAllMotion enables mouse click, release, wheel and motion events, +// regardless of whether a mouse button is pressed. Many modern terminals +// support this, but not all. +// +// Deprecated: Use the WithMouseAllMotion ProgramOption instead. +func (p *Program) EnableMouseAllMotion() { + p.renderer.enableMouseAllMotion() +} + +// DisableMouseAllMotion disables All Motion mouse tracking. This will be +// called automatically when exiting a Bubble Tea program. +// +// Deprecated: The mouse will automatically be disabled when the program exits. +func (p *Program) DisableMouseAllMotion() { + p.renderer.disableMouseAllMotion() +} diff --git a/tea.go b/tea.go index 5533f63..b080a2f 100644 --- a/tea.go +++ b/tea.go @@ -154,98 +154,6 @@ func Quit() Msg { // send a quitMsg with Quit. type quitMsg struct{} -// EnterAltScreen is a special command that tells the Bubble Tea program to -// enter the alternate screen buffer. -// -// Because commands run asynchronously, this command should not be used in your -// model's Init function. To initialize your program with the altscreen enabled -// use the WithAltScreen ProgramOption instead. -func EnterAltScreen() Msg { - return enterAltScreenMsg{} -} - -// enterAltScreenMsg in an internal message signals that the program should -// enter alternate screen buffer. You can send a enterAltScreenMsg with -// EnterAltScreen. -type enterAltScreenMsg struct{} - -// ExitAltScreen is a special command that tells the Bubble Tea program to exit -// the alternate screen buffer. This command should be used to exit the -// alternate screen buffer while the program is running. -// -// Note that the alternate screen buffer will be automatically exited when the -// program quits. -func ExitAltScreen() Msg { - return exitAltScreenMsg{} -} - -// exitAltScreenMsg in an internal message signals that the program should exit -// alternate screen buffer. You can send a exitAltScreenMsg with ExitAltScreen. -type exitAltScreenMsg struct{} - -// EnableMouseCellMotion is a special command that enables mouse click, -// release, and wheel events. Mouse movement events are also captured if -// a mouse button is pressed (i.e., drag events). -// -// Because commands run asynchronously, this command should not be used in your -// model's Init function. Use the WithMouseCellMotion ProgramOption instead. -func EnableMouseCellMotion() Msg { - return enableMouseCellMotionMsg{} -} - -// enableMouseCellMotionMsg is a special command that signals to start -// listening for "cell motion" type mouse events (ESC[?1002l). To send an -// enableMouseCellMotionMsg, use the EnableMouseCellMotion command. -type enableMouseCellMotionMsg struct{} - -// EnableMouseAllMotion is a special command that enables mouse click, release, -// wheel, and motion events, which are delivered regardless of whether a mouse -// button is pressed, effectively enabling support for hover interactions. -// -// Many modern terminals support this, but not all. If in doubt, use -// EnableMouseCellMotion instead. -// -// Because commands run asynchronously, this command should not be used in your -// model's Init function. Use the WithMouseAllMotion ProgramOption instead. -func EnableMouseAllMotion() Msg { - return enableMouseAllMotionMsg{} -} - -// enableMouseAllMotionMsg is a special command that signals to start listening -// for "all motion" type mouse events (ESC[?1003l). To send an -// enableMouseAllMotionMsg, use the EnableMouseAllMotion command. -type enableMouseAllMotionMsg struct{} - -// DisableMouse is a special command that stops listening for mouse events. -func DisableMouse() Msg { - return disableMouseMsg{} -} - -// disableMouseMsg is an internal message that that signals to stop listening -// for mouse events. To send a disableMouseMsg, use the DisableMouse command. -type disableMouseMsg struct{} - -// WindowSizeMsg is used to report the terminal size. It's sent to Update once -// initially and then on every terminal resize. Note that Windows does not -// have support for reporting when resizes occur as it does not support the -// SIGWINCH signal. -type WindowSizeMsg struct { - Width int - Height int -} - -// HideCursor is a special command for manually instructing Bubble Tea to hide -// the cursor. In some rare cases, certain operations will cause the terminal -// to show the cursor, which is normally hidden for the duration of a Bubble -// Tea program's lifetime. You will most likely not need to use this command. -func HideCursor() Msg { - return hideCursorMsg{} -} - -// hideCursorMsg is an internal command used to hide the cursor. You can send -// this message with HideCursor. -type hideCursorMsg struct{} - // NewProgram creates a new Program. func NewProgram(model Model, opts ...ProgramOption) *Program { p := &Program{ @@ -606,58 +514,6 @@ func (p *Program) shutdown(kill bool) { } } -// EnterAltScreen enters the alternate screen buffer, which consumes the entire -// terminal window. ExitAltScreen will return the terminal to its former state. -// -// Deprecated: Use the WithAltScreen ProgramOption instead. -func (p *Program) EnterAltScreen() { - if p.renderer != nil { - p.renderer.enterAltScreen() - } -} - -// ExitAltScreen exits the alternate screen buffer. -// -// Deprecated: The altscreen will exited automatically when the program exits. -func (p *Program) ExitAltScreen() { - if p.renderer != nil { - p.renderer.exitAltScreen() - } -} - -// EnableMouseCellMotion enables mouse click, release, wheel and motion events -// if a mouse button is pressed (i.e., drag events). -// -// Deprecated: Use the WithMouseCellMotion ProgramOption instead. -func (p *Program) EnableMouseCellMotion() { - p.renderer.enableMouseCellMotion() -} - -// DisableMouseCellMotion disables Mouse Cell Motion tracking. This will be -// called automatically when exiting a Bubble Tea program. -// -// Deprecated: The mouse will automatically be disabled when the program exits. -func (p *Program) DisableMouseCellMotion() { - p.renderer.disableMouseCellMotion() -} - -// EnableMouseAllMotion enables mouse click, release, wheel and motion events, -// regardless of whether a mouse button is pressed. Many modern terminals -// support this, but not all. -// -// Deprecated: Use the WithMouseAllMotion ProgramOption instead. -func (p *Program) EnableMouseAllMotion() { - p.renderer.enableMouseAllMotion() -} - -// DisableMouseAllMotion disables All Motion mouse tracking. This will be -// called automatically when exiting a Bubble Tea program. -// -// Deprecated: The mouse will automatically be disabled when the program exits. -func (p *Program) DisableMouseAllMotion() { - p.renderer.disableMouseAllMotion() -} - // ReleaseTerminal restores the original terminal state and cancels the input // reader. You can return control to the Program with RestoreTerminal. func (p *Program) ReleaseTerminal() error {