summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-08-20 18:13:43 +0900
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2018-08-22 04:54:39 +0000
commite575fac087ed4d8ee5f4605615604030583d5449 (patch)
tree3559390cfbcd3be863d7642681fba7dc7e62377d
parentd8256c74e3485d17d56f027c51ccf2c7100ac754 (diff)
downloadbuildstream-tristan/notifications.tar.gz
_frontend/linuxapp.py: Fix special casing around desktop notification escape sequencetristan/notifications
Now we allow the notification to happen on any TERM which starts with 'xterm' or 'vte', and we only do it if the VTE_VERSION is >= 4600, where we know for sure that VTE will not print garbage on the terminal. Fixes #385
-rw-r--r--buildstream/_frontend/linuxapp.py37
1 files changed, 34 insertions, 3 deletions
diff --git a/buildstream/_frontend/linuxapp.py b/buildstream/_frontend/linuxapp.py
index 176c5d052..667ce5c2b 100644
--- a/buildstream/_frontend/linuxapp.py
+++ b/buildstream/_frontend/linuxapp.py
@@ -22,12 +22,43 @@ import click
from .app import App
+# This trick is currently only supported on some terminals,
+# avoid using it where it can cause garbage to be printed
+# to the terminal.
+#
+def _osc_777_supported():
+
+ term = os.environ['TERM']
+
+ if term.startswith('xterm') or term.startswith('vte'):
+
+ # Since vte version 4600, upstream silently ignores
+ # the OSC 777 without printing garbage to the terminal.
+ #
+ # For distros like Fedora who have patched vte, this
+ # will trigger a desktop notification and bring attention
+ # to the terminal.
+ #
+ vte_version = os.environ['VTE_VERSION']
+ try:
+ vte_version_int = int(vte_version)
+ except ValueError:
+ return False
+
+ if vte_version_int >= 4600:
+ return True
+
+ return False
+
+
# A linux specific App implementation
#
class LinuxApp(App):
def notify(self, title, text):
- term = os.environ['TERM']
- if term in ('xterm', 'vte'):
- click.echo("\033]777;notify;{};{}\007".format(title, text))
+ # Currently we only try this notification method
+ # of sending an escape sequence to the terminal
+ #
+ if _osc_777_supported():
+ click.echo("\033]777;notify;{};{}\007".format(title, text), err=True)