Skip to content

Commit

Permalink
external_script module: allow display full output as notification on …
Browse files Browse the repository at this point in the history
…click (#1585)
  • Loading branch information
maximbaz authored and ultrabug committed Dec 2, 2018
1 parent 6d5da3e commit 9865a2e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions py3status/modules/external_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
The script should not have any parameters, but it could work.
Configuration parameters:
button_show_notification: button to show notification with full output
(default None)
cache_timeout: how often we refresh this module in seconds
(default 15)
format: see placeholders below (default '{output}')
Expand All @@ -21,6 +23,7 @@
(default False)
Format placeholders:
{lines} number of lines in the output
{output} output of script given by "script_path"
i3status.conf example:
Expand Down Expand Up @@ -49,6 +52,7 @@ class Py3status:
"""
"""
# available configuration parameters
button_show_notification = None
cache_timeout = 15
format = '{output}'
localize = True
Expand All @@ -64,8 +68,8 @@ def external_script(self):
response = {}
response['cached_until'] = self.py3.time_in(self.cache_timeout)
try:
output = self.py3.command_output(self.script_path, shell=True, localized=self.localize)
output_lines = output.splitlines()
self.output = self.py3.command_output(self.script_path, shell=True, localized=self.localize)
output_lines = self.output.splitlines()
if len(output_lines) > 1:
output_color = output_lines[1]
if re.search(r'^#[0-9a-fA-F]{6}$', output_color):
Expand Down Expand Up @@ -97,9 +101,15 @@ def external_script(self):
output = ''

response['full_text'] = self.py3.safe_format(
self.format, {'output': output})
self.format, {'output': output, 'lines': len(output_lines)})
return response

def on_click(self, event):
button = event["button"]
if button == self.button_show_notification:
self.py3.notify_user(self.output)
self.py3.prevent_refresh()


if __name__ == "__main__":
"""
Expand Down

0 comments on commit 9865a2e

Please sign in to comment.