screen.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. // enableReportFocusMsg is an internal message that signals to enable focus
  126. // reporting. You can send an enableReportFocusMsg with EnableReportFocus.
  127. type enableReportFocusMsg struct{}
  128. // EnableReportFocus is a special command that tells the Bubble Tea program to
  129. // report focus events to the program.
  130. func EnableReportFocus() Msg {
  131. return enableReportFocusMsg{}
  132. }
  133. // disableReportFocusMsg is an internal message that signals to disable focus
  134. // reporting. You can send an disableReportFocusMsg with DisableReportFocus.
  135. type disableReportFocusMsg struct{}
  136. // DisableReportFocus is a special command that tells the Bubble Tea program to
  137. // stop reporting focus events to the program.
  138. func DisableReportFocus() Msg {
  139. return disableReportFocusMsg{}
  140. }
  141. // EnterAltScreen enters the alternate screen buffer, which consumes the entire
  142. // terminal window. ExitAltScreen will return the terminal to its former state.
  143. //
  144. // Deprecated: Use the WithAltScreen ProgramOption instead.
  145. func (p *Program) EnterAltScreen() {
  146. if p.renderer != nil {
  147. p.renderer.enterAltScreen()
  148. } else {
  149. p.startupOptions |= withAltScreen
  150. }
  151. }
  152. // ExitAltScreen exits the alternate screen buffer.
  153. //
  154. // Deprecated: The altscreen will exited automatically when the program exits.
  155. func (p *Program) ExitAltScreen() {
  156. if p.renderer != nil {
  157. p.renderer.exitAltScreen()
  158. } else {
  159. p.startupOptions &^= withAltScreen
  160. }
  161. }
  162. // EnableMouseCellMotion enables mouse click, release, wheel and motion events
  163. // if a mouse button is pressed (i.e., drag events).
  164. //
  165. // Deprecated: Use the WithMouseCellMotion ProgramOption instead.
  166. func (p *Program) EnableMouseCellMotion() {
  167. if p.renderer != nil {
  168. p.renderer.enableMouseCellMotion()
  169. } else {
  170. p.startupOptions |= withMouseCellMotion
  171. }
  172. }
  173. // DisableMouseCellMotion disables Mouse Cell Motion tracking. This will be
  174. // called automatically when exiting a Bubble Tea program.
  175. //
  176. // Deprecated: The mouse will automatically be disabled when the program exits.
  177. func (p *Program) DisableMouseCellMotion() {
  178. if p.renderer != nil {
  179. p.renderer.disableMouseCellMotion()
  180. } else {
  181. p.startupOptions &^= withMouseCellMotion
  182. }
  183. }
  184. // EnableMouseAllMotion enables mouse click, release, wheel and motion events,
  185. // regardless of whether a mouse button is pressed. Many modern terminals
  186. // support this, but not all.
  187. //
  188. // Deprecated: Use the WithMouseAllMotion ProgramOption instead.
  189. func (p *Program) EnableMouseAllMotion() {
  190. if p.renderer != nil {
  191. p.renderer.enableMouseAllMotion()
  192. } else {
  193. p.startupOptions |= withMouseAllMotion
  194. }
  195. }
  196. // DisableMouseAllMotion disables All Motion mouse tracking. This will be
  197. // called automatically when exiting a Bubble Tea program.
  198. //
  199. // Deprecated: The mouse will automatically be disabled when the program exits.
  200. func (p *Program) DisableMouseAllMotion() {
  201. if p.renderer != nil {
  202. p.renderer.disableMouseAllMotion()
  203. } else {
  204. p.startupOptions &^= withMouseAllMotion
  205. }
  206. }
  207. // SetWindowTitle sets the terminal window title.
  208. //
  209. // Deprecated: Use the SetWindowTitle command instead.
  210. func (p *Program) SetWindowTitle(title string) {
  211. if p.renderer != nil {
  212. p.renderer.setWindowTitle(title)
  213. } else {
  214. p.startupTitle = title
  215. }
  216. }