main.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #!/usr/bin/env python
  2. # License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
  3. OPTIONS = '''\
  4. --align
  5. type=choices
  6. choices=center,left,right
  7. default=center
  8. Horizontal alignment for the displayed image.
  9. --place
  10. Choose where on the screen to display the image. The image will be scaled to fit
  11. into the specified rectangle. The syntax for specifying rectangles is
  12. <:italic:`width`>x<:italic:`height`>@<:italic:`left`>x<:italic:`top`>.
  13. All measurements are in cells (i.e. cursor positions) with the origin
  14. :italic:`(0, 0)` at the top-left corner of the screen. Note that the :option:`--align`
  15. option will horizontally align the image within this rectangle. By default, the image
  16. is horizontally centered within the rectangle. Using place will cause the cursor to
  17. be positioned at the top left corner of the image, instead of on the line after the image.
  18. --scale-up
  19. type=bool-set
  20. When used in combination with :option:`--place` it will cause images that are
  21. smaller than the specified area to be scaled up to use as much of the specified
  22. area as possible.
  23. --background
  24. default=none
  25. Specify a background color, this will cause transparent images to be composited
  26. on top of the specified color.
  27. --mirror
  28. default=none
  29. type=choices
  30. choices=none,horizontal,vertical,both
  31. Mirror the image about a horizontal or vertical axis or both.
  32. --clear
  33. type=bool-set
  34. Remove all images currently displayed on the screen.
  35. --transfer-mode
  36. type=choices
  37. choices=detect,file,stream,memory
  38. default=detect
  39. Which mechanism to use to transfer images to the terminal. The default is to
  40. auto-detect. :italic:`file` means to use a temporary file, :italic:`memory` means
  41. to use shared memory, :italic:`stream` means to send the data via terminal
  42. escape codes. Note that if you use the :italic:`file` or :italic:`memory` transfer
  43. modes and you are connecting over a remote session then image display will not
  44. work.
  45. --detect-support
  46. type=bool-set
  47. Detect support for image display in the terminal. If not supported, will exit
  48. with exit code 1, otherwise will exit with code 0 and print the supported
  49. transfer mode to stderr, which can be used with the :option:`--transfer-mode`
  50. option.
  51. --detection-timeout
  52. type=float
  53. default=10
  54. The amount of time (in seconds) to wait for a response from the terminal, when
  55. detecting image display support.
  56. --use-window-size
  57. Instead of querying the terminal for the window size, use the specified size, which must
  58. be of the format: width_in_cells,height_in_cells,width_in_pixels,height_in_pixels
  59. --print-window-size
  60. type=bool-set
  61. Print out the window size as <:italic:`width`>x<:italic:`height`> (in pixels) and quit. This is a
  62. convenience method to query the window size if using :code:`kitten icat`
  63. from a scripting language that cannot make termios calls.
  64. --stdin
  65. type=choices
  66. choices=detect,yes,no
  67. default=detect
  68. Read image data from STDIN. The default is to do it automatically, when STDIN is
  69. not a terminal, but you can turn it off or on explicitly, if needed.
  70. --silent
  71. type=bool-set
  72. Not used, present for legacy compatibility.
  73. --engine
  74. type=choices
  75. choices=auto,builtin,magick
  76. default=auto
  77. The engine used for decoding and processing of images. The default is to use
  78. the most appropriate engine. The :code:`builtin` engine uses Go's native
  79. imaging libraries. The :code:`magick` engine uses ImageMagick which requires
  80. it to be installed on the system.
  81. --z-index -z
  82. default=0
  83. Z-index of the image. When negative, text will be displayed on top of the image.
  84. Use a double minus for values under the threshold for drawing images under cell
  85. background colors. For example, :code:`--1` evaluates as -1,073,741,825.
  86. --loop -l
  87. default=-1
  88. type=int
  89. Number of times to loop animations. Negative values loop forever. Zero means
  90. only the first frame of the animation is displayed. Otherwise, the animation
  91. is looped the specified number of times.
  92. --hold
  93. type=bool-set
  94. Wait for a key press before exiting after displaying the images.
  95. --unicode-placeholder
  96. type=bool-set
  97. Use the Unicode placeholder method to display the images. Useful to display
  98. images from within full screen terminal programs that do not understand the
  99. kitty graphics protocol such as multiplexers or editors. See
  100. :ref:`graphics_unicode_placeholders` for details. Note that when using this
  101. method, placed (with :option:`--place`) images that do not fit on the screen,
  102. will get wrapped at the screen edge instead of getting truncated. This
  103. wrapping is per line and therefore the image will look like it is interleaved
  104. with blank lines.
  105. --passthrough
  106. type=choices
  107. choices=detect,tmux,none
  108. default=detect
  109. Whether to surround graphics commands with escape sequences that allow them to passthrough
  110. programs like tmux. The default is to detect when running inside tmux and automatically use
  111. the tmux passthrough escape codes. Note that when this option is enabled it implies
  112. :option:`--unicode-placeholder` as well.
  113. --image-id
  114. type=int
  115. default=0
  116. The graphics protocol id to use for the created image. Normally, a random id is created if needed.
  117. This option allows control of the id. When multiple images are sent, sequential ids starting from the specified id
  118. are used. Valid ids are from 1 to 4294967295. Numbers outside this range are automatically wrapped.
  119. '''
  120. help_text = (
  121. 'A cat like utility to display images in the terminal.'
  122. ' You can specify multiple image files and/or directories.'
  123. ' Directories are scanned recursively for image files. If STDIN'
  124. ' is not a terminal, image data will be read from it as well.'
  125. ' You can also specify HTTP(S) or FTP URLs which will be'
  126. ' automatically downloaded and displayed.'
  127. )
  128. usage = 'image-file-or-url-or-directory ...'
  129. if __name__ == '__main__':
  130. raise SystemExit('This should be run as kitten icat')
  131. elif __name__ == '__doc__':
  132. import sys
  133. from kitty.cli import CompletionSpec
  134. cd = sys.cli_docs # type: ignore
  135. cd['usage'] = usage
  136. cd['options'] = lambda: OPTIONS.format()
  137. cd['help_text'] = help_text
  138. cd['short_desc'] = 'Display images in the terminal'
  139. cd['args_completion'] = CompletionSpec.from_string('type:file mime:image/* group:Images')