screen.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. // EnterAltScreen enters the alternate screen buffer, which consumes the entire
  102. // terminal window. ExitAltScreen will return the terminal to its former state.
  103. //
  104. // Deprecated: Use the WithAltScreen ProgramOption instead.
  105. func (p *Program) EnterAltScreen() {
  106. if p.renderer != nil {
  107. p.renderer.enterAltScreen()
  108. }
  109. }
  110. // ExitAltScreen exits the alternate screen buffer.
  111. //
  112. // Deprecated: The altscreen will exited automatically when the program exits.
  113. func (p *Program) ExitAltScreen() {
  114. if p.renderer != nil {
  115. p.renderer.exitAltScreen()
  116. }
  117. }
  118. // EnableMouseCellMotion enables mouse click, release, wheel and motion events
  119. // if a mouse button is pressed (i.e., drag events).
  120. //
  121. // Deprecated: Use the WithMouseCellMotion ProgramOption instead.
  122. func (p *Program) EnableMouseCellMotion() {
  123. p.renderer.enableMouseCellMotion()
  124. }
  125. // DisableMouseCellMotion disables Mouse Cell Motion tracking. This will be
  126. // called automatically when exiting a Bubble Tea program.
  127. //
  128. // Deprecated: The mouse will automatically be disabled when the program exits.
  129. func (p *Program) DisableMouseCellMotion() {
  130. p.renderer.disableMouseCellMotion()
  131. }
  132. // EnableMouseAllMotion enables mouse click, release, wheel and motion events,
  133. // regardless of whether a mouse button is pressed. Many modern terminals
  134. // support this, but not all.
  135. //
  136. // Deprecated: Use the WithMouseAllMotion ProgramOption instead.
  137. func (p *Program) EnableMouseAllMotion() {
  138. p.renderer.enableMouseAllMotion()
  139. }
  140. // DisableMouseAllMotion disables All Motion mouse tracking. This will be
  141. // called automatically when exiting a Bubble Tea program.
  142. //
  143. // Deprecated: The mouse will automatically be disabled when the program exits.
  144. func (p *Program) DisableMouseAllMotion() {
  145. p.renderer.disableMouseAllMotion()
  146. }