summaryrefslogtreecommitdiffstats
path: root/powerline/listers
diff options
context:
space:
mode:
Diffstat (limited to 'powerline/listers')
-rw-r--r--powerline/listers/__init__.py0
-rw-r--r--powerline/listers/i3wm.py63
-rw-r--r--powerline/listers/pdb.py37
-rw-r--r--powerline/listers/vim.py123
4 files changed, 223 insertions, 0 deletions
diff --git a/powerline/listers/__init__.py b/powerline/listers/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/powerline/listers/__init__.py
diff --git a/powerline/listers/i3wm.py b/powerline/listers/i3wm.py
new file mode 100644
index 0000000..9224d16
--- /dev/null
+++ b/powerline/listers/i3wm.py
@@ -0,0 +1,63 @@
+# vim:fileencoding=utf-8:noet
+from __future__ import (unicode_literals, division, absolute_import, print_function)
+
+from powerline.theme import requires_segment_info
+from powerline.lib.dict import updated
+from powerline.bindings.wm import get_i3_connection, get_connected_xrandr_outputs
+
+
+@requires_segment_info
+def output_lister(pl, segment_info):
+ '''List all outputs in segment_info format
+ '''
+
+ return (
+ (
+ updated(segment_info, output=output['name']),
+ {
+ 'draw_inner_divider': None
+ }
+ )
+ for output in get_connected_xrandr_outputs(pl)
+ )
+
+
+@requires_segment_info
+def workspace_lister(pl, segment_info, only_show=None, output=None):
+ '''List all workspaces in segment_info format
+
+ Sets the segment info values of ``workspace`` and ``output`` to the name of
+ the i3 workspace and the ``xrandr`` output respectively and the keys
+ ``"visible"``, ``"urgent"`` and ``"focused"`` to a boolean indicating these
+ states.
+
+ :param list only_show:
+ Specifies which workspaces to list. Valid entries are ``"visible"``,
+ ``"urgent"`` and ``"focused"``. If omitted or ``null`` all workspaces
+ are listed.
+
+ :param str output:
+ May be set to the name of an X output. If specified, only workspaces
+ on that output are listed. Overrides automatic output detection by
+ the lemonbar renderer and bindings. Set to ``false`` to force
+ all workspaces to be shown.
+ '''
+
+ if output == None:
+ output = output or segment_info.get('output')
+
+ return (
+ (
+ updated(
+ segment_info,
+ output=w.output,
+ workspace=w,
+ ),
+ {
+ 'draw_inner_divider': None
+ }
+ )
+ for w in get_i3_connection().get_workspaces()
+ if (((not only_show or any(getattr(w, typ) for typ in only_show))
+ and (not output or w.output == output)))
+ )
diff --git a/powerline/listers/pdb.py b/powerline/listers/pdb.py
new file mode 100644
index 0000000..24e11ea
--- /dev/null
+++ b/powerline/listers/pdb.py
@@ -0,0 +1,37 @@
+# vim:fileencoding=utf-8:noet
+from __future__ import (unicode_literals, division, absolute_import, print_function)
+
+from powerline.theme import requires_segment_info
+
+
+@requires_segment_info
+def frame_lister(pl, segment_info, full_stack=False, maxframes=3):
+ '''List all frames in segment_info format
+
+ :param bool full_stack:
+ If true, then all frames in the stack are listed. Normally N first
+ frames are discarded where N is a number of frames present at the first
+ invocation of the prompt minus one.
+ :param int maxframes:
+ Maximum number of frames to display.
+ '''
+ if full_stack:
+ initial_stack_length = 0
+ frames = segment_info['pdb'].stack
+ else:
+ initial_stack_length = segment_info['initial_stack_length']
+ frames = segment_info['pdb'].stack[initial_stack_length:]
+
+ if len(frames) > maxframes:
+ frames = frames[-maxframes:]
+
+ return (
+ (
+ {
+ 'curframe': frame[0],
+ 'initial_stack_length': initial_stack_length,
+ },
+ {}
+ )
+ for frame in frames
+ )
diff --git a/powerline/listers/vim.py b/powerline/listers/vim.py
new file mode 100644
index 0000000..583e0d3
--- /dev/null
+++ b/powerline/listers/vim.py
@@ -0,0 +1,123 @@
+# vim:fileencoding=utf-8:noet
+from __future__ import (unicode_literals, division, absolute_import, print_function)
+
+from powerline.theme import requires_segment_info
+from powerline.bindings.vim import (current_tabpage, list_tabpages)
+
+try:
+ import vim
+except ImportError:
+ vim = object()
+
+
+def tabpage_updated_segment_info(segment_info, tabpage):
+ segment_info = segment_info.copy()
+ window = tabpage.window
+ buffer = window.buffer
+ segment_info.update(
+ tabpage=tabpage,
+ tabnr=tabpage.number,
+ window=window,
+ winnr=window.number,
+ window_id=int(window.vars.get('powerline_window_id', -1)),
+ buffer=buffer,
+ bufnr=buffer.number,
+ )
+ return segment_info
+
+
+@requires_segment_info
+def tablister(pl, segment_info, **kwargs):
+ '''List all tab pages in segment_info format
+
+ Specifically generates a list of segment info dictionaries with ``window``,
+ ``winnr``, ``window_id``, ``buffer`` and ``bufnr`` keys set to tab-local
+ ones and additional ``tabpage`` and ``tabnr`` keys.
+
+ Adds either ``tab:`` or ``tab_nc:`` prefix to all segment highlight groups.
+
+ Works best with vim-7.4 or later: earlier versions miss tabpage object and
+ thus window objects are not available as well.
+ '''
+ cur_tabpage = current_tabpage()
+ cur_tabnr = cur_tabpage.number
+
+ def add_multiplier(tabpage, dct):
+ dct['priority_multiplier'] = 1 + (0.001 * abs(tabpage.number - cur_tabnr))
+ return dct
+
+ return (
+ (lambda tabpage, prefix: (
+ tabpage_updated_segment_info(segment_info, tabpage),
+ add_multiplier(tabpage, {
+ 'highlight_group_prefix': prefix,
+ 'divider_highlight_group': 'tab:divider'
+ })
+ ))(tabpage, 'tab' if tabpage == cur_tabpage else 'tab_nc')
+ for tabpage in list_tabpages()
+ )
+
+
+def buffer_updated_segment_info(segment_info, buffer):
+ segment_info = segment_info.copy()
+ segment_info.update(
+ window=None,
+ winnr=None,
+ window_id=None,
+ buffer=buffer,
+ bufnr=buffer.number,
+ )
+ return segment_info
+
+
+@requires_segment_info
+def bufferlister(pl, segment_info, show_unlisted=False, **kwargs):
+ '''List all buffers in segment_info format
+
+ Specifically generates a list of segment info dictionaries with ``buffer``
+ and ``bufnr`` keys set to buffer-specific ones, ``window``, ``winnr`` and
+ ``window_id`` keys set to None.
+
+ Adds one of ``buf:``, ``buf_nc:``, ``buf_mod:``, or ``buf_nc_mod``
+ prefix to all segment highlight groups.
+
+ :param bool show_unlisted:
+ True if unlisted buffers should be shown as well. Current buffer is
+ always shown.
+ '''
+ cur_buffer = vim.current.buffer
+ cur_bufnr = cur_buffer.number
+
+ def add_multiplier(buffer, dct):
+ dct['priority_multiplier'] = 1 + (0.001 * abs(buffer.number - cur_bufnr))
+ return dct
+
+ return (
+ (lambda buffer, current, modified: (
+ buffer_updated_segment_info(segment_info, buffer),
+ add_multiplier(buffer, {
+ 'highlight_group_prefix': '{0}{1}'.format(current, modified),
+ 'divider_highlight_group': 'tab:divider'
+ })
+ ))(
+ buffer,
+ 'buf' if buffer is cur_buffer else 'buf_nc',
+ '_mod' if int(vim.eval('getbufvar({0}, \'&modified\')'.format(buffer.number))) > 0 else ''
+ )
+ for buffer in vim.buffers if (
+ buffer is cur_buffer
+ or show_unlisted
+ # We can't use vim_getbufoption(segment_info, 'buflisted')
+ # here for performance reasons. Querying the buffer options
+ # through the vim python module's option attribute caused
+ # vim to think it needed to update the tabline for every
+ # keystroke after any event that changed the buffer's
+ # options.
+ #
+ # Using the vim module's eval method to directly use the
+ # buflisted(nr) vim method instead does not cause vim to
+ # update the tabline after every keystroke, but rather after
+ # events that would change that status. Fixes #1281
+ or int(vim.eval('buflisted(%s)' % buffer.number)) > 0
+ )
+ )