diff options
author | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2018-08-21 15:44:21 +0000 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2018-08-21 15:44:21 +0000 |
commit | fc3cff95f480e91644cbefa96d95ff0978fe0cfa (patch) | |
tree | 33a5c072296f1595722f698c144d242e27a7cf82 | |
parent | be7533abf18211a37b1895e9cea0bb31401926ff (diff) | |
parent | 1be685a7f3a8e0e01a2fd18e1efcee0393abd8f8 (diff) | |
download | buildstream-fc3cff95f480e91644cbefa96d95ff0978fe0cfa.tar.gz |
Merge branch 'tristan/notifications-1.2' into 'bst-1.2'
_frontend/linuxapp.py: Fix special casing around desktop notification escape sequence
See merge request BuildStream/buildstream!693
-rw-r--r-- | buildstream/_frontend/linuxapp.py | 37 |
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) |