pointer-shapes.rst 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. Mouse pointer shapes
  2. =======================
  3. .. versionadded:: 0.31.0
  4. This is a simple escape code that can be used by terminal programs to change
  5. the shape of the mouse pointer. This is useful for buttons/links, dragging to
  6. resize panes, etc. It is based on the original escape code proposal from xterm
  7. however, it properly specifies names for the different shapes in a system
  8. independent manner, adds a stack for easy push/pop of shapes, allows programs
  9. to query support and specifies interaction with other terminal state.
  10. The escape code is of the form::
  11. <OSC> 22 ; <optional first char> <comma-separates list of shape names> <ESC>\
  12. Here, ``<OSC>`` is the bytes ``<ESC>]`` and ``<ESC>`` is the byte ``0x1b``.
  13. Spaces in the above are present for clarity only and should not be actually used.
  14. First some examples::
  15. # Set the pointer to a pointing hand
  16. <OSC> 22 ; pointer <ESC>\
  17. # Reset the pointer to default
  18. <OSC> 22 ; <ESC>\
  19. # Push a shape onto the stack making it the current shape
  20. <OSC> 22 ; >wait <ESC>\
  21. # Pop a shape off the stack restoring to the previous shape
  22. <OSC> 22 ; < <ESC>\
  23. # Query the terminal for what the currently set shape is
  24. <OSC> 22 ; ?__current__ <ESC>\
  25. To demo the various shapes, simply run the following command inside kitty::
  26. kitten mouse-demo
  27. For more details see below.
  28. Setting the pointer shape
  29. -------------------------------
  30. For set operations, the optional first char can be either ``=`` or omitted.
  31. Follow the first char with the name of the shape. See the
  32. :ref:`pointer_shape_names` table.
  33. Pushing and popping shapes onto the stack
  34. ---------------------------------------------
  35. The terminal emulator maintains a stack of shapes. To add shapes to the stack,
  36. the optional first char must be ``>`` followed by a comma separated list of
  37. shape names. See the :ref:`pointer_shape_names` table. All the specified names
  38. are added to the stack, with the last name being the top of the stack and the
  39. current shape. If the stack is full, the entry at the bottom of the stack is
  40. evicted. Terminal implementations are free to choose an appropriate maximum
  41. stack size, with a minimum stack size of 16.
  42. To pop shapes of the top of the stack the optional first char must be ``<``.
  43. The comma separated list of names is ignored. Once the stack is empty further
  44. pops have no effect. An empty stack means the terminal is free to use whatever
  45. pointer shape it likes.
  46. Querying support
  47. -------------------
  48. Terminal programs can ask the terminal about this feature by setting the
  49. optional first char to ``?``. The comma separated list of names is then
  50. considered the query to which the terminal must respond with an OSC 22 code.
  51. For example::
  52. <OSC> 22 ; ?__current__ <ESC>\
  53. results in
  54. <OSC> 22 ; shape_name <ESC>\
  55. Here, ``shape_name`` will be a name from the table of shape names below or ``0``
  56. if the stack is empty, i.e., no shape is currently set.
  57. To check if the terminal supports some shapes, pass the shape names and the
  58. terminal will reply with a comma separated list of zeros and ones where 1 means
  59. the shape name is supported and zero means it is not. For example::
  60. <OSC> 22 ; ?pointer,crosshair,no-such-name,wait <ESC>\
  61. results in
  62. <OSC> 22 ; 1,1,0,1 <ESC>\
  63. In addition to ``__current__`` there are a couple of other special names::
  64. __default__ - The terminal responds with the shape name of the shape used by default
  65. __grabbed__ - The terminal responds with the shape name of the shape used when the mouse is "grabbed"
  66. Interaction with other terminal features
  67. ---------------------------------------------
  68. The terminal must maintain separate shape stacks for the *main* and *alternate*
  69. screens. This allows full screen programs, which are likely to be the main
  70. consumers of this feature, to easily temporarily switch back from the alternate screen,
  71. without needing to worry about pointer shape state. Think of suspending a
  72. terminal editor to get back to the shell, for example.
  73. Resetting the terminal must empty both the shape stacks.
  74. When dragging to select text, the terminal is free to ignore any mouse pointer
  75. shape specified using this escape code in favor of one appropriate for
  76. dragging. Similarly, when hovering over a URL or OSC 8 based hyperlink, the
  77. terminal may choose to change the mouse pointer regardless of the value set by
  78. this escape code.
  79. This feature is independent of mouse reporting. The changed pointer shapes apply
  80. regardless of whether the terminal program has enabled mouse reporting or not.
  81. .. _pointer_shape_names:
  82. Pointer shape names
  83. ----------------------------------
  84. There is a well defined set of shape names that all conforming terminal
  85. emulators must support. The list is based on the names used by the `cursor
  86. property in the CSS standard
  87. <https://developer.mozilla.org/en-US/docs/Web/CSS/cursor>`__, click the link to
  88. see representative images for the names. Valid names must consist of only the
  89. characters from the set ``a-z0-9_-``.
  90. .. start list of shape css names (auto generated by gen-key-constants.py do not edit)
  91. #. alias
  92. #. cell
  93. #. copy
  94. #. crosshair
  95. #. default
  96. #. e-resize
  97. #. ew-resize
  98. #. grab
  99. #. grabbing
  100. #. help
  101. #. move
  102. #. n-resize
  103. #. ne-resize
  104. #. nesw-resize
  105. #. no-drop
  106. #. not-allowed
  107. #. ns-resize
  108. #. nw-resize
  109. #. nwse-resize
  110. #. pointer
  111. #. progress
  112. #. s-resize
  113. #. se-resize
  114. #. sw-resize
  115. #. text
  116. #. vertical-text
  117. #. w-resize
  118. #. wait
  119. #. zoom-in
  120. #. zoom-out
  121. .. end list of shape css names
  122. To demo the various shapes, simply run the following command inside kitty::
  123. kitten mouse-demo
  124. Legacy xterm compatibility
  125. ----------------------------
  126. The original xterm proposal for this escape code used shape names from the
  127. file:`X11/cursorfont.h` header on X11 based systems. Terminal implementations
  128. wishing to maintain compatibility with xterm can also implement these names as
  129. aliases for the CSS based names defined in the :ref:`pointer_shape_names` table.
  130. The simplest mode of operation of this escape code, which is no leading
  131. optional char and a single shape name is compatible with xterm.