[output/i3bar] Add flush method

flush() terminates a single iteration of widget drawing.

see #23
This commit is contained in:
Tobi-wan Kenobi 2016-12-04 16:14:43 +01:00
parent 712d958e18
commit b6eb3ee8e6
6 changed files with 20 additions and 2 deletions

View file

@ -3,11 +3,14 @@
import sys import sys
import bumblebee.engine import bumblebee.engine
import bumblebee.config import bumblebee.config
import bumblebee.output
def main(): def main():
config = bumblebee.config.Config(sys.argv[1:]) config = bumblebee.config.Config(sys.argv[1:])
output = bumblebee.output.I3BarOutput()
engine = bumblebee.engine.Engine( engine = bumblebee.engine.Engine(
config=config config=config,
output=output,
) )
engine.run() engine.run()

View file

@ -52,6 +52,7 @@ class Engine(object):
for module in self._modules: for module in self._modules:
widgets += module.widgets() widgets += module.widgets()
self._output.draw(widgets) self._output.draw(widgets)
self._output.flush()
self._output.stop() self._output.stop()

View file

@ -8,4 +8,7 @@ class Module(bumblebee.engine.Module):
def __init__(self, engine): def __init__(self, engine):
super(Module, self).__init__(engine) super(Module, self).__init__(engine)
def widgets(self):
return []
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -29,4 +29,9 @@ class I3BarOutput(object):
}) })
sys.stdout.write(json.dumps(result)) sys.stdout.write(json.dumps(result))
def flush(self):
"""Flushes output"""
sys.stdout.write(",\n")
sys.stdout.flush()
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh
find . -name "*.py"|xargs pylint --disable=R0903 find . -name "*.py"|xargs pylint --disable=R0903,R0201

View file

@ -41,4 +41,10 @@ class TestI3BarOutput(unittest.TestCase):
for res in result: for res in result:
self.assertEquals(res["full_text"], self.someWidget.text()) self.assertEquals(res["full_text"], self.someWidget.text())
@mock.patch("sys.stdout", new_callable=StringIO)
def test_flush(self, stdout):
self.output.flush()
self.assertEquals(",\n", stdout.getvalue())
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4