mirror of
https://github.com/powerline/powerline.git
synced 2025-07-28 00:04:39 +02:00
Use new functionality to replace tabbuflister and single_tab segment
This commit is contained in:
parent
c5ca1b23c4
commit
54e12b1515
@ -134,4 +134,5 @@ References
|
|||||||
configuration/reference
|
configuration/reference
|
||||||
configuration/segments
|
configuration/segments
|
||||||
configuration/listers
|
configuration/listers
|
||||||
|
configuration/selectors
|
||||||
configuration/local
|
configuration/local
|
||||||
|
17
docs/source/selectors.rst
Normal file
17
docs/source/selectors.rst
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
.. _config-selectors:
|
||||||
|
|
||||||
|
******************
|
||||||
|
Selector functions
|
||||||
|
******************
|
||||||
|
|
||||||
|
Selector functions are functions that return ``True`` or ``False`` depending on
|
||||||
|
application state. They are used for :ref:`exclude_function and include_function
|
||||||
|
segment options <config-themes-seg-exclude_function>`.
|
||||||
|
|
||||||
|
Available selectors
|
||||||
|
===================
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:glob:
|
||||||
|
|
||||||
|
selectors/*
|
6
docs/source/selectors/vim.rst
Normal file
6
docs/source/selectors/vim.rst
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
*************
|
||||||
|
Vim selectors
|
||||||
|
*************
|
||||||
|
|
||||||
|
.. automodule:: powerline.selectors.vim
|
||||||
|
:members:
|
@ -4,18 +4,12 @@
|
|||||||
"left": [
|
"left": [
|
||||||
{
|
{
|
||||||
"type": "segment_list",
|
"type": "segment_list",
|
||||||
"function": "powerline.listers.vim.tabbuflister",
|
"function": "powerline.listers.vim.tablister",
|
||||||
|
"exclude_function": "single_tab",
|
||||||
"segments": [
|
"segments": [
|
||||||
{
|
{
|
||||||
"function": "tabnr",
|
"function": "tabnr",
|
||||||
"after": " ",
|
"after": " ",
|
||||||
"exclude_modes": ["tab", "buf", "buf_nc"],
|
|
||||||
"priority": 5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"function": "bufnr",
|
|
||||||
"after": " ",
|
|
||||||
"exclude_modes": ["tab", "buf", "tab_nc"],
|
|
||||||
"priority": 5
|
"priority": 5
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -31,12 +25,33 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"function": "tab_modified_indicator",
|
"function": "tab_modified_indicator",
|
||||||
"exclude_modes": ["buf", "buf_nc"],
|
"priority": 5
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "segment_list",
|
||||||
|
"function": "powerline.listers.vim.bufferlister",
|
||||||
|
"include_function": "single_tab",
|
||||||
|
"segments": [
|
||||||
|
{
|
||||||
|
"function": "bufnr",
|
||||||
|
"after": " ",
|
||||||
"priority": 5
|
"priority": 5
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"function": "file_directory",
|
||||||
|
"priority": 40
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"function": "file_name",
|
||||||
|
"args": {
|
||||||
|
"display_no_file": true
|
||||||
|
},
|
||||||
|
"priority": 10
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"function": "modified_indicator",
|
"function": "modified_indicator",
|
||||||
"exclude_modes": ["tab", "tab_nc"],
|
|
||||||
"priority": 5
|
"priority": 5
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -51,7 +66,18 @@
|
|||||||
],
|
],
|
||||||
"right": [
|
"right": [
|
||||||
{
|
{
|
||||||
"function": "single_tab"
|
"type": "string",
|
||||||
|
"contents": "Bufs",
|
||||||
|
"name": "single_tab",
|
||||||
|
"highlight_group": ["single_tab"],
|
||||||
|
"include_function": "single_tab"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"contents": "Tabs",
|
||||||
|
"name": "many_tabs",
|
||||||
|
"highlight_group": ["many_tabs"],
|
||||||
|
"exclude_function": "single_tab"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -110,11 +110,3 @@ def bufferlister(pl, segment_info, show_unlisted=False, **kwargs):
|
|||||||
or int(vim_getbufoption(buf_segment_info, 'buflisted'))
|
or int(vim_getbufoption(buf_segment_info, 'buflisted'))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@requires_segment_info
|
|
||||||
def tabbuflister(**kwargs):
|
|
||||||
if len(list_tabpages()) == 1:
|
|
||||||
return bufferlister(**kwargs)
|
|
||||||
else:
|
|
||||||
return tablister(**kwargs)
|
|
||||||
|
@ -14,7 +14,6 @@ except ImportError:
|
|||||||
from powerline.bindings.vim import (vim_get_func, getbufvar, vim_getbufoption,
|
from powerline.bindings.vim import (vim_get_func, getbufvar, vim_getbufoption,
|
||||||
buffer_name, vim_getwinvar,
|
buffer_name, vim_getwinvar,
|
||||||
register_buffer_cache, current_tabpage,
|
register_buffer_cache, current_tabpage,
|
||||||
list_tabpages,
|
|
||||||
list_tabpage_buffers_segment_info)
|
list_tabpage_buffers_segment_info)
|
||||||
from powerline.theme import requires_segment_info, requires_filesystem_watcher
|
from powerline.theme import requires_segment_info, requires_filesystem_watcher
|
||||||
from powerline.lib import add_divider_highlight_group
|
from powerline.lib import add_divider_highlight_group
|
||||||
@ -622,29 +621,3 @@ def winnr(pl, segment_info, show_current=False):
|
|||||||
winnr = segment_info['winnr']
|
winnr = segment_info['winnr']
|
||||||
if show_current or winnr != vim.current.window.number:
|
if show_current or winnr != vim.current.window.number:
|
||||||
return str(winnr)
|
return str(winnr)
|
||||||
|
|
||||||
|
|
||||||
def single_tab(pl, single_text='Bufs', multiple_text='Tabs'):
|
|
||||||
'''Show one text if there is only one tab and another if there are many
|
|
||||||
|
|
||||||
Mostly useful for tabline to indicate what kind of data is shown there.
|
|
||||||
|
|
||||||
:param str single_text:
|
|
||||||
Text displayed when there is only one tabpage. May be None if you do not
|
|
||||||
want to display anything.
|
|
||||||
:param str multiple_text:
|
|
||||||
Text displayed when there is more then one tabpage. May be None if you
|
|
||||||
do not want to display anything.
|
|
||||||
|
|
||||||
Highlight groups used: ``single_tab``, ``many_tabs``.
|
|
||||||
'''
|
|
||||||
if len(list_tabpages()) == 1:
|
|
||||||
return single_text and [{
|
|
||||||
'contents': single_text,
|
|
||||||
'highlight_group': ['single_tab'],
|
|
||||||
}]
|
|
||||||
else:
|
|
||||||
return multiple_text and [{
|
|
||||||
'contents': multiple_text,
|
|
||||||
'highlight_group': ['many_tabs'],
|
|
||||||
}]
|
|
||||||
|
0
powerline/selectors/__init__.py
Normal file
0
powerline/selectors/__init__.py
Normal file
10
powerline/selectors/vim.py
Normal file
10
powerline/selectors/vim.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
from powerline.bindings.vim import list_tabpages
|
||||||
|
|
||||||
|
|
||||||
|
def single_tab(pl, segment_info, mode):
|
||||||
|
'''Returns True if Vim has only one tab opened
|
||||||
|
'''
|
||||||
|
return len(list_tabpages()) == 1
|
@ -1076,19 +1076,6 @@ class TestVim(TestCase):
|
|||||||
self.assertEqual(self.vim.winnr(pl=pl, segment_info=segment_info, show_current=True), str(segment_info['winnr']))
|
self.assertEqual(self.vim.winnr(pl=pl, segment_info=segment_info, show_current=True), str(segment_info['winnr']))
|
||||||
self.assertEqual(self.vim.winnr(pl=pl, segment_info=segment_info, show_current=False), None)
|
self.assertEqual(self.vim.winnr(pl=pl, segment_info=segment_info, show_current=False), None)
|
||||||
|
|
||||||
def test_single_tab(self):
|
|
||||||
pl = Pl()
|
|
||||||
single_tab = partial(vim.single_tab, pl=pl)
|
|
||||||
with vim_module._with('tabpage'):
|
|
||||||
self.assertEqual(single_tab(), [{'highlight_group': ['many_tabs'], 'contents': 'Tabs'}])
|
|
||||||
self.assertEqual(single_tab(single_text='s', multiple_text='m'), [{'highlight_group': ['many_tabs'], 'contents': 'm'}])
|
|
||||||
self.assertEqual(single_tab(multiple_text='m'), [{'highlight_group': ['many_tabs'], 'contents': 'm'}])
|
|
||||||
self.assertEqual(single_tab(single_text='s'), [{'highlight_group': ['many_tabs'], 'contents': 'Tabs'}])
|
|
||||||
self.assertEqual(single_tab(), [{'highlight_group': ['single_tab'], 'contents': 'Bufs'}])
|
|
||||||
self.assertEqual(single_tab(single_text='s', multiple_text='m'), [{'highlight_group': ['single_tab'], 'contents': 's'}])
|
|
||||||
self.assertEqual(single_tab(multiple_text='m'), [{'highlight_group': ['single_tab'], 'contents': 'Bufs'}])
|
|
||||||
self.assertEqual(single_tab(single_text='s'), [{'highlight_group': ['single_tab'], 'contents': 's'}])
|
|
||||||
|
|
||||||
def test_segment_info(self):
|
def test_segment_info(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
with vim_module._with('tabpage'):
|
with vim_module._with('tabpage'):
|
||||||
|
36
tests/test_selectors.py
Normal file
36
tests/test_selectors.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
# vim:fileencoding=utf-8:noet
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
|
import tests.vim as vim_module
|
||||||
|
|
||||||
|
from tests.lib import Pl
|
||||||
|
from tests import TestCase
|
||||||
|
|
||||||
|
|
||||||
|
class TestVim(TestCase):
|
||||||
|
def test_single_tab(self):
|
||||||
|
pl = Pl()
|
||||||
|
single_tab = partial(self.vim.single_tab, pl=pl, segment_info=None, mode=None)
|
||||||
|
with vim_module._with('tabpage'):
|
||||||
|
self.assertEqual(single_tab(), False)
|
||||||
|
self.assertEqual(single_tab(), True)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'path')))
|
||||||
|
from powerline.selectors import vim
|
||||||
|
cls.vim = vim
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDownClass(cls):
|
||||||
|
sys.path.pop(0)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
from tests import main
|
||||||
|
main()
|
Loading…
x
Reference in New Issue
Block a user