3.11: Add test command, invoke like this: i3pystatus test
This commit is contained in:
parent
c8c8e2226f
commit
7dfac95f1e
@ -2,11 +2,13 @@
|
||||
|
||||
import sys
|
||||
import threading
|
||||
import os
|
||||
|
||||
from .core import util, io
|
||||
from .core.modules import Module, AsyncModule, IntervalModule, START_HOOKS
|
||||
from .core.settings import SettingsBase
|
||||
from .core.config import ConfigFinder
|
||||
from .core.render import render_json
|
||||
|
||||
__all__ = [
|
||||
"SettingsBase",
|
||||
@ -14,9 +16,6 @@ __all__ = [
|
||||
"Status", "I3statusHandler",
|
||||
]
|
||||
|
||||
def main():
|
||||
ConfigFinder().run_config()
|
||||
|
||||
class Status:
|
||||
def __init__(self, standalone=False, interval=1, input_stream=sys.stdin):
|
||||
self.standalone = standalone
|
||||
@ -37,11 +36,11 @@ class Status:
|
||||
self.modules.append(module, *args, **kwargs)
|
||||
|
||||
def run_command_endpoint(self):
|
||||
for j in io.JSONIO(io=io.IOHandler(sys.stdin, io.DevNull()), skiplines=1).read():
|
||||
if j["command"] == "block_clicked":
|
||||
module = self.modules.get_by_id(j["instance"])
|
||||
for command in io.JSONIO(io=io.IOHandler(sys.stdin, open(os.devnull,"w")), skiplines=1).read():
|
||||
if command["command"] == "block_clicked":
|
||||
module = self.modules.get_by_id(command["instance"])
|
||||
if module:
|
||||
module.on_click(j["button"])
|
||||
module.on_click(command["button"])
|
||||
|
||||
def call_start_hooks(self):
|
||||
for hook in START_HOOKS:
|
||||
@ -53,3 +52,34 @@ class Status:
|
||||
for module in self.modules:
|
||||
module.inject(j)
|
||||
I3statusHandler = Status
|
||||
|
||||
def run_config():
|
||||
ConfigFinder().run_config()
|
||||
|
||||
def test_setup():
|
||||
import i3pystatus
|
||||
class TestStatus(Status):
|
||||
def run(self):
|
||||
self.call_start_hooks()
|
||||
for module in self.modules:
|
||||
|
||||
sys.stdout.write("{module}: ".format(module=module.__name__))
|
||||
sys.stdout.flush()
|
||||
module.run()
|
||||
output = module.output or {"full_text": "(no output)"}
|
||||
print(render_json(output))
|
||||
|
||||
i3pystatus.Status = TestStatus
|
||||
|
||||
def test_config():
|
||||
test_setup()
|
||||
cf = ConfigFinder()
|
||||
print("Using configuration file {file}".format(file=cf.get_config_path()[1]))
|
||||
print("Output, would be displayed right to left in i3bar")
|
||||
cf.run_config()
|
||||
|
||||
def main():
|
||||
if len(sys.argv) == 2 and sys.argv[1] == "test":
|
||||
test_config()
|
||||
else:
|
||||
run_config()
|
||||
|
@ -4,11 +4,6 @@ import json
|
||||
import sys
|
||||
import threading
|
||||
from contextlib import contextmanager
|
||||
import io
|
||||
|
||||
class DevNull(io.TextIOBase):
|
||||
def write(self, string):
|
||||
pass
|
||||
|
||||
class IOHandler:
|
||||
def __init__(self, inp=sys.stdin, out=sys.stdout):
|
||||
@ -56,7 +51,7 @@ class StandaloneIO(IOHandler):
|
||||
"""
|
||||
|
||||
n = -1
|
||||
proto = ('{"version":1,"bidirectional":1}', "[", "[]", ",[]", )
|
||||
proto = ('{"version":1,"bidirectional":true}', "[", "[]", ",[]", )
|
||||
|
||||
def __init__(self, interval=1):
|
||||
super().__init__()
|
||||
|
6
i3pystatus/core/render.py
Normal file
6
i3pystatus/core/render.py
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
def render_json(json):
|
||||
if not json.get("full_text", ""):
|
||||
return ""
|
||||
|
||||
return json["full_text"]
|
Loading…
Reference in New Issue
Block a user