Fix issues found in 1256 pull request

Ref #1256
This commit is contained in:
ZyX 2015-01-25 12:51:19 +03:00
parent dd77d420a3
commit 1e7dc7900d
4 changed files with 48 additions and 35 deletions

View File

@ -47,18 +47,19 @@ Add the following to :file:`~/.config/qtile/config.py`:
.. _bar-usage: .. _bar-usage:
LemonBoys bar LemonBoys bar
============= ==============
To run the bar simply pipe the output of the binding script into ``bar`` and specify appropriate To run the bar simply pipe the output of the binding script into ``bar`` and
options, for example like this:: specify appropriate options, for example like this::
python powerline-bar.py | bar -f "-xos4-*" python /path/to/powerline/bindings/bar/powerline-bar.py | bar
to run with i3, simply ``exec`` this in i3 config file:: to run with i3, simply ``exec`` this in i3 config file::
exec python powerline-bar.py | bar -f "-xos4-*" exec python /path/to/powerline/bindings/bar/powerline-bar.py --i3 | bar
See the `bar documentation <https://github.com/LemonBoy/bar>`_ for more information and options. See the `bar documentation <https://github.com/LemonBoy/bar>`_ for more
information and options.
I3 bar I3 bar
====== ======

View File

@ -4,38 +4,37 @@ from __future__ import (unicode_literals, division, absolute_import, print_funct
import sys import sys
import time import time
import i3
from threading import Lock from threading import Lock
from argparse import ArgumentParser
from powerline import Powerline from powerline import Powerline
from powerline.lib.monotonic import monotonic from powerline.lib.monotonic import monotonic
if __name__ == '__main__':
name = 'wm'
if len(sys.argv) > 1:
name = sys.argv[1]
powerline = Powerline( name, renderer_module='bar' ) if __name__ == '__main__':
parser = ArgumentParser(description='Powerline BAR bindings.')
parser.add_argument(
'--i3', action='store_true',
help='Subscribe for i3 events.'
)
args = parser.parse_args()
powerline = Powerline('wm', renderer_module='bar')
powerline.update_renderer() powerline.update_renderer()
interval = 0.5 interval = 0.5
lock = Lock() lock = Lock()
def encode( str ): return str.encode('utf-8')
if sys.version_info > (3,0):
def encode( str ): return str
def render(event=None, data=None, sub=None): def render(event=None, data=None, sub=None):
global lock global lock
with lock: with lock:
ln = '%{l}' print(powerline.render())
ln += powerline.render(side='left')
ln += '%{r}'
ln += powerline.render(side='right')
print( encode(ln) )
sys.stdout.flush() sys.stdout.flush()
sub = i3.Subscription(render, 'workspace') if args.i3:
import i3
sub = i3.Subscription(render, 'workspace')
while True: while True:
start_time = monotonic() start_time = monotonic()
render() render()

View File

@ -2,7 +2,7 @@
from __future__ import (unicode_literals, division, absolute_import, print_function) from __future__ import (unicode_literals, division, absolute_import, print_function)
from powerline.renderer import Renderer from powerline.renderer import Renderer
from powerline.colorscheme import ATTR_BOLD, ATTR_ITALIC, ATTR_UNDERLINE from powerline.colorscheme import ATTR_UNDERLINE
class BarRenderer(Renderer): class BarRenderer(Renderer):
@ -25,15 +25,21 @@ class BarRenderer(Renderer):
if fg is not None: if fg is not None:
if fg is not False and fg[1] is not False: if fg is not False and fg[1] is not False:
text += '%{{F#ff{0:06x}}}'.format(fg[1]) text += '%{{F#ff{0:06x}}}'.format(fg[1])
if bg is not None: if bg is not None:
if bg is not False and bg[1] is not False: if bg is not False and bg[1] is not False:
text += '%{{B#ff{0:06x}}}'.format(bg[1]) text += '%{{B#ff{0:06x}}}'.format(bg[1])
if attrs & ATTR_UNDERLINE: if attrs & ATTR_UNDERLINE:
text += '%{+u}' text += '%{+u}'
return text + contents + '%{F-B--u}' return text + contents + '%{F-B--u}'
def render(self):
return '%{{l}}{0}%{{r}}{1}'.format(
super(BarRenderer, self).render(side='left'),
super(BarRenderer, self).render(side='right'),
)
renderer = BarRenderer renderer = BarRenderer

View File

@ -824,23 +824,30 @@ class TestVim(TestCase):
def tearDownClass(cls): def tearDownClass(cls):
sys.path.pop(0) sys.path.pop(0)
class TestBar(TestCase):
class TestBar(TestRender):
def test_bar(self): def test_bar(self):
import powerline as powerline_module import powerline as powerline_module
with swap_attributes(config, powerline_module): with swap_attributes(config, powerline_module):
with get_powerline_raw(config, powerline_module, ext='wm', renderer_module='bar') as powerline: with get_powerline_raw(config, powerline_module.Powerline, replace_gcp=True, ext='wm', renderer_module='bar') as powerline:
self.assertEqual("%{{l}}{}%{{r}}{}".format(powerline.render(side='left'), powerline.render(side='right')), "SOME_STRING_HERE") self.assertRenderEqual(
powerline,
'%{l}%{F#ffc00000}%{B#ff008000}%{+u} A%{F-B--u}%{F#ff008000}%{B#ffc00000}>>%{F-B--u}%{F#ff008000}%{B#ffc00000}B%{F-B--u}%{F#ffc00000}>>%{F-B--u}%{r}%{F#ffc00000}<<%{F-B--u}%{F#ff804000}%{B#ffc00000}%{+u}C%{F-B--u}%{F#ff0000c0}%{B#ffc00000}<<%{F-B--u}%{F#ff008000}%{B#ff0000c0}D %{F-B--u}'
)
def test_bar_escape(self): @with_new_config
from powerline.shell import ShellPowerline def test_bar_escape(self, config):
import powerline as powerline_module import powerline as powerline_module
config['themes/wm/default']['segments']['left'] = { config['themes/wm/default']['segments']['left'] = (
highlighted_string('%{asd}', 'hl1'), highlighted_string('%{asd}', 'hl1'),
highlighted_string('10% %', 'hl2'), highlighted_string('10% %', 'hl2'),
} )
with swap_attributes(config, powerline_module): with swap_attributes(config, powerline_module):
with get_powerline_raw(config, powerline_module, ext='wm', renderer_module='bar') as powerline: with get_powerline_raw(config, powerline_module.Powerline, replace_gcp=True, ext='wm', renderer_module='bar') as powerline:
self.assertEqual(powerline.render(side='left'), "SOME_STRING_HERE") self.assertRenderEqual(
powerline,
'%{l}%{F#ffc00000}%{B#ff008000}%{+u} %%{asd}%{F-B--u}%{F#ff008000}%{B#ffc00000}>>%{F-B--u}%{F#ff008000}%{B#ffc00000}10%% %%%{F-B--u}%{F#ffc00000}>>%{F-B--u}%{r}%{F#ffc00000}<<%{F-B--u}%{F#ff804000}%{B#ffc00000}%{+u}C%{F-B--u}%{F#ff0000c0}%{B#ffc00000}<<%{F-B--u}%{F#ff008000}%{B#ff0000c0}D %{F-B--u}'
)
if __name__ == '__main__': if __name__ == '__main__':