Tristan Van Berkom pushed to branch tristan/notifications at BuildStream / buildstream
Commits:
-
ef606229
by Josh Smith at 2018-08-21T14:49:57Z
-
d8256c74
by Qinusty at 2018-08-21T15:46:14Z
-
e575fac0
by Tristan Van Berkom at 2018-08-22T04:54:39Z
2 changed files:
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)
|
... | ... | @@ -508,6 +508,7 @@ class Plugin(): |
508 | 508 |
project = self._get_project()
|
509 | 509 |
|
510 | 510 |
if project._warning_is_fatal(warning_token):
|
511 |
+ detail = detail if detail else ""
|
|
511 | 512 |
raise PluginError(message="{}\n{}".format(brief, detail), reason=warning_token)
|
512 | 513 |
|
513 | 514 |
self.__message(MessageType.WARN, brief=brief, detail=detail)
|