Add BAR (bar ain't recursive) renderer and fitting i3 bindings

This commit is contained in:
S0lll0s 2015-01-08 00:03:34 +01:00 committed by ZyX
parent 9dfd40a6a7
commit dd77d420a3
4 changed files with 144 additions and 3 deletions

View File

@ -44,13 +44,30 @@ Add the following to :file:`~/.config/qtile/config.py`:
),
]
.. _bar-usage:
LemonBoys bar
=============
To run the bar simply pipe the output of the binding script into ``bar`` and specify appropriate
options, for example like this::
python powerline-bar.py | bar -f "-xos4-*"
to run with i3, simply ``exec`` this in i3 config file::
exec python powerline-bar.py | bar -f "-xos4-*"
See the `bar documentation <https://github.com/LemonBoy/bar>`_ for more information and options.
I3 bar
======
.. note::
Until the patch is done in i3 a custom ``i3bar`` build called ``i3bgbar`` is
needed. The source is available `in S0lll0s/i3bgbar github repository
<https://github.com/S0lll0s/i3bgbar>`_.
As the patch to include background-colors in i3bar is likely not to be
merged, it is recommended to instead run ``bar`` (see above). The source for
i3bgbar is however still available `here
<https://github.com/S0lll0s/i3bgbar>`_.
Add the following to :file:`~/.i3/config`::

View File

@ -0,0 +1,42 @@
#!/usr/bin/env python
# vim:fileencoding=utf-8:noet
from __future__ import (unicode_literals, division, absolute_import, print_function)
import sys
import time
import i3
from threading import Lock
from powerline import Powerline
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' )
powerline.update_renderer()
interval = 0.5
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):
global lock
with lock:
ln = '%{l}'
ln += powerline.render(side='left')
ln += '%{r}'
ln += powerline.render(side='right')
print( encode(ln) )
sys.stdout.flush()
sub = i3.Subscription(render, 'workspace')
while True:
start_time = monotonic()
render()
time.sleep(max(interval - (monotonic() - start_time), 0.1))

View File

@ -0,0 +1,39 @@
# vim:fileencoding=utf-8:noet
from __future__ import (unicode_literals, division, absolute_import, print_function)
from powerline.renderer import Renderer
from powerline.colorscheme import ATTR_BOLD, ATTR_ITALIC, ATTR_UNDERLINE
class BarRenderer(Renderer):
'''bar (bar ain't recursive) renderer
See documentation of `bar <https://github.com/LemonBoy/bar>`_ and :ref:`the usage instructions <bar-usage>`
'''
character_translations = Renderer.character_translations.copy()
character_translations[ord('%')] = '%%'
@staticmethod
def hlstyle(*args, **kwargs):
# We dont need to explicitly reset attributes, so skip those calls
return ''
def hl(self, contents, fg=None, bg=None, attrs=None):
text = ''
if fg is not None:
if fg is not False and fg[1] is not False:
text += '%{{F#ff{0:06x}}}'.format(fg[1])
if bg is not None:
if bg is not False and bg[1] is not False:
text += '%{{B#ff{0:06x}}}'.format(bg[1])
if attrs & ATTR_UNDERLINE:
text += '%{+u}'
return text + contents + '%{F-B--u}'
renderer = BarRenderer

View File

@ -43,6 +43,10 @@ config = {
'theme': 'default',
'colorscheme': 'default',
},
'wm': {
'theme': 'default',
'colorscheme': 'default',
},
},
},
'colors': {
@ -91,6 +95,14 @@ config = {
'environment': {'fg': 'col3', 'bg': 'col4', 'attrs': ['underline']},
},
},
'colorschemes/wm/default': {
'groups': {
'hl1': {'fg': 'col1', 'bg': 'col2', 'attrs': ['underline']},
'hl2': {'fg': 'col2', 'bg': 'col1', 'attrs': []},
'hl3': {'fg': 'col3', 'bg': 'col1', 'attrs': ['underline']},
'hl4': {'fg': 'col2', 'bg': 'col4', 'attrs': []},
},
},
'themes/test/default': {
'segments': {
'left': [
@ -142,6 +154,19 @@ config = {
],
},
},
'themes/wm/default': {
'default_module': 'powerline.segments.common',
'segments': {
'left': [
highlighted_string('A', 'hl1'),
highlighted_string('B', 'hl2'),
],
'right': [
highlighted_string('C', 'hl3'),
highlighted_string('D', 'hl4'),
],
},
},
}
@ -799,6 +824,24 @@ class TestVim(TestCase):
def tearDownClass(cls):
sys.path.pop(0)
class TestBar(TestCase):
def test_bar(self):
import powerline as powerline_module
with swap_attributes(config, powerline_module):
with get_powerline_raw(config, powerline_module, ext='wm', renderer_module='bar') as powerline:
self.assertEqual("%{{l}}{}%{{r}}{}".format(powerline.render(side='left'), powerline.render(side='right')), "SOME_STRING_HERE")
def test_bar_escape(self):
from powerline.shell import ShellPowerline
import powerline as powerline_module
config['themes/wm/default']['segments']['left'] = {
highlighted_string('%{asd}', 'hl1'),
highlighted_string('10% %', 'hl2'),
}
with swap_attributes(config, powerline_module):
with get_powerline_raw(config, powerline_module, ext='wm', renderer_module='bar') as powerline:
self.assertEqual(powerline.render(side='left'), "SOME_STRING_HERE")
if __name__ == '__main__':
from tests import main