screen.go 7.8 KB

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