diff options
-rw-r--r-- | examples/plugin-test | 6 | ||||
-rw-r--r-- | src/util.py | 13 |
2 files changed, 17 insertions, 2 deletions
diff --git a/examples/plugin-test b/examples/plugin-test index 214449a..db316ee 100644 --- a/examples/plugin-test +++ b/examples/plugin-test @@ -41,7 +41,9 @@ def redraw(): users = ['%s{%i}' % (colour_user(u) % u, len(users_[u])) for u in users_.keys()] users = 'Users: %s' % (' '.join(users)) - text = '%s │ %s │ %s │ %s' - text %= (uptime, idle, loadavg, users) + time = spawn_read('date', '+%Y-(%m)%b-%d %T, %a w%V, %Z') + + text = '%s │ %s │ %s │ %s │ %s' + text %= (time, uptime, idle, loadavg, users) bar.draw_coloured_text(0, 10, 0, 2, text) diff --git a/src/util.py b/src/util.py index 25aac1f..e95c419 100644 --- a/src/util.py +++ b/src/util.py @@ -58,3 +58,16 @@ def spawn(*command): proc = subprocess.Popen(list(command), stderr = sys.stderr, stdout = subprocess.PIPE) return proc.stdout + +def spawn_read(*command): + ''' + Spawn an external process and returns its output + + @param command:*str The command line + @return :str The process's output to stdout, without the final LF + ''' + proc = subprocess.Popen(list(command), stderr = sys.stderr, stdout = subprocess.PIPE) + out = proc.stdout.read().decode('utf-8', 'replace') + if out.endswith('\n'): + out = out[:-1] + return out |