main.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/usr/bin/env python
  2. # License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
  3. import sys
  4. def OPTIONS() -> str:
  5. from kitty.constants import standard_icon_names
  6. return f'''
  7. --icon -n
  8. type=list
  9. The name of the icon to use for the notification. An icon with this name
  10. will be searched for on the computer running the terminal emulator. Can
  11. be specified multiple times, the first name that is found will be used.
  12. Standard names: {', '.join(sorted(standard_icon_names))}
  13. --icon-path -p
  14. Path to an image file in PNG/JPEG/GIF formats to use as the icon. If both
  15. name and path are specified then first the name will be looked for and if not found
  16. then the path will be used.
  17. --app-name -a
  18. default=kitten-notify
  19. The application name for the notification.
  20. --button -b
  21. type=list
  22. Add a button with the specified text to the notification. Can be specified multiple times for multiple buttons.
  23. If --wait-till-closed is used then the kitten will print the button number to STDOUT if the user clicks a button.
  24. 1 for the first button, 2 for the second button and so on.
  25. --urgency -u
  26. default=normal
  27. choices=normal,low,critical
  28. The urgency of the notification.
  29. --expire-after -e
  30. The duration, for the notification to appear on screen. The default is to
  31. use the policy of the OS notification service. A value of :code:`never` means the notification should
  32. never expire, however, this may or may not work depending on the policies of the OS notification
  33. service. Time is specified in the form NUMBER[SUFFIX] where SUFFIX can be :code:`s` for seconds, :code:`m` for minutes,
  34. :code:`h` for hours or :code:`d` for days. Non-integer numbers are allowed.
  35. If not specified, seconds is assumed. The notification is guaranteed to be closed automatically
  36. after the specified time has elapsed. The notification could be closed before by user
  37. action or OS policy.
  38. --sound-name -s
  39. default=system
  40. The name of the sound to play with the notification. :code:`system` means let the
  41. notification system use whatever sound it wants. :code:`silent` means prevent
  42. any sound from being played. Any other value is passed to the desktop's notification system
  43. which may or may not honor it.
  44. --type -t
  45. The notification type. Can be any string, it is used by users to create filter rules
  46. for notifications, so choose something descriptive of the notification's purpose.
  47. --identifier -i
  48. The identifier of this notification. If a notification with the same identifier
  49. is already displayed, it is replaced/updated.
  50. --print-identifier -P
  51. type=bool-set
  52. Print the identifier for the notification to STDOUT. Useful when not specifying
  53. your own identifier via the --identifier option.
  54. --wait-till-closed --wait-for-completion -w
  55. type=bool-set
  56. Wait until the notification is closed. If the user activates the notification,
  57. "0" is printed to STDOUT before quitting. If a button on the notification is pressed the
  58. number corresponding to the button is printed to STDOUT. Press the Esc or Ctrl+C keys
  59. to close the notification manually.
  60. --only-print-escape-code
  61. type=bool-set
  62. Only print the escape code to STDOUT. Useful if using this kitten as part
  63. of a larger application. If this is specified, the --wait-till-closed option
  64. will be used for escape code generation, but no actual waiting will be done.
  65. --icon-cache-id -g
  66. Identifier to use when caching icons in the terminal emulator. Using an identifier means
  67. that icon data needs to be transmitted only once using --icon-path. Subsequent invocations
  68. will use the cached icon data, at least until the terminal instance is restarted. This is useful
  69. if this kitten is being used inside a larger application, with --only-print-escape-code.
  70. '''
  71. help_text = '''\
  72. Send notifications to the user that are displayed to them via the
  73. desktop environment's notifications service. Works over SSH as well.
  74. To update an existing notification, specify the identifier of the notification
  75. with the --identifier option. The value should be the same as the identifier specified for
  76. the notification you wish to update.
  77. If no title is specified and an identifier is specified using the --identifier
  78. option, then instead of creating a new notification, an existing notification
  79. with the specified identifier is closed.
  80. '''
  81. usage = 'TITLE [BODY ...]'
  82. if __name__ == '__main__':
  83. raise SystemExit('This should be run as `kitten notify ...`')
  84. elif __name__ == '__doc__':
  85. cd = sys.cli_docs # type: ignore
  86. cd['usage'] = usage
  87. cd['options'] = OPTIONS
  88. cd['help_text'] = help_text
  89. cd['short_desc'] = 'Send notifications to the user'