A simple replacement for i3status that is both extensible and customizable.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.4 KiB

#!/usr/bin/python3
import argparse
import importlib
import json
import os
import sys
import time
import yaml
DEFAULT_CONFIG = os.path.join(os.environ['HOME'], '.config/vdstatus/conf.yaml')
DEFAULTS = {
'output_format': 'term',
'output_freq': 1,
'plugins': [{'name': 'date'}]
}
def parse_arguments():
desc = ('A simple i3status replacement, '
'and more. Warning: WIP, may be broken.')
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('-c', '--conf', default=DEFAULT_CONFIG,
help='configuration file')
return parser.parse_args()
class PluginRunner:
def __init__(self, config_file=DEFAULT_CONFIG):
self.conf = dict()
self.conf.update(DEFAULTS)
with open(config_file) as config_data:
self.conf.update(yaml.safe_load(config_data))
self.plugins_loaded = list()
self.format_output = self.format_term
for plugin in self.conf['plugins']:
mod = importlib.import_module('.' + plugin['name'], 'plugins')
thread_object = mod.PluginThread(plugin)
self.plugins_loaded.append(thread_object)
def start(self):
if self.conf['output_format'] == 'i3':
print('{"version":1}\n[', flush=True)
self.format_output = self.format_i3wm
for plugin in self.plugins_loaded:
plugin.start()
def query(self):
outputs = list()
for plugin in self.plugins_loaded:
if \
'full_text' in plugin.status and (
not plugin.conf['hide_ok'] or not plugin.hide
):
outputs.append(plugin.status)
print(self.format_output(outputs), flush=True)
def run(self):
while True:
try:
self.query()
time.sleep(self.conf['output_freq'])
except (KeyboardInterrupt, SystemExit):
sys.exit()
@staticmethod
def format_i3wm(inputs):
return json.dumps(inputs, ensure_ascii=False) + ','
@staticmethod
def format_term(inputs):
return_info = list()
for item in inputs:
return_info.append(item['full_text'])
return ' \033[1m|\033[0m '.join(return_info)
def main():
args = parse_arguments()
plugin_runner = PluginRunner(args.conf)
plugin_runner.start()
time.sleep(0.1)
plugin_runner.run()
if __name__ == '__main__':
main()