Tristan Van Berkom pushed to branch tristan/notifications at BuildStream / buildstream
Commits:
-
aa9f8eb9
by Tristan Van Berkom at 2018-08-21T13:44:09Z
1 changed file:
Changes:
| ... | ... | @@ -22,12 +22,43 @@ import click |
| 22 | 22 |
from .app import App
|
| 23 | 23 |
|
| 24 | 24 |
|
| 25 |
+# This trick is currently only supported on some terminals,
|
|
| 26 |
+# avoid using it where it can cause garbage to be printed
|
|
| 27 |
+# to the terminal.
|
|
| 28 |
+#
|
|
| 29 |
+def _osc_777_supported():
|
|
| 30 |
+ |
|
| 31 |
+ term = os.environ['TERM']
|
|
| 32 |
+ |
|
| 33 |
+ if term.startswith('xterm') or term.startswith('vte'):
|
|
| 34 |
+ |
|
| 35 |
+ # Since vte version 4600, upstream silently ignores
|
|
| 36 |
+ # the OSC 777 without printing garbage to the terminal.
|
|
| 37 |
+ #
|
|
| 38 |
+ # For distros like Fedora who have patched vte, this
|
|
| 39 |
+ # will trigger a desktop notification and bring attention
|
|
| 40 |
+ # to the terminal.
|
|
| 41 |
+ #
|
|
| 42 |
+ vte_version = os.environ['VTE_VERSION']
|
|
| 43 |
+ try:
|
|
| 44 |
+ vte_version_int = int(vte_version)
|
|
| 45 |
+ except ValueError:
|
|
| 46 |
+ return False
|
|
| 47 |
+ |
|
| 48 |
+ if vte_version_int >= 4600:
|
|
| 49 |
+ return True
|
|
| 50 |
+ |
|
| 51 |
+ return False
|
|
| 52 |
+ |
|
| 53 |
+ |
|
| 25 | 54 |
# A linux specific App implementation
|
| 26 | 55 |
#
|
| 27 | 56 |
class LinuxApp(App):
|
| 28 | 57 |
|
| 29 | 58 |
def notify(self, title, text):
|
| 30 | 59 |
|
| 31 |
- term = os.environ['TERM']
|
|
| 32 |
- if term in ('xterm', 'vte'):
|
|
| 33 |
- click.echo("\033]777;notify;{};{}\007".format(title, text))
|
|
| 60 |
+ # Currently we only try this notification method
|
|
| 61 |
+ # of sending an escape sequence to the terminal
|
|
| 62 |
+ #
|
|
| 63 |
+ if _osc_777_supported():
|
|
| 64 |
+ click.echo("\033]777;notify;{};{}\007".format(title, text), err=True)
|
