mirror of
https://github.com/powerline/powerline.git
synced 2025-09-23 18:08:52 +02:00
Merge pull request #1058 from ZyX-I/tabline-fixes
Improve tabline support
This commit is contained in:
commit
766efe3754
@ -108,7 +108,7 @@ segments that you may want to customize right away:
|
|||||||
The weather segment will try to find your location using a GeoIP lookup,
|
The weather segment will try to find your location using a GeoIP lookup,
|
||||||
so unless you're on a VPN you probably won't have to change the location
|
so unless you're on a VPN you probably won't have to change the location
|
||||||
query.
|
query.
|
||||||
|
|
||||||
If you want to change the location query or the temperature unit you'll
|
If you want to change the location query or the temperature unit you'll
|
||||||
have to update the segment arguments. Open a theme file, scroll down to
|
have to update the segment arguments. Open a theme file, scroll down to
|
||||||
the weather segment and update it to include unit/location query
|
the weather segment and update it to include unit/location query
|
||||||
@ -134,4 +134,5 @@ References
|
|||||||
configuration/reference
|
configuration/reference
|
||||||
configuration/segments
|
configuration/segments
|
||||||
configuration/listers
|
configuration/listers
|
||||||
|
configuration/selectors
|
||||||
configuration/local
|
configuration/local
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
.. _config-listers:
|
||||||
|
|
||||||
****************
|
****************
|
||||||
Lister reference
|
Lister reference
|
||||||
****************
|
****************
|
||||||
|
@ -380,6 +380,9 @@ ascii Theme without any unicode characters at all
|
|||||||
The segment contents is the return value of the function defined in
|
The segment contents is the return value of the function defined in
|
||||||
the :ref:`function option <config-themes-seg-function>`.
|
the :ref:`function option <config-themes-seg-function>`.
|
||||||
|
|
||||||
|
List of function segments is available in :ref:`Segment reference
|
||||||
|
<config-segments>` section.
|
||||||
|
|
||||||
``string``
|
``string``
|
||||||
A static string segment where the contents is defined in the
|
A static string segment where the contents is defined in the
|
||||||
:ref:`contents option <config-themes-seg-contents>`, and the
|
:ref:`contents option <config-themes-seg-contents>`, and the
|
||||||
@ -392,6 +395,9 @@ ascii Theme without any unicode characters at all
|
|||||||
<config-themes-seg-segments>` and :ref:`args
|
<config-themes-seg-segments>` and :ref:`args
|
||||||
<config-themes-seg-args>` options.
|
<config-themes-seg-args>` options.
|
||||||
|
|
||||||
|
List of lister segments is available in :ref:`Lister reference
|
||||||
|
<config-lister>` section.
|
||||||
|
|
||||||
.. _config-themes-seg-name:
|
.. _config-themes-seg-name:
|
||||||
|
|
||||||
``name``
|
``name``
|
||||||
@ -493,13 +499,31 @@ ascii Theme without any unicode characters at all
|
|||||||
|
|
||||||
.. _config-themes-seg-exclude_modes:
|
.. _config-themes-seg-exclude_modes:
|
||||||
|
|
||||||
``exclude_modes``
|
``exclude_modes``, ``include_modes``
|
||||||
A list of modes where this segment will be excluded: The segment is
|
A list of modes where this segment will be excluded: the segment is not
|
||||||
included in all modes, *except* for the modes in this list.
|
included or is included in all modes, *except* for the modes in one of
|
||||||
|
these lists respectively. If ``exclude_modes`` is not present then it
|
||||||
|
acts like an empty list (segment is not excluded from any modes).
|
||||||
|
Without ``include_modes`` it acts like a list with all possible modes
|
||||||
|
(segment is included in all modes). When there are both
|
||||||
|
``exclude_modes`` overrides ``include_modes``.
|
||||||
|
|
||||||
``include_modes``
|
.. _config-themes-seg-exclude_function:
|
||||||
A list of modes where this segment will be included: The segment is
|
|
||||||
*not* included in any modes, *except* for the modes in this list.
|
``exclude_function``, ``include_function``
|
||||||
|
Function name in a form ``{name}`` or ``{module}.{name}`` (in the first
|
||||||
|
form ``{module}`` defaults to ``powerline.selectors.{ext}``). Determines
|
||||||
|
under which condition specific segment will be included or excluded. By
|
||||||
|
default segment is always included and never excluded.
|
||||||
|
``exclude_function`` overrides ``include_function``.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
Options :ref:`exclude_/include_modes
|
||||||
|
<config-themes-seg-exclude_modes>` complement
|
||||||
|
``exclude_/include_functions``: segment will be included if it is
|
||||||
|
included by either ``include_mode`` or ``include_function`` and will
|
||||||
|
be excluded if it is excluded by either ``exclude_mode`` or
|
||||||
|
``exclude_function``.
|
||||||
|
|
||||||
.. _config-themes-seg-display:
|
.. _config-themes-seg-display:
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
.. _config-segments:
|
||||||
|
|
||||||
*****************
|
*****************
|
||||||
Segment reference
|
Segment reference
|
||||||
*****************
|
*****************
|
||||||
|
@ -40,11 +40,6 @@ resulting segment. In addition to :ref:`usual keys that describe segment
|
|||||||
<dev-segments-segment>` the following keys may be present (it is advised that
|
<dev-segments-segment>` the following keys may be present (it is advised that
|
||||||
*only* the following keys will be used):
|
*only* the following keys will be used):
|
||||||
|
|
||||||
.. _dev-listers-mode:
|
|
||||||
|
|
||||||
``mode``
|
|
||||||
Segment-specific mode. Used to alter segment highlighting.
|
|
||||||
|
|
||||||
``priority_multiplier``
|
``priority_multiplier``
|
||||||
Value (usually a ``float``) used to multiply segment priority. It is useful
|
Value (usually a ``float``) used to multiply segment priority. It is useful
|
||||||
for finer-grained controlling which segments disappear first: e.g. when
|
for finer-grained controlling which segments disappear first: e.g. when
|
||||||
|
@ -228,6 +228,12 @@ Segment dictionary contains the following keys:
|
|||||||
``highlight_group``, ``divider_highlight_group``
|
``highlight_group``, ``divider_highlight_group``
|
||||||
Used highlight groups. May be ``None``.
|
Used highlight groups. May be ``None``.
|
||||||
|
|
||||||
|
``highlight_group_prefix``
|
||||||
|
If this key is present then given prefix will be prepended to each highlight
|
||||||
|
group (both regular and divider) used by this segment in a form
|
||||||
|
``{prefix}:{group}`` (note the colon). This key is mostly useful for
|
||||||
|
:ref:`segment listers <dev-listers>`.
|
||||||
|
|
||||||
.. _dev-segments-seg-around:
|
.. _dev-segments-seg-around:
|
||||||
|
|
||||||
``before``, ``after``
|
``before``, ``after``
|
||||||
@ -254,9 +260,15 @@ Segment dictionary contains the following keys:
|
|||||||
``side``
|
``side``
|
||||||
Segment side: ``right`` or ``left``.
|
Segment side: ``right`` or ``left``.
|
||||||
|
|
||||||
``exclude_modes``, ``include_modes``
|
``display_condition```
|
||||||
:ref:`Mode display control lists <config-themes-seg-exclude_modes>`. May be
|
Contains function that takes three position parameters:
|
||||||
empty, but may not be ``None``.
|
:py:class:`powerline.PowerlineLogger` instance, :ref:`segment_info
|
||||||
|
<dev-segments-info>` dictionary and current mode and returns either ``True``
|
||||||
|
or ``False`` to indicate whether particular segment should be processed.
|
||||||
|
|
||||||
|
This key is constructed based on :ref:`exclude_/include_modes keys
|
||||||
|
<config-themes-seg-exclude_modes>` and :ref:`exclude_/include_function keys
|
||||||
|
<config-themes-seg-exclude_function>`.
|
||||||
|
|
||||||
``width``, ``align``
|
``width``, ``align``
|
||||||
:ref:`Width and align options <config-themes-seg-align>`. May be ``None``.
|
:ref:`Width and align options <config-themes-seg-align>`. May be ``None``.
|
||||||
@ -275,9 +287,6 @@ Segment dictionary contains the following keys:
|
|||||||
``shutdown``
|
``shutdown``
|
||||||
:ref:`Shutdown function <dev-segments-shutdown>`. Accepts no argument.
|
:ref:`Shutdown function <dev-segments-shutdown>`. Accepts no argument.
|
||||||
|
|
||||||
``mode``
|
|
||||||
:ref:`Segment-specific mode <dev-listers-mode>`. May be ``None``.
|
|
||||||
|
|
||||||
Segments layout
|
Segments layout
|
||||||
===============
|
===============
|
||||||
|
|
||||||
|
21
docs/source/develop/tips-and-tricks.rst
Normal file
21
docs/source/develop/tips-and-tricks.rst
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
****************************************
|
||||||
|
Tips and tricks for powerline developers
|
||||||
|
****************************************
|
||||||
|
|
||||||
|
Profiling powerline in Vim
|
||||||
|
==========================
|
||||||
|
|
||||||
|
Given that current directory is the root of the powerline repository the
|
||||||
|
following command may be used:
|
||||||
|
|
||||||
|
.. code-block:: sh
|
||||||
|
|
||||||
|
vim --cmd 'let g:powerline_pyeval="powerline#debug#profile_pyeval"' \
|
||||||
|
--cmd 'set rtp=powerline/bindings/vim' \
|
||||||
|
-c 'runtime! plugin/powerline.vim' \
|
||||||
|
{other arguments if needed}
|
||||||
|
|
||||||
|
After some time run ``:WriteProfiling {filename}`` Vim command. Currently this
|
||||||
|
only works with recent Vim and python-2*. It should be easy to modify
|
||||||
|
:file:`powerline/bindings/vim/autoload/powerline/debug.vim` to suit other
|
||||||
|
needs.
|
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:
|
20
powerline/bindings/vim/autoload/powerline/debug.vim
Normal file
20
powerline/bindings/vim/autoload/powerline/debug.vim
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
python import cProfile
|
||||||
|
python powerline_pr = cProfile.Profile()
|
||||||
|
|
||||||
|
function powerline#debug#profile_pyeval(s)
|
||||||
|
python powerline_pr.enable()
|
||||||
|
try
|
||||||
|
let ret = pyeval(a:s)
|
||||||
|
finally
|
||||||
|
python powerline_pr.disable()
|
||||||
|
endtry
|
||||||
|
return ret
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function powerline#debug#write_profile(fname)
|
||||||
|
python import vim
|
||||||
|
python powerline_pr.dump_stats(vim.eval('a:fname'))
|
||||||
|
python powerline_pr = cProfile.Profile()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
command -nargs=1 -complete=file WriteProfiling :call powerline#debug#write_profile(<q-args>)
|
@ -32,14 +32,6 @@ def pick_gradient_value(grad_list, gradient_level):
|
|||||||
return grad_list[int(round(gradient_level * (len(grad_list) - 1) / 100))]
|
return grad_list[int(round(gradient_level * (len(grad_list) - 1) / 100))]
|
||||||
|
|
||||||
|
|
||||||
def hl_iter(value):
|
|
||||||
if type(value) is list:
|
|
||||||
for v in value:
|
|
||||||
yield v
|
|
||||||
else:
|
|
||||||
yield value
|
|
||||||
|
|
||||||
|
|
||||||
class Colorscheme(object):
|
class Colorscheme(object):
|
||||||
def __init__(self, colorscheme_config, colors_config):
|
def __init__(self, colorscheme_config, colors_config):
|
||||||
'''Initialize a colorscheme.'''
|
'''Initialize a colorscheme.'''
|
||||||
@ -105,12 +97,12 @@ class Colorscheme(object):
|
|||||||
|
|
||||||
def get_highlighting(self, groups, mode, gradient_level=None):
|
def get_highlighting(self, groups, mode, gradient_level=None):
|
||||||
trans = self.translations.get(mode, {})
|
trans = self.translations.get(mode, {})
|
||||||
for group in hl_iter(groups):
|
for group in groups:
|
||||||
group_props = self.get_group_props(mode, trans, group)
|
group_props = self.get_group_props(mode, trans, group)
|
||||||
if group_props:
|
if group_props:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
raise KeyError('Highlighting groups not found in colorscheme: ' + ', '.join(hl_iter(groups)))
|
raise KeyError('Highlighting groups not found in colorscheme: ' + ', '.join(groups))
|
||||||
|
|
||||||
if gradient_level is None:
|
if gradient_level is None:
|
||||||
pick_color = self.colors.__getitem__
|
pick_color = self.colors.__getitem__
|
||||||
|
@ -17,6 +17,15 @@
|
|||||||
"many_tabs": "line_current",
|
"many_tabs": "line_current",
|
||||||
"bufnr": "file_directory",
|
"bufnr": "file_directory",
|
||||||
"winnr": "information:unimportant",
|
"winnr": "information:unimportant",
|
||||||
"tabnr": "file_directory"
|
"tabnr": "file_directory",
|
||||||
|
|
||||||
|
"tab_nc:file_directory": "information:unimportant",
|
||||||
|
"tab_nc:file_name": "tab_nc:file_directory",
|
||||||
|
"tab_nc:tabnr": "tab_nc:file_directory",
|
||||||
|
|
||||||
|
"buf_nc:file_directory": "tab_nc:file_directory",
|
||||||
|
"buf_nc:file_name": "tab_nc:file_name",
|
||||||
|
"buf_nc:bufnr": "tab_nc:tabnr",
|
||||||
|
"buf_nc:modified_indicator": "tab_nc:modified_indicator"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,9 @@
|
|||||||
"attached_clients": { "fg": "gray8", "bg": "gray2", "attr": [] },
|
"attached_clients": { "fg": "gray8", "bg": "gray2", "attr": [] },
|
||||||
"error": { "fg": "brightestred", "bg": "darkred", "attr": ["bold"] },
|
"error": { "fg": "brightestred", "bg": "darkred", "attr": ["bold"] },
|
||||||
"warning": { "fg": "brightyellow", "bg": "darkorange", "attr": ["bold"] },
|
"warning": { "fg": "brightyellow", "bg": "darkorange", "attr": ["bold"] },
|
||||||
"current_tag": { "fg": "gray9", "bg": "gray2", "attr": [] }
|
"current_tag": { "fg": "gray9", "bg": "gray2", "attr": [] },
|
||||||
|
|
||||||
|
"tab_nc:modified_indicator": { "fg": "brightyellow", "bg": "gray2", "attr": ["bold"] }
|
||||||
},
|
},
|
||||||
"mode_translations": {
|
"mode_translations": {
|
||||||
"nc": {
|
"nc": {
|
||||||
@ -52,44 +54,6 @@
|
|||||||
"dark_green_gray": "gray5"
|
"dark_green_gray": "gray5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tab_nc": {
|
|
||||||
"colors": {
|
|
||||||
"brightyellow": "darkorange",
|
|
||||||
"brightestred": "darkred",
|
|
||||||
"gray0": "gray0",
|
|
||||||
"gray1": "gray0",
|
|
||||||
"gray2": "gray0",
|
|
||||||
"gray3": "gray1",
|
|
||||||
"gray4": "gray1",
|
|
||||||
"gray5": "gray1",
|
|
||||||
"gray6": "gray1",
|
|
||||||
"gray7": "gray4",
|
|
||||||
"gray8": "gray4",
|
|
||||||
"gray9": "gray4",
|
|
||||||
"gray10": "gray5",
|
|
||||||
"white": "gray6",
|
|
||||||
"dark_green_gray": "gray5"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"buf_nc": {
|
|
||||||
"colors": {
|
|
||||||
"brightyellow": "darkorange",
|
|
||||||
"brightestred": "darkred",
|
|
||||||
"gray0": "gray0",
|
|
||||||
"gray1": "gray0",
|
|
||||||
"gray2": "gray0",
|
|
||||||
"gray3": "gray1",
|
|
||||||
"gray4": "gray1",
|
|
||||||
"gray5": "gray1",
|
|
||||||
"gray6": "gray1",
|
|
||||||
"gray7": "gray4",
|
|
||||||
"gray8": "gray4",
|
|
||||||
"gray9": "gray4",
|
|
||||||
"gray10": "gray5",
|
|
||||||
"white": "gray6",
|
|
||||||
"dark_green_gray": "gray5"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"i": {
|
"i": {
|
||||||
"colors": {
|
"colors": {
|
||||||
"gray0": "darkestblue",
|
"gray0": "darkestblue",
|
||||||
|
@ -44,26 +44,6 @@
|
|||||||
"solarized:base3": "solarized:base1"
|
"solarized:base3": "solarized:base1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tab_nc": {
|
|
||||||
"colors": {
|
|
||||||
"solarized:base01": "solarized:base02",
|
|
||||||
"solarized:base00": "solarized:base02",
|
|
||||||
"solarized:base0": "solarized:base01",
|
|
||||||
"solarized:base1": "solarized:base00",
|
|
||||||
"solarized:base2": "solarized:base0",
|
|
||||||
"solarized:base3": "solarized:base1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"buf_nc": {
|
|
||||||
"colors": {
|
|
||||||
"solarized:base01": "solarized:base02",
|
|
||||||
"solarized:base00": "solarized:base02",
|
|
||||||
"solarized:base0": "solarized:base01",
|
|
||||||
"solarized:base1": "solarized:base00",
|
|
||||||
"solarized:base2": "solarized:base0",
|
|
||||||
"solarized:base3": "solarized:base1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"i": {
|
"i": {
|
||||||
"groups": {
|
"groups": {
|
||||||
"background": { "fg": "solarized:base3", "bg": "solarized:base01", "attr": [] },
|
"background": { "fg": "solarized:base3", "bg": "solarized:base01", "attr": [] },
|
||||||
|
@ -43,26 +43,6 @@
|
|||||||
"solarized:base03": "solarized:base1"
|
"solarized:base03": "solarized:base1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tab_nc": {
|
|
||||||
"colors": {
|
|
||||||
"solarized:base2": "solarized:base01",
|
|
||||||
"solarized:base0": "solarized:base01",
|
|
||||||
"solarized:base00": "solarized:base2",
|
|
||||||
"solarized:base1": "solarized:base0",
|
|
||||||
"solarized:base02": "solarized:base00",
|
|
||||||
"solarized:base03": "solarized:base1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"buf_nc": {
|
|
||||||
"colors": {
|
|
||||||
"solarized:base2": "solarized:base01",
|
|
||||||
"solarized:base0": "solarized:base01",
|
|
||||||
"solarized:base00": "solarized:base2",
|
|
||||||
"solarized:base1": "solarized:base0",
|
|
||||||
"solarized:base02": "solarized:base00",
|
|
||||||
"solarized:base03": "solarized:base1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"i": {
|
"i": {
|
||||||
"groups": {
|
"groups": {
|
||||||
"background": { "fg": "solarized:base03", "bg": "solarized:base2", "attr": [] },
|
"background": { "fg": "solarized:base03", "bg": "solarized:base2", "attr": [] },
|
||||||
|
@ -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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import logging
|
|||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
from powerline.lint.markedjson import load
|
from powerline.lint.markedjson import load
|
||||||
from powerline import generate_config_finder, get_config_paths, load_config
|
from powerline import generate_config_finder, get_config_paths, load_config
|
||||||
@ -478,18 +479,18 @@ def check_matcher_func(ext, match_name, data, context, echoerr):
|
|||||||
echoerr(context='Error while loading matcher functions',
|
echoerr(context='Error while loading matcher functions',
|
||||||
problem='failed to load module {0}'.format(match_module),
|
problem='failed to load module {0}'.format(match_module),
|
||||||
problem_mark=match_name.mark)
|
problem_mark=match_name.mark)
|
||||||
return True, True
|
return True, False, True
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
echoerr(context='Error while loading matcher functions',
|
echoerr(context='Error while loading matcher functions',
|
||||||
problem='failed to load matcher function {0}'.format(match_function),
|
problem='failed to load matcher function {0}'.format(match_function),
|
||||||
problem_mark=match_name.mark)
|
problem_mark=match_name.mark)
|
||||||
return True, True
|
return True, False, True
|
||||||
|
|
||||||
if not callable(func):
|
if not callable(func):
|
||||||
echoerr(context='Error while loading matcher functions',
|
echoerr(context='Error while loading matcher functions',
|
||||||
problem='loaded "function" {0} is not callable'.format(match_function),
|
problem='loaded "function" {0} is not callable'.format(match_function),
|
||||||
problem_mark=match_name.mark)
|
problem_mark=match_name.mark)
|
||||||
return True, True
|
return True, False, True
|
||||||
|
|
||||||
if hasattr(func, 'func_code') and hasattr(func.func_code, 'co_argcount'):
|
if hasattr(func, 'func_code') and hasattr(func.func_code, 'co_argcount'):
|
||||||
if func.func_code.co_argcount != 1:
|
if func.func_code.co_argcount != 1:
|
||||||
@ -502,7 +503,7 @@ def check_matcher_func(ext, match_name, data, context, echoerr):
|
|||||||
problem_mark=match_name.mark
|
problem_mark=match_name.mark
|
||||||
)
|
)
|
||||||
|
|
||||||
return True, False
|
return True, False, False
|
||||||
|
|
||||||
|
|
||||||
def check_ext(ext, data, context, echoerr):
|
def check_ext(ext, data, context, echoerr):
|
||||||
@ -561,6 +562,9 @@ def check_top_theme(theme, data, context, echoerr):
|
|||||||
return True, False, False
|
return True, False, False
|
||||||
|
|
||||||
|
|
||||||
|
function_name_re = '^(\w+\.)*[a-zA-Z_]\w*$'
|
||||||
|
|
||||||
|
|
||||||
divider_spec = Spec().type(unicode).len(
|
divider_spec = Spec().type(unicode).len(
|
||||||
'le', 3, (lambda value: 'Divider {0!r} is too large!'.format(value))).copy
|
'le', 3, (lambda value: 'Divider {0!r} is too large!'.format(value))).copy
|
||||||
ext_theme_spec = Spec().type(unicode).func(lambda *args: check_config('themes', *args)).copy
|
ext_theme_spec = Spec().type(unicode).func(lambda *args: check_config('themes', *args)).copy
|
||||||
@ -608,7 +612,8 @@ main_spec = (Spec(
|
|||||||
local_themes=Spec(
|
local_themes=Spec(
|
||||||
__tabline__=ext_theme_spec(),
|
__tabline__=ext_theme_spec(),
|
||||||
).unknown_spec(
|
).unknown_spec(
|
||||||
lambda *args: check_matcher_func('vim', *args), ext_theme_spec()
|
Spec().re(function_name_re).func(partial(check_matcher_func, 'vim')),
|
||||||
|
ext_theme_spec()
|
||||||
),
|
),
|
||||||
).optional(),
|
).optional(),
|
||||||
ipython=ext_spec().update(
|
ipython=ext_spec().update(
|
||||||
@ -801,6 +806,7 @@ shell_colorscheme_spec = (Spec(
|
|||||||
|
|
||||||
generic_keys = set((
|
generic_keys = set((
|
||||||
'exclude_modes', 'include_modes',
|
'exclude_modes', 'include_modes',
|
||||||
|
'exclude_function', 'include_function',
|
||||||
'width', 'align',
|
'width', 'align',
|
||||||
'name',
|
'name',
|
||||||
'draw_soft_divider', 'draw_hard_divider',
|
'draw_soft_divider', 'draw_hard_divider',
|
||||||
@ -935,7 +941,7 @@ def check_full_segment_data(segment, data, context, echoerr):
|
|||||||
return check_key_compatibility(segment_copy, data, context, echoerr)
|
return check_key_compatibility(segment_copy, data, context, echoerr)
|
||||||
|
|
||||||
|
|
||||||
def import_segment(name, data, context, echoerr, module):
|
def import_function(function_type, name, data, context, echoerr, module):
|
||||||
context_has_marks(context)
|
context_has_marks(context)
|
||||||
havemarks(name, module)
|
havemarks(name, module)
|
||||||
|
|
||||||
@ -949,7 +955,7 @@ def import_segment(name, data, context, echoerr, module):
|
|||||||
problem_mark=module.mark)
|
problem_mark=module.mark)
|
||||||
return None
|
return None
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
echoerr(context='Error while loading segment function (key {key})'.format(key=context_key(context)),
|
echoerr(context='Error while loading {0} function (key {key})'.format(function_type, key=context_key(context)),
|
||||||
problem='failed to load function {0} from module {1}'.format(name, module),
|
problem='failed to load function {0} from module {1}'.format(name, module),
|
||||||
problem_mark=name.mark)
|
problem_mark=name.mark)
|
||||||
return None
|
return None
|
||||||
@ -964,6 +970,10 @@ def import_segment(name, data, context, echoerr, module):
|
|||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
||||||
|
def import_segment(*args, **kwargs):
|
||||||
|
return import_function('segment', *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def check_segment_function(function_name, data, context, echoerr):
|
def check_segment_function(function_name, data, context, echoerr):
|
||||||
havemarks(function_name)
|
havemarks(function_name)
|
||||||
ext = data['ext']
|
ext = data['ext']
|
||||||
@ -1334,6 +1344,17 @@ def get_all_possible_functions(data, context, echoerr):
|
|||||||
yield func
|
yield func
|
||||||
|
|
||||||
|
|
||||||
|
def check_exinclude_function(name, data, context, echoerr):
|
||||||
|
ext = data['ext']
|
||||||
|
module, name = name.rpartition('.')[::2]
|
||||||
|
if not module:
|
||||||
|
module = MarkedUnicode('powerline.selectors.' + ext, None)
|
||||||
|
func = import_function('selector', name, data, context, echoerr, module=module)
|
||||||
|
if not func:
|
||||||
|
return True, False, True
|
||||||
|
return True, False, False
|
||||||
|
|
||||||
|
|
||||||
args_spec = Spec(
|
args_spec = Spec(
|
||||||
pl=Spec().error('pl object must be set by powerline').optional(),
|
pl=Spec().error('pl object must be set by powerline').optional(),
|
||||||
segment_info=Spec().error('Segment info dictionary must be set by powerline').optional(),
|
segment_info=Spec().error('Segment info dictionary must be set by powerline').optional(),
|
||||||
@ -1341,12 +1362,15 @@ args_spec = Spec(
|
|||||||
highlight_group_spec = Spec().type(unicode).copy
|
highlight_group_spec = Spec().type(unicode).copy
|
||||||
segment_module_spec = Spec().type(unicode).func(check_segment_module).optional().copy
|
segment_module_spec = Spec().type(unicode).func(check_segment_module).optional().copy
|
||||||
sub_segments_spec = Spec()
|
sub_segments_spec = Spec()
|
||||||
|
exinclude_spec = Spec().re(function_name_re).func(check_exinclude_function).copy
|
||||||
segment_spec = Spec(
|
segment_spec = Spec(
|
||||||
type=Spec().oneof(type_keys).optional(),
|
type=Spec().oneof(type_keys).optional(),
|
||||||
name=Spec().re('^[a-zA-Z_]\w*$').optional(),
|
name=Spec().re('^[a-zA-Z_]\w*$').optional(),
|
||||||
function=Spec().re('^(\w+\.)*[a-zA-Z_]\w*$').func(check_segment_function).optional(),
|
function=Spec().re(function_name_re).func(check_segment_function).optional(),
|
||||||
exclude_modes=Spec().list(vim_mode_spec()).optional(),
|
exclude_modes=Spec().list(vim_mode_spec()).optional(),
|
||||||
include_modes=Spec().list(vim_mode_spec()).optional(),
|
include_modes=Spec().list(vim_mode_spec()).optional(),
|
||||||
|
exclude_function=exinclude_spec().optional(),
|
||||||
|
include_function=exinclude_spec().optional(),
|
||||||
draw_hard_divider=Spec().type(bool).optional(),
|
draw_hard_divider=Spec().type(bool).optional(),
|
||||||
draw_soft_divider=Spec().type(bool).optional(),
|
draw_soft_divider=Spec().type(bool).optional(),
|
||||||
draw_inner_divider=Spec().type(bool).optional(),
|
draw_inner_divider=Spec().type(bool).optional(),
|
||||||
|
@ -10,7 +10,7 @@ except ImportError:
|
|||||||
vim = {}
|
vim = {}
|
||||||
|
|
||||||
|
|
||||||
def tabpage_updated_segment_info(segment_info, tabpage, mode):
|
def tabpage_updated_segment_info(segment_info, tabpage):
|
||||||
segment_info = segment_info.copy()
|
segment_info = segment_info.copy()
|
||||||
window = tabpage.window
|
window = tabpage.window
|
||||||
buffer = window.buffer
|
buffer = window.buffer
|
||||||
@ -22,7 +22,6 @@ def tabpage_updated_segment_info(segment_info, tabpage, mode):
|
|||||||
window_id=int(window.vars.get('powerline_window_id', -1)),
|
window_id=int(window.vars.get('powerline_window_id', -1)),
|
||||||
buffer=buffer,
|
buffer=buffer,
|
||||||
bufnr=buffer.number,
|
bufnr=buffer.number,
|
||||||
mode=mode,
|
|
||||||
)
|
)
|
||||||
return segment_info
|
return segment_info
|
||||||
|
|
||||||
@ -35,8 +34,7 @@ def tablister(pl, segment_info, **kwargs):
|
|||||||
``winnr``, ``window_id``, ``buffer`` and ``bufnr`` keys set to tab-local
|
``winnr``, ``window_id``, ``buffer`` and ``bufnr`` keys set to tab-local
|
||||||
ones and additional ``tabpage`` and ``tabnr`` keys.
|
ones and additional ``tabpage`` and ``tabnr`` keys.
|
||||||
|
|
||||||
Sets segment ``mode`` to either ``tab`` (for current tab page) or ``tab_nc``
|
Adds either ``tab:`` or ``tab_nc:`` prefix to all segment highlight groups.
|
||||||
(for all other tab pages).
|
|
||||||
|
|
||||||
Works best with vim-7.4 or later: earlier versions miss tabpage object and
|
Works best with vim-7.4 or later: earlier versions miss tabpage object and
|
||||||
thus window objects are not available as well.
|
thus window objects are not available as well.
|
||||||
@ -49,15 +47,15 @@ def tablister(pl, segment_info, **kwargs):
|
|||||||
return dct
|
return dct
|
||||||
|
|
||||||
return (
|
return (
|
||||||
(lambda tabpage, mode: (
|
(lambda tabpage, prefix: (
|
||||||
tabpage_updated_segment_info(segment_info, tabpage, mode),
|
tabpage_updated_segment_info(segment_info, tabpage),
|
||||||
add_multiplier(tabpage, {'mode': mode})
|
add_multiplier(tabpage, {'highlight_group_prefix': prefix})
|
||||||
))(tabpage, 'tab' if tabpage == cur_tabpage else 'tab_nc')
|
))(tabpage, 'tab' if tabpage == cur_tabpage else 'tab_nc')
|
||||||
for tabpage in list_tabpages()
|
for tabpage in list_tabpages()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def buffer_updated_segment_info(segment_info, buffer, mode):
|
def buffer_updated_segment_info(segment_info, buffer):
|
||||||
segment_info = segment_info.copy()
|
segment_info = segment_info.copy()
|
||||||
segment_info.update(
|
segment_info.update(
|
||||||
window=None,
|
window=None,
|
||||||
@ -65,7 +63,6 @@ def buffer_updated_segment_info(segment_info, buffer, mode):
|
|||||||
window_id=None,
|
window_id=None,
|
||||||
buffer=buffer,
|
buffer=buffer,
|
||||||
bufnr=buffer.number,
|
bufnr=buffer.number,
|
||||||
mode=mode,
|
|
||||||
)
|
)
|
||||||
return segment_info
|
return segment_info
|
||||||
|
|
||||||
@ -78,8 +75,7 @@ def bufferlister(pl, segment_info, show_unlisted=False, **kwargs):
|
|||||||
and ``bufnr`` keys set to buffer-specific ones, ``window``, ``winnr`` and
|
and ``bufnr`` keys set to buffer-specific ones, ``window``, ``winnr`` and
|
||||||
``window_id`` keys set to None.
|
``window_id`` keys set to None.
|
||||||
|
|
||||||
Sets segment ``mode`` to either ``buf`` (for current buffer) or ``buf_nc``
|
Adds either ``buf:`` or ``buf_nc:`` prefix to all segment highlight groups.
|
||||||
(for all other buffers).
|
|
||||||
|
|
||||||
:param bool show_unlisted:
|
:param bool show_unlisted:
|
||||||
True if unlisted buffers should be shown as well. Current buffer is
|
True if unlisted buffers should be shown as well. Current buffer is
|
||||||
@ -95,12 +91,14 @@ def bufferlister(pl, segment_info, show_unlisted=False, **kwargs):
|
|||||||
return (
|
return (
|
||||||
(
|
(
|
||||||
buf_segment_info,
|
buf_segment_info,
|
||||||
add_multiplier(buf_segment_info['buffer'], {'mode': buf_segment_info['mode']})
|
add_multiplier(buf_segment_info['buffer'], {'highlight_group_prefix': prefix})
|
||||||
)
|
)
|
||||||
for buf_segment_info in (
|
for buf_segment_info, prefix in (
|
||||||
buffer_updated_segment_info(
|
(
|
||||||
segment_info,
|
buffer_updated_segment_info(
|
||||||
buffer,
|
segment_info,
|
||||||
|
buffer
|
||||||
|
),
|
||||||
('buf' if buffer is cur_buffer else 'buf_nc')
|
('buf' if buffer is cur_buffer else 'buf_nc')
|
||||||
)
|
)
|
||||||
for buffer in vim.buffers
|
for buffer in vim.buffers
|
||||||
@ -110,11 +108,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)
|
|
||||||
|
@ -266,20 +266,32 @@ class Renderer(object):
|
|||||||
for segment in chain(segments_priority, no_priority_segments):
|
for segment in chain(segments_priority, no_priority_segments):
|
||||||
if segment['truncate'] is not None:
|
if segment['truncate'] is not None:
|
||||||
segment['contents'] = segment['truncate'](self.pl, current_width - width, segment)
|
segment['contents'] = segment['truncate'](self.pl, current_width - width, segment)
|
||||||
for segment in segments_priority:
|
|
||||||
if current_width <= width:
|
segments_priority = iter(segments_priority)
|
||||||
break
|
if current_width > width and len(segments) > 100:
|
||||||
segments.remove(segment)
|
# When there are too many segments use faster, but less correct
|
||||||
|
# algorythm for width computation
|
||||||
|
diff = current_width - width
|
||||||
|
for segment in segments_priority:
|
||||||
|
segments.remove(segment)
|
||||||
|
diff -= segment['_len']
|
||||||
|
if diff <= 0:
|
||||||
|
break
|
||||||
current_width = self._render_length(theme, segments, divider_widths)
|
current_width = self._render_length(theme, segments, divider_widths)
|
||||||
|
if current_width > width:
|
||||||
|
# When there are not too much use more precise, but much slower
|
||||||
|
# width computation. It also finishes computations in case
|
||||||
|
# previous variant did not free enough space.
|
||||||
|
for segment in segments_priority:
|
||||||
|
segments.remove(segment)
|
||||||
|
current_width = self._render_length(theme, segments, divider_widths)
|
||||||
|
if current_width <= width:
|
||||||
|
break
|
||||||
|
del segments_priority
|
||||||
|
|
||||||
# Distribute the remaining space on spacer segments
|
# Distribute the remaining space on spacer segments
|
||||||
segments_spacers = [segment for segment in segments if segment['expand'] is not None]
|
segments_spacers = [segment for segment in segments if segment['expand'] is not None]
|
||||||
if segments_spacers:
|
if segments_spacers:
|
||||||
if not segments_priority:
|
|
||||||
# Update segment['_len'] and current_width if not already done
|
|
||||||
# (is not done in shells where there is nothing to remove
|
|
||||||
# because “priority” key is not specified)
|
|
||||||
current_width = self._render_length(theme, segments, divider_widths)
|
|
||||||
distribute_len, distribute_len_remainder = divmod(width - current_width, len(segments_spacers))
|
distribute_len, distribute_len_remainder = divmod(width - current_width, len(segments_spacers))
|
||||||
for segment in segments_spacers:
|
for segment in segments_spacers:
|
||||||
segment['contents'] = (
|
segment['contents'] = (
|
||||||
@ -360,50 +372,46 @@ class Renderer(object):
|
|||||||
contents_highlighted = ''
|
contents_highlighted = ''
|
||||||
draw_divider = segment['draw_' + divider_type + '_divider']
|
draw_divider = segment['draw_' + divider_type + '_divider']
|
||||||
|
|
||||||
# Pad segments first
|
contents_raw = contents_raw.translate(self.np_character_translations)
|
||||||
|
|
||||||
|
# XXX Make sure self.hl() calls are called in the same order
|
||||||
|
# segments are displayed. This is needed for Vim renderer to work.
|
||||||
if draw_divider:
|
if draw_divider:
|
||||||
divider_raw = self.escape(theme.get_divider(side, divider_type))
|
divider_raw = self.escape(theme.get_divider(side, divider_type))
|
||||||
if side == 'left':
|
if side == 'left':
|
||||||
contents_raw = outer_padding + contents_raw + (divider_spaces * ' ')
|
contents_raw = outer_padding + contents_raw + (divider_spaces * ' ')
|
||||||
else:
|
else:
|
||||||
contents_raw = (divider_spaces * ' ') + contents_raw + outer_padding
|
contents_raw = (divider_spaces * ' ') + contents_raw + outer_padding
|
||||||
|
|
||||||
|
if divider_type == 'soft':
|
||||||
|
divider_highlight_group_key = 'highlight' if segment['divider_highlight_group'] is None else 'divider_highlight'
|
||||||
|
divider_fg = segment[divider_highlight_group_key]['fg']
|
||||||
|
divider_bg = segment[divider_highlight_group_key]['bg']
|
||||||
|
else:
|
||||||
|
divider_fg = segment['highlight']['bg']
|
||||||
|
divider_bg = compare_segment['highlight']['bg']
|
||||||
|
|
||||||
|
if side == 'left':
|
||||||
|
if render_highlighted:
|
||||||
|
contents_highlighted = self.hl(self.escape(contents_raw), **segment['highlight'])
|
||||||
|
divider_highlighted = self.hl(divider_raw, divider_fg, divider_bg, False)
|
||||||
|
segment['_rendered_raw'] = contents_raw + divider_raw
|
||||||
|
segment['_rendered_hl'] = contents_highlighted + divider_highlighted
|
||||||
|
else:
|
||||||
|
if render_highlighted:
|
||||||
|
divider_highlighted = self.hl(divider_raw, divider_fg, divider_bg, False)
|
||||||
|
contents_highlighted = self.hl(self.escape(contents_raw), **segment['highlight'])
|
||||||
|
segment['_rendered_raw'] = divider_raw + contents_raw
|
||||||
|
segment['_rendered_hl'] = divider_highlighted + contents_highlighted
|
||||||
else:
|
else:
|
||||||
if side == 'left':
|
if side == 'left':
|
||||||
contents_raw = outer_padding + contents_raw
|
contents_raw = outer_padding + contents_raw
|
||||||
else:
|
else:
|
||||||
contents_raw = contents_raw + outer_padding
|
contents_raw = contents_raw + outer_padding
|
||||||
|
|
||||||
# Replace spaces with no-break spaces
|
|
||||||
contents_raw = contents_raw.translate(self.np_character_translations)
|
|
||||||
|
|
||||||
# Apply highlighting to padded dividers and contents
|
|
||||||
if render_highlighted:
|
|
||||||
if draw_divider:
|
|
||||||
if divider_type == 'soft':
|
|
||||||
divider_highlight_group_key = 'highlight' if segment['divider_highlight_group'] is None else 'divider_highlight'
|
|
||||||
divider_fg = segment[divider_highlight_group_key]['fg']
|
|
||||||
divider_bg = segment[divider_highlight_group_key]['bg']
|
|
||||||
else:
|
|
||||||
divider_fg = segment['highlight']['bg']
|
|
||||||
divider_bg = compare_segment['highlight']['bg']
|
|
||||||
divider_highlighted = self.hl(divider_raw, divider_fg, divider_bg, False)
|
|
||||||
contents_highlighted = self.hl(self.escape(contents_raw), **segment['highlight'])
|
contents_highlighted = self.hl(self.escape(contents_raw), **segment['highlight'])
|
||||||
|
segment['_rendered_raw'] = contents_raw
|
||||||
# Append padded raw and highlighted segments to the rendered segment variables
|
segment['_rendered_hl'] = contents_highlighted
|
||||||
if draw_divider:
|
|
||||||
if side == 'left':
|
|
||||||
segment['_rendered_raw'] = contents_raw + divider_raw
|
|
||||||
segment['_rendered_hl'] = contents_highlighted + divider_highlighted
|
|
||||||
else:
|
|
||||||
segment['_rendered_raw'] = divider_raw + contents_raw
|
|
||||||
segment['_rendered_hl'] = divider_highlighted + contents_highlighted
|
|
||||||
else:
|
|
||||||
if side == 'left':
|
|
||||||
segment['_rendered_raw'] = contents_raw
|
|
||||||
segment['_rendered_hl'] = contents_highlighted
|
|
||||||
else:
|
|
||||||
segment['_rendered_raw'] = contents_raw
|
|
||||||
segment['_rendered_hl'] = contents_highlighted
|
|
||||||
yield segment
|
yield segment
|
||||||
|
|
||||||
def escape(self, string):
|
def escape(self, string):
|
||||||
|
@ -40,6 +40,7 @@ class VimRenderer(Renderer):
|
|||||||
kwargs['ambigious'] = 2
|
kwargs['ambigious'] = 2
|
||||||
super(VimRenderer, self).__init__(*args, **kwargs)
|
super(VimRenderer, self).__init__(*args, **kwargs)
|
||||||
self.hl_groups = {}
|
self.hl_groups = {}
|
||||||
|
self.prev_highlight = None
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
self.theme.shutdown()
|
self.theme.shutdown()
|
||||||
@ -126,7 +127,15 @@ class VimRenderer(Renderer):
|
|||||||
False, the argument is reset to the terminal defaults. If an argument
|
False, the argument is reset to the terminal defaults. If an argument
|
||||||
is a valid color or attribute, it's added to the vim highlight group.
|
is a valid color or attribute, it's added to the vim highlight group.
|
||||||
'''
|
'''
|
||||||
# We don't need to explicitly reset attributes in vim, so skip those calls
|
# In order not to hit E541 two consequent identical highlighting
|
||||||
|
# specifiers may be squashed into one.
|
||||||
|
attr = attr or 0 # Normalize `attr`
|
||||||
|
if (fg, bg, attr) == self.prev_highlight:
|
||||||
|
return ''
|
||||||
|
self.prev_highlight = (fg, bg, attr)
|
||||||
|
|
||||||
|
# We don't need to explicitly reset attributes in vim, so skip those
|
||||||
|
# calls
|
||||||
if not attr and not bg and not fg:
|
if not attr and not bg and not fg:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
@ -102,6 +102,11 @@ def get_attr_func(contents_func, key, args, is_space_func=False):
|
|||||||
|
|
||||||
def process_segment_lister(pl, segment_info, parsed_segments, side, mode, colorscheme,
|
def process_segment_lister(pl, segment_info, parsed_segments, side, mode, colorscheme,
|
||||||
lister, subsegments, patcher_args):
|
lister, subsegments, patcher_args):
|
||||||
|
subsegments = [
|
||||||
|
subsegment
|
||||||
|
for subsegment in subsegments
|
||||||
|
if subsegment['display_condition'](pl, segment_info, mode)
|
||||||
|
]
|
||||||
for subsegment_info, subsegment_update in lister(pl=pl, segment_info=segment_info, **patcher_args):
|
for subsegment_info, subsegment_update in lister(pl=pl, segment_info=segment_info, **patcher_args):
|
||||||
draw_inner_divider = subsegment_update.pop('draw_inner_divider', False)
|
draw_inner_divider = subsegment_update.pop('draw_inner_divider', False)
|
||||||
old_pslen = len(parsed_segments)
|
old_pslen = len(parsed_segments)
|
||||||
@ -109,26 +114,16 @@ def process_segment_lister(pl, segment_info, parsed_segments, side, mode, colors
|
|||||||
if subsegment_update:
|
if subsegment_update:
|
||||||
subsegment = subsegment.copy()
|
subsegment = subsegment.copy()
|
||||||
subsegment.update(subsegment_update)
|
subsegment.update(subsegment_update)
|
||||||
if subsegment_update['priority_multiplier'] and subsegment['priority']:
|
if 'priority_multiplier' in subsegment_update and subsegment['priority']:
|
||||||
subsegment['priority'] *= subsegment_update['priority_multiplier']
|
subsegment['priority'] *= subsegment_update['priority_multiplier']
|
||||||
|
|
||||||
subsegment_mode = subsegment_update.get('mode')
|
|
||||||
if subsegment_mode and (
|
|
||||||
subsegment_mode in subsegment['exclude_modes']
|
|
||||||
or (
|
|
||||||
subsegment['include_modes']
|
|
||||||
and subsegment_mode not in subsegment['include_modes']
|
|
||||||
)
|
|
||||||
):
|
|
||||||
continue
|
|
||||||
|
|
||||||
process_segment(
|
process_segment(
|
||||||
pl,
|
pl,
|
||||||
side,
|
side,
|
||||||
subsegment_info,
|
subsegment_info,
|
||||||
parsed_segments,
|
parsed_segments,
|
||||||
subsegment,
|
subsegment,
|
||||||
subsegment_mode or mode,
|
mode,
|
||||||
colorscheme,
|
colorscheme,
|
||||||
)
|
)
|
||||||
new_pslen = len(parsed_segments)
|
new_pslen = len(parsed_segments)
|
||||||
@ -138,17 +133,23 @@ def process_segment_lister(pl, segment_info, parsed_segments, side, mode, colors
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def set_segment_highlighting(pl, colorscheme, segment):
|
def set_segment_highlighting(pl, colorscheme, segment, mode):
|
||||||
|
try:
|
||||||
|
highlight_group_prefix = segment['highlight_group_prefix']
|
||||||
|
except KeyError:
|
||||||
|
hl_groups = lambda hlgs: hlgs
|
||||||
|
else:
|
||||||
|
hl_groups = lambda hlgs: [highlight_group_prefix + ':' + hlg for hlg in hlgs] + hlgs
|
||||||
try:
|
try:
|
||||||
segment['highlight'] = colorscheme.get_highlighting(
|
segment['highlight'] = colorscheme.get_highlighting(
|
||||||
segment['highlight_group'],
|
hl_groups(segment['highlight_group']),
|
||||||
segment['mode'],
|
mode,
|
||||||
segment.get('gradient_level')
|
segment.get('gradient_level')
|
||||||
)
|
)
|
||||||
if segment['divider_highlight_group']:
|
if segment['divider_highlight_group']:
|
||||||
segment['divider_highlight'] = colorscheme.get_highlighting(
|
segment['divider_highlight'] = colorscheme.get_highlighting(
|
||||||
segment['divider_highlight_group'],
|
hl_groups([segment['divider_highlight_group']]),
|
||||||
segment['mode']
|
mode
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
segment['divider_highlight'] = None
|
segment['divider_highlight'] = None
|
||||||
@ -161,7 +162,6 @@ def set_segment_highlighting(pl, colorscheme, segment):
|
|||||||
|
|
||||||
def process_segment(pl, side, segment_info, parsed_segments, segment, mode, colorscheme):
|
def process_segment(pl, side, segment_info, parsed_segments, segment, mode, colorscheme):
|
||||||
segment = segment.copy()
|
segment = segment.copy()
|
||||||
segment['mode'] = mode
|
|
||||||
pl.prefix = segment['name']
|
pl.prefix = segment['name']
|
||||||
if segment['type'] in ('function', 'segment_list'):
|
if segment['type'] in ('function', 'segment_list'):
|
||||||
try:
|
try:
|
||||||
@ -207,17 +207,20 @@ def process_segment(pl, side, segment_info, parsed_segments, segment, mode, colo
|
|||||||
if draw_inner_divider is not None:
|
if draw_inner_divider is not None:
|
||||||
segment_copy['draw_soft_divider'] = draw_inner_divider
|
segment_copy['draw_soft_divider'] = draw_inner_divider
|
||||||
draw_inner_divider = segment_copy.pop('draw_inner_divider', None)
|
draw_inner_divider = segment_copy.pop('draw_inner_divider', None)
|
||||||
if set_segment_highlighting(pl, colorscheme, segment_copy):
|
if set_segment_highlighting(pl, colorscheme, segment_copy, mode):
|
||||||
append(segment_copy)
|
append(segment_copy)
|
||||||
else:
|
else:
|
||||||
segment['contents'] = contents
|
segment['contents'] = contents
|
||||||
if set_segment_highlighting(pl, colorscheme, segment):
|
if set_segment_highlighting(pl, colorscheme, segment, mode):
|
||||||
parsed_segments.append(segment)
|
parsed_segments.append(segment)
|
||||||
elif segment['width'] == 'auto' or (segment['type'] == 'string' and segment['contents'] is not None):
|
elif segment['width'] == 'auto' or (segment['type'] == 'string' and segment['contents'] is not None):
|
||||||
if set_segment_highlighting(pl, colorscheme, segment):
|
if set_segment_highlighting(pl, colorscheme, segment, mode):
|
||||||
parsed_segments.append(segment)
|
parsed_segments.append(segment)
|
||||||
|
|
||||||
|
|
||||||
|
always_true = lambda pl, segment_info, mode: True
|
||||||
|
|
||||||
|
|
||||||
def gen_segment_getter(pl, ext, common_config, theme_configs, default_module, get_module_attr, top_theme):
|
def gen_segment_getter(pl, ext, common_config, theme_configs, default_module, get_module_attr, top_theme):
|
||||||
data = {
|
data = {
|
||||||
'default_module': default_module or 'powerline.segments.' + ext,
|
'default_module': default_module or 'powerline.segments.' + ext,
|
||||||
@ -229,12 +232,67 @@ def gen_segment_getter(pl, ext, common_config, theme_configs, default_module, ge
|
|||||||
return get_segment_key(merge, segment, theme_configs, data['segment_data'], key, function_name, name, module, default)
|
return get_segment_key(merge, segment, theme_configs, data['segment_data'], key, function_name, name, module, default)
|
||||||
data['get_key'] = get_key
|
data['get_key'] = get_key
|
||||||
|
|
||||||
|
def get_selector(function_name):
|
||||||
|
if '.' in function_name:
|
||||||
|
module, function_name = function_name.rpartition('.')[::2]
|
||||||
|
else:
|
||||||
|
module = 'powerline.selectors.' + ext
|
||||||
|
function = get_module_attr(module, function_name, prefix='segment_generator/selector_function')
|
||||||
|
if not function:
|
||||||
|
pl.error('Failed to get segment selector, ignoring it')
|
||||||
|
return function
|
||||||
|
|
||||||
|
def get_segment_selector(segment, selector_type):
|
||||||
|
try:
|
||||||
|
function_name = segment[selector_type + '_function']
|
||||||
|
except KeyError:
|
||||||
|
function = None
|
||||||
|
else:
|
||||||
|
function = get_selector(function_name)
|
||||||
|
try:
|
||||||
|
modes = segment[selector_type + '_modes']
|
||||||
|
except KeyError:
|
||||||
|
modes = None
|
||||||
|
|
||||||
|
if modes:
|
||||||
|
if function:
|
||||||
|
return lambda pl, segment_info, mode: (
|
||||||
|
mode in modes
|
||||||
|
or function(pl=pl, segment_info=segment_info, mode=mode)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return lambda pl, segment_info, mode: mode in modes
|
||||||
|
else:
|
||||||
|
if function:
|
||||||
|
return lambda pl, segment_info, mode: (
|
||||||
|
function(pl=pl, segment_info=segment_info, mode=mode)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def gen_display_condition(segment):
|
||||||
|
include_function = get_segment_selector(segment, 'include')
|
||||||
|
exclude_function = get_segment_selector(segment, 'exclude')
|
||||||
|
if include_function:
|
||||||
|
if exclude_function:
|
||||||
|
return lambda *args: (
|
||||||
|
include_function(*args)
|
||||||
|
and not exclude_function(*args))
|
||||||
|
else:
|
||||||
|
return include_function
|
||||||
|
else:
|
||||||
|
if exclude_function:
|
||||||
|
return lambda *args: not exclude_function(*args)
|
||||||
|
else:
|
||||||
|
return always_true
|
||||||
|
|
||||||
def get(segment, side):
|
def get(segment, side):
|
||||||
segment_type = segment.get('type', 'function')
|
segment_type = segment.get('type', 'function')
|
||||||
try:
|
try:
|
||||||
get_segment_info = segment_getters[segment_type]
|
get_segment_info = segment_getters[segment_type]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise TypeError('Unknown segment type: {0}'.format(segment_type))
|
pl.error('Unknown segment type: {0}', segment_type)
|
||||||
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
|
contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
|
||||||
@ -253,18 +311,27 @@ def gen_segment_getter(pl, ext, common_config, theme_configs, default_module, ge
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if segment_type == 'function':
|
if segment_type == 'function':
|
||||||
highlight_group = [module + '.' + function_name, function_name]
|
highlight_group = [function_name]
|
||||||
else:
|
else:
|
||||||
highlight_group = segment.get('highlight_group') or name
|
highlight_group = segment.get('highlight_group') or name
|
||||||
|
|
||||||
if segment_type in ('function', 'segment_list'):
|
if segment_type in ('function', 'segment_list'):
|
||||||
args = dict(((str(k), v) for k, v in get_key(True, segment, module, function_name, name, 'args', {}).items()))
|
args = dict((
|
||||||
|
(str(k), v)
|
||||||
|
for k, v in
|
||||||
|
get_key(True, segment, module, function_name, name, 'args', {}).items()
|
||||||
|
))
|
||||||
|
|
||||||
|
display_condition = gen_display_condition(segment)
|
||||||
|
|
||||||
if segment_type == 'segment_list':
|
if segment_type == 'segment_list':
|
||||||
# Handle startup and shutdown of _contents_func?
|
# Handle startup and shutdown of _contents_func?
|
||||||
subsegments = [
|
subsegments = [
|
||||||
get(subsegment, side)
|
subsegment
|
||||||
for subsegment in segment['segments']
|
for subsegment in (
|
||||||
|
get(subsegment, side)
|
||||||
|
for subsegment in segment['segments']
|
||||||
|
) if subsegment
|
||||||
]
|
]
|
||||||
return {
|
return {
|
||||||
'name': name or function_name,
|
'name': name or function_name,
|
||||||
@ -287,15 +354,13 @@ def gen_segment_getter(pl, ext, common_config, theme_configs, default_module, ge
|
|||||||
'draw_hard_divider': None,
|
'draw_hard_divider': None,
|
||||||
'draw_inner_divider': None,
|
'draw_inner_divider': None,
|
||||||
'side': side,
|
'side': side,
|
||||||
'exclude_modes': segment.get('exclude_modes', []),
|
'display_condition': display_condition,
|
||||||
'include_modes': segment.get('include_modes', []),
|
|
||||||
'width': None,
|
'width': None,
|
||||||
'align': None,
|
'align': None,
|
||||||
'expand': None,
|
'expand': None,
|
||||||
'truncate': None,
|
'truncate': None,
|
||||||
'startup': None,
|
'startup': None,
|
||||||
'shutdown': None,
|
'shutdown': None,
|
||||||
'mode': None,
|
|
||||||
'_rendered_raw': '',
|
'_rendered_raw': '',
|
||||||
'_rendered_hl': '',
|
'_rendered_hl': '',
|
||||||
'_len': None,
|
'_len': None,
|
||||||
@ -337,15 +402,13 @@ def gen_segment_getter(pl, ext, common_config, theme_configs, default_module, ge
|
|||||||
'draw_soft_divider': segment.get('draw_soft_divider', True),
|
'draw_soft_divider': segment.get('draw_soft_divider', True),
|
||||||
'draw_inner_divider': segment.get('draw_inner_divider', False),
|
'draw_inner_divider': segment.get('draw_inner_divider', False),
|
||||||
'side': side,
|
'side': side,
|
||||||
'exclude_modes': segment.get('exclude_modes', []),
|
'display_condition': display_condition,
|
||||||
'include_modes': segment.get('include_modes', []),
|
|
||||||
'width': segment.get('width'),
|
'width': segment.get('width'),
|
||||||
'align': segment.get('align', 'l'),
|
'align': segment.get('align', 'l'),
|
||||||
'expand': expand_func,
|
'expand': expand_func,
|
||||||
'truncate': truncate_func,
|
'truncate': truncate_func,
|
||||||
'startup': startup_func,
|
'startup': startup_func,
|
||||||
'shutdown': shutdown_func,
|
'shutdown': shutdown_func,
|
||||||
'mode': None,
|
|
||||||
'_rendered_raw': '',
|
'_rendered_raw': '',
|
||||||
'_rendered_hl': '',
|
'_rendered_hl': '',
|
||||||
'_len': None,
|
'_len': None,
|
||||||
|
@ -750,7 +750,7 @@ def user(pl, segment_info=None, hide_user=None):
|
|||||||
euid = _geteuid()
|
euid = _geteuid()
|
||||||
return [{
|
return [{
|
||||||
'contents': username,
|
'contents': username,
|
||||||
'highlight_group': 'user' if euid != 0 else ['superuser', 'user'],
|
'highlight_group': ['user'] if euid != 0 else ['superuser', 'user'],
|
||||||
}]
|
}]
|
||||||
if 'psutil' not in globals():
|
if 'psutil' not in globals():
|
||||||
user = requires_segment_info(user)
|
user = requires_segment_info(user)
|
||||||
@ -966,7 +966,7 @@ class EmailIMAPSegment(KwThreadedSegment):
|
|||||||
elif type(unread_count) != int or not max_msgs:
|
elif type(unread_count) != int or not max_msgs:
|
||||||
return [{
|
return [{
|
||||||
'contents': str(unread_count),
|
'contents': str(unread_count),
|
||||||
'highlight_group': 'email_alert',
|
'highlight_group': ['email_alert'],
|
||||||
}]
|
}]
|
||||||
else:
|
else:
|
||||||
return [{
|
return [{
|
||||||
|
@ -29,7 +29,7 @@ def last_status(pl, segment_info):
|
|||||||
'''
|
'''
|
||||||
if not segment_info['args'].last_exit_code:
|
if not segment_info['args'].last_exit_code:
|
||||||
return None
|
return None
|
||||||
return [{'contents': str(segment_info['args'].last_exit_code), 'highlight_group': 'exit_fail'}]
|
return [{'contents': str(segment_info['args'].last_exit_code), 'highlight_group': ['exit_fail']}]
|
||||||
|
|
||||||
|
|
||||||
@requires_segment_info
|
@requires_segment_info
|
||||||
@ -40,8 +40,14 @@ def last_pipe_status(pl, segment_info):
|
|||||||
'''
|
'''
|
||||||
last_pipe_status = segment_info['args'].last_pipe_status
|
last_pipe_status = segment_info['args'].last_pipe_status
|
||||||
if any(last_pipe_status):
|
if any(last_pipe_status):
|
||||||
return [{'contents': str(status), 'highlight_group': 'exit_fail' if status else 'exit_success', 'draw_inner_divider': True}
|
return [
|
||||||
for status in last_pipe_status]
|
{
|
||||||
|
'contents': str(status),
|
||||||
|
'highlight_group': ['exit_fail' if status else 'exit_success'],
|
||||||
|
'draw_inner_divider': True
|
||||||
|
}
|
||||||
|
for status in last_pipe_status
|
||||||
|
]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -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
|
||||||
@ -585,7 +584,7 @@ def trailing_whitespace(pl, segment_info):
|
|||||||
|
|
||||||
|
|
||||||
@requires_segment_info
|
@requires_segment_info
|
||||||
def tabnr(pl, segment_info, show_current=False):
|
def tabnr(pl, segment_info, show_current=True):
|
||||||
'''Show tabpage number
|
'''Show tabpage number
|
||||||
|
|
||||||
:param bool show_current:
|
:param bool show_current:
|
||||||
@ -601,7 +600,7 @@ def tabnr(pl, segment_info, show_current=False):
|
|||||||
|
|
||||||
|
|
||||||
@requires_segment_info
|
@requires_segment_info
|
||||||
def bufnr(pl, segment_info, show_current=False):
|
def bufnr(pl, segment_info, show_current=True):
|
||||||
'''Show buffer number
|
'''Show buffer number
|
||||||
|
|
||||||
:param bool show_current:
|
:param bool show_current:
|
||||||
@ -613,7 +612,7 @@ def bufnr(pl, segment_info, show_current=False):
|
|||||||
|
|
||||||
|
|
||||||
@requires_segment_info
|
@requires_segment_info
|
||||||
def winnr(pl, segment_info, show_current=False):
|
def winnr(pl, segment_info, show_current=True):
|
||||||
'''Show window number
|
'''Show window number
|
||||||
|
|
||||||
:param bool show_current:
|
:param bool show_current:
|
||||||
@ -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
|
@ -135,10 +135,7 @@ class Theme(object):
|
|||||||
for side in [side] if side else ['left', 'right']:
|
for side in [side] if side else ['left', 'right']:
|
||||||
parsed_segments = []
|
parsed_segments = []
|
||||||
for segment in self.segments[line][side]:
|
for segment in self.segments[line][side]:
|
||||||
# No segment-local modes at this point
|
if segment['display_condition'](self.pl, segment_info, mode):
|
||||||
if mode not in segment['exclude_modes'] and (
|
|
||||||
not segment['include_modes'] or mode in segment['include_modes']
|
|
||||||
):
|
|
||||||
process_segment(
|
process_segment(
|
||||||
self.pl,
|
self.pl,
|
||||||
side,
|
side,
|
||||||
|
@ -11,7 +11,7 @@ import tests.vim as vim_module
|
|||||||
|
|
||||||
from tests import TestCase
|
from tests import TestCase
|
||||||
from tests.lib.config_mock import get_powerline, get_powerline_raw, swap_attributes
|
from tests.lib.config_mock import get_powerline, get_powerline_raw, swap_attributes
|
||||||
from tests.lib import Args
|
from tests.lib import Args, replace_item
|
||||||
|
|
||||||
|
|
||||||
def highlighted_string(s, group, **kwargs):
|
def highlighted_string(s, group, **kwargs):
|
||||||
@ -389,7 +389,7 @@ class TestThemeHierarchy(TestRender):
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
class TestModes(TestRender):
|
class TestDisplayCondition(TestRender):
|
||||||
@add_args
|
@add_args
|
||||||
def test_include_modes(self, p, config):
|
def test_include_modes(self, p, config):
|
||||||
config['themes/test/default']['segments'] = {
|
config['themes/test/default']['segments'] = {
|
||||||
@ -432,13 +432,93 @@ class TestModes(TestRender):
|
|||||||
self.assertRenderEqual(p, '{56} s1{6-}>>{--}', mode='m2')
|
self.assertRenderEqual(p, '{56} s1{6-}>>{--}', mode='m2')
|
||||||
self.assertRenderEqual(p, '{56} s2{6-}>>{--}', mode='m3')
|
self.assertRenderEqual(p, '{56} s2{6-}>>{--}', mode='m3')
|
||||||
|
|
||||||
|
@add_args
|
||||||
|
def test_exinclude_function_nonexistent_module(self, p, config):
|
||||||
|
config['themes/test/default']['segments'] = {
|
||||||
|
'left': [
|
||||||
|
highlighted_string('s1', 'g1', exclude_function='xxx_nonexistent_module.foo'),
|
||||||
|
highlighted_string('s2', 'g1', exclude_function='xxx_nonexistent_module.foo', include_function='xxx_nonexistent_module.bar'),
|
||||||
|
highlighted_string('s3', 'g1', include_function='xxx_nonexistent_module.bar'),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
self.assertRenderEqual(p, '{56} s1{56}>{56}s2{56}>{56}s3{6-}>>{--}')
|
||||||
|
|
||||||
|
@add_args
|
||||||
|
def test_exinclude_function(self, p, config):
|
||||||
|
config['themes/test/default']['segments'] = {
|
||||||
|
'left': [
|
||||||
|
highlighted_string('s1', 'g1', exclude_function='mod.foo'),
|
||||||
|
highlighted_string('s2', 'g1', exclude_function='mod.foo', include_function='mod.bar'),
|
||||||
|
highlighted_string('s3', 'g1', include_function='mod.bar'),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
launched = set()
|
||||||
|
fool = [None]
|
||||||
|
barl = [None]
|
||||||
|
|
||||||
|
def foo(*args, **kwargs):
|
||||||
|
launched.add('foo')
|
||||||
|
self.assertEqual(set(kwargs.keys()), set(('pl', 'segment_info', 'mode')))
|
||||||
|
self.assertEqual(args, ())
|
||||||
|
return fool[0]
|
||||||
|
|
||||||
|
def bar(*args, **kwargs):
|
||||||
|
launched.add('bar')
|
||||||
|
self.assertEqual(set(kwargs.keys()), set(('pl', 'segment_info', 'mode')))
|
||||||
|
self.assertEqual(args, ())
|
||||||
|
return barl[0]
|
||||||
|
|
||||||
|
with replace_item(sys.modules, 'mod', Args(foo=foo, bar=bar)):
|
||||||
|
fool[0] = True
|
||||||
|
barl[0] = True
|
||||||
|
self.assertRenderEqual(p, '{56} s3{6-}>>{--}')
|
||||||
|
self.assertEqual(launched, set(('foo', 'bar')))
|
||||||
|
|
||||||
|
fool[0] = False
|
||||||
|
barl[0] = True
|
||||||
|
self.assertRenderEqual(p, '{56} s1{56}>{56}s2{56}>{56}s3{6-}>>{--}')
|
||||||
|
self.assertEqual(launched, set(('foo', 'bar')))
|
||||||
|
|
||||||
|
fool[0] = False
|
||||||
|
barl[0] = False
|
||||||
|
self.assertRenderEqual(p, '{56} s1{6-}>>{--}')
|
||||||
|
self.assertEqual(launched, set(('foo', 'bar')))
|
||||||
|
|
||||||
|
fool[0] = True
|
||||||
|
barl[0] = False
|
||||||
|
self.assertRenderEqual(p, '{--}')
|
||||||
|
self.assertEqual(launched, set(('foo', 'bar')))
|
||||||
|
|
||||||
|
@add_args
|
||||||
|
def test_exinclude_modes_override_functions(self, p, config):
|
||||||
|
config['themes/test/default']['segments'] = {
|
||||||
|
'left': [
|
||||||
|
highlighted_string('s1', 'g1', exclude_function='mod.foo', exclude_modes=['m2']),
|
||||||
|
highlighted_string('s2', 'g1', exclude_function='mod.foo', include_modes=['m2']),
|
||||||
|
highlighted_string('s3', 'g1', include_function='mod.foo', exclude_modes=['m2']),
|
||||||
|
highlighted_string('s4', 'g1', include_function='mod.foo', include_modes=['m2']),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
fool = [None]
|
||||||
|
|
||||||
|
def foo(*args, **kwargs):
|
||||||
|
return fool[0]
|
||||||
|
|
||||||
|
with replace_item(sys.modules, 'mod', Args(foo=foo)):
|
||||||
|
fool[0] = True
|
||||||
|
self.assertRenderEqual(p, '{56} s4{6-}>>{--}', mode='m2')
|
||||||
|
self.assertRenderEqual(p, '{56} s3{56}>{56}s4{6-}>>{--}', mode='m1')
|
||||||
|
|
||||||
|
fool[0] = False
|
||||||
|
self.assertRenderEqual(p, '{56} s2{56}>{56}s4{6-}>>{--}', mode='m2')
|
||||||
|
self.assertRenderEqual(p, '{56} s1{6-}>>{--}', mode='m1')
|
||||||
|
|
||||||
|
|
||||||
class TestSegmentAttributes(TestRender):
|
class TestSegmentAttributes(TestRender):
|
||||||
@add_args
|
@add_args
|
||||||
def test_no_attributes(self, p, config):
|
def test_no_attributes(self, p, config):
|
||||||
def m1(divider=',', **kwargs):
|
def m1(divider=',', **kwargs):
|
||||||
return divider.join(kwargs.keys()) + divider
|
return divider.join(kwargs.keys()) + divider
|
||||||
sys.modules['bar'] = Args(m1=m1)
|
|
||||||
config['themes/test/default']['segments'] = {
|
config['themes/test/default']['segments'] = {
|
||||||
'left': [
|
'left': [
|
||||||
{
|
{
|
||||||
@ -446,7 +526,8 @@ class TestSegmentAttributes(TestRender):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
self.assertRenderEqual(p, '{56} pl,{6-}>>{--}')
|
with replace_item(sys.modules, 'bar', Args(m1=m1)):
|
||||||
|
self.assertRenderEqual(p, '{56} pl,{6-}>>{--}')
|
||||||
|
|
||||||
@add_args
|
@add_args
|
||||||
def test_segment_datas(self, p, config):
|
def test_segment_datas(self, p, config):
|
||||||
@ -464,7 +545,6 @@ class TestSegmentAttributes(TestRender):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sys.modules['bar'] = Args(m1=m1)
|
|
||||||
config['themes/test/default']['segments'] = {
|
config['themes/test/default']['segments'] = {
|
||||||
'left': [
|
'left': [
|
||||||
{
|
{
|
||||||
@ -472,7 +552,8 @@ class TestSegmentAttributes(TestRender):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
self.assertRenderEqual(p, '{56} pl;{6-}>>{--}')
|
with replace_item(sys.modules, 'bar', Args(m1=m1)):
|
||||||
|
self.assertRenderEqual(p, '{56} pl;{6-}>>{--}')
|
||||||
|
|
||||||
@add_args
|
@add_args
|
||||||
def test_expand(self, p, config):
|
def test_expand(self, p, config):
|
||||||
@ -483,7 +564,6 @@ class TestSegmentAttributes(TestRender):
|
|||||||
return ('-' * amount) + segment['contents']
|
return ('-' * amount) + segment['contents']
|
||||||
|
|
||||||
m1.expand = expand
|
m1.expand = expand
|
||||||
sys.modules['bar'] = Args(m1=m1)
|
|
||||||
config['themes/test/default']['segments'] = {
|
config['themes/test/default']['segments'] = {
|
||||||
'left': [
|
'left': [
|
||||||
{
|
{
|
||||||
@ -492,7 +572,8 @@ class TestSegmentAttributes(TestRender):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
self.assertRenderEqual(p, '{56} ----pl,{6-}>>{--}', width=10)
|
with replace_item(sys.modules, 'bar', Args(m1=m1)):
|
||||||
|
self.assertRenderEqual(p, '{56} ----pl,{6-}>>{--}', width=10)
|
||||||
|
|
||||||
@add_args
|
@add_args
|
||||||
def test_truncate(self, p, config):
|
def test_truncate(self, p, config):
|
||||||
@ -503,7 +584,6 @@ class TestSegmentAttributes(TestRender):
|
|||||||
return segment['contents'][:-amount]
|
return segment['contents'][:-amount]
|
||||||
|
|
||||||
m1.truncate = truncate
|
m1.truncate = truncate
|
||||||
sys.modules['bar'] = Args(m1=m1)
|
|
||||||
config['themes/test/default']['segments'] = {
|
config['themes/test/default']['segments'] = {
|
||||||
'left': [
|
'left': [
|
||||||
{
|
{
|
||||||
@ -511,7 +591,8 @@ class TestSegmentAttributes(TestRender):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
self.assertRenderEqual(p, '{56} p{6-}>>{--}', width=4)
|
with replace_item(sys.modules, 'bar', Args(m1=m1)):
|
||||||
|
self.assertRenderEqual(p, '{56} p{6-}>>{--}', width=4)
|
||||||
|
|
||||||
|
|
||||||
class TestSegmentData(TestRender):
|
class TestSegmentData(TestRender):
|
||||||
@ -603,13 +684,13 @@ class TestVim(TestCase):
|
|||||||
winnr = window.number
|
winnr = window.number
|
||||||
self.assertEqual(powerline.render(window, window_id, winnr), '%#Pl_5_12583104_6_32896_NONE#\xa0\u201cbar\u201d%#Pl_6_32896_NONE_None_NONE#>>')
|
self.assertEqual(powerline.render(window, window_id, winnr), '%#Pl_5_12583104_6_32896_NONE#\xa0\u201cbar\u201d%#Pl_6_32896_NONE_None_NONE#>>')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'path')))
|
||||||
|
|
||||||
def setUpModule():
|
@classmethod
|
||||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'path')))
|
def tearDownClass(cls):
|
||||||
|
sys.path.pop(0)
|
||||||
|
|
||||||
def tearDownModule():
|
|
||||||
sys.path.pop(0)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -18,7 +18,7 @@ VBLOCK = chr(ord('V') - 0x40)
|
|||||||
SBLOCK = chr(ord('S') - 0x40)
|
SBLOCK = chr(ord('S') - 0x40)
|
||||||
|
|
||||||
|
|
||||||
class TestConfig(TestCase):
|
class TestVimConfig(TestCase):
|
||||||
def test_vim(self):
|
def test_vim(self):
|
||||||
from powerline.vim import VimPowerline
|
from powerline.vim import VimPowerline
|
||||||
cfg_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'powerline', 'config_files')
|
cfg_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'powerline', 'config_files')
|
||||||
@ -76,6 +76,16 @@ class TestConfig(TestCase):
|
|||||||
finally:
|
finally:
|
||||||
vim_module._start_mode('n')
|
vim_module._start_mode('n')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'path')))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDownClass(cls):
|
||||||
|
sys.path.pop(0)
|
||||||
|
|
||||||
|
|
||||||
|
class TestConfig(TestCase):
|
||||||
def test_tmux(self):
|
def test_tmux(self):
|
||||||
from powerline.segments import common
|
from powerline.segments import common
|
||||||
from imp import reload
|
from imp import reload
|
||||||
@ -151,10 +161,7 @@ def setUpModule():
|
|||||||
saved_get_config_paths = powerline.get_config_paths
|
saved_get_config_paths = powerline.get_config_paths
|
||||||
path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'powerline', 'config_files')
|
path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'powerline', 'config_files')
|
||||||
powerline.get_config_paths = lambda: [path]
|
powerline.get_config_paths = lambda: [path]
|
||||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'path')))
|
|
||||||
old_cwd = os.getcwd()
|
old_cwd = os.getcwd()
|
||||||
from powerline.segments import vim
|
|
||||||
globals()['vim'] = vim
|
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
@ -164,7 +171,6 @@ def tearDownModule():
|
|||||||
powerline.get_config_paths = saved_get_config_paths
|
powerline.get_config_paths = saved_get_config_paths
|
||||||
os.chdir(old_cwd)
|
os.chdir(old_cwd)
|
||||||
old_cwd = None
|
old_cwd = None
|
||||||
sys.path.pop(0)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -15,9 +15,6 @@ from tests.lib import Args, urllib_read, replace_attr, new_module, replace_modul
|
|||||||
from tests import TestCase, SkipTest
|
from tests import TestCase, SkipTest
|
||||||
|
|
||||||
|
|
||||||
vim = None
|
|
||||||
|
|
||||||
|
|
||||||
def get_dummy_guess(**kwargs):
|
def get_dummy_guess(**kwargs):
|
||||||
if 'directory' in kwargs:
|
if 'directory' in kwargs:
|
||||||
def guess(path, create_watcher):
|
def guess(path, create_watcher):
|
||||||
@ -33,7 +30,7 @@ class TestShell(TestCase):
|
|||||||
pl = Pl()
|
pl = Pl()
|
||||||
segment_info = {'args': Args(last_exit_code=10)}
|
segment_info = {'args': Args(last_exit_code=10)}
|
||||||
self.assertEqual(shell.last_status(pl=pl, segment_info=segment_info), [
|
self.assertEqual(shell.last_status(pl=pl, segment_info=segment_info), [
|
||||||
{'contents': '10', 'highlight_group': 'exit_fail'}
|
{'contents': '10', 'highlight_group': ['exit_fail']}
|
||||||
])
|
])
|
||||||
segment_info['args'].last_exit_code = 0
|
segment_info['args'].last_exit_code = 0
|
||||||
self.assertEqual(shell.last_status(pl=pl, segment_info=segment_info), None)
|
self.assertEqual(shell.last_status(pl=pl, segment_info=segment_info), None)
|
||||||
@ -48,9 +45,9 @@ class TestShell(TestCase):
|
|||||||
self.assertEqual(shell.last_pipe_status(pl=pl, segment_info=segment_info), None)
|
self.assertEqual(shell.last_pipe_status(pl=pl, segment_info=segment_info), None)
|
||||||
segment_info['args'].last_pipe_status = [0, 2, 0]
|
segment_info['args'].last_pipe_status = [0, 2, 0]
|
||||||
self.assertEqual(shell.last_pipe_status(pl=pl, segment_info=segment_info), [
|
self.assertEqual(shell.last_pipe_status(pl=pl, segment_info=segment_info), [
|
||||||
{'contents': '0', 'highlight_group': 'exit_success', 'draw_inner_divider': True},
|
{'contents': '0', 'highlight_group': ['exit_success'], 'draw_inner_divider': True},
|
||||||
{'contents': '2', 'highlight_group': 'exit_fail', 'draw_inner_divider': True},
|
{'contents': '2', 'highlight_group': ['exit_fail'], 'draw_inner_divider': True},
|
||||||
{'contents': '0', 'highlight_group': 'exit_success', 'draw_inner_divider': True}
|
{'contents': '0', 'highlight_group': ['exit_success'], 'draw_inner_divider': True}
|
||||||
])
|
])
|
||||||
|
|
||||||
def test_jobnum(self):
|
def test_jobnum(self):
|
||||||
@ -338,10 +335,10 @@ class TestCommon(TestCase):
|
|||||||
with replace_attr(common, 'psutil', new_psutil):
|
with replace_attr(common, 'psutil', new_psutil):
|
||||||
with replace_attr(common, '_geteuid', lambda: 5):
|
with replace_attr(common, '_geteuid', lambda: 5):
|
||||||
self.assertEqual(common.user(pl=pl, segment_info=segment_info), [
|
self.assertEqual(common.user(pl=pl, segment_info=segment_info), [
|
||||||
{'contents': 'def', 'highlight_group': 'user'}
|
{'contents': 'def', 'highlight_group': ['user']}
|
||||||
])
|
])
|
||||||
self.assertEqual(common.user(pl=pl, segment_info=segment_info, hide_user='abc'), [
|
self.assertEqual(common.user(pl=pl, segment_info=segment_info, hide_user='abc'), [
|
||||||
{'contents': 'def', 'highlight_group': 'user'}
|
{'contents': 'def', 'highlight_group': ['user']}
|
||||||
])
|
])
|
||||||
self.assertEqual(common.user(pl=pl, segment_info=segment_info, hide_user='def'), None)
|
self.assertEqual(common.user(pl=pl, segment_info=segment_info, hide_user='def'), None)
|
||||||
with replace_attr(common, '_geteuid', lambda: 0):
|
with replace_attr(common, '_geteuid', lambda: 0):
|
||||||
@ -781,18 +778,18 @@ class TestVim(TestCase):
|
|||||||
def test_mode(self):
|
def test_mode(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
segment_info = vim_module._get_segment_info()
|
segment_info = vim_module._get_segment_info()
|
||||||
self.assertEqual(vim.mode(pl=pl, segment_info=segment_info), 'NORMAL')
|
self.assertEqual(self.vim.mode(pl=pl, segment_info=segment_info), 'NORMAL')
|
||||||
self.assertEqual(vim.mode(pl=pl, segment_info=segment_info, override={'i': 'INS'}), 'NORMAL')
|
self.assertEqual(self.vim.mode(pl=pl, segment_info=segment_info, override={'i': 'INS'}), 'NORMAL')
|
||||||
self.assertEqual(vim.mode(pl=pl, segment_info=segment_info, override={'n': 'NORM'}), 'NORM')
|
self.assertEqual(self.vim.mode(pl=pl, segment_info=segment_info, override={'n': 'NORM'}), 'NORM')
|
||||||
with vim_module._with('mode', 'i') as segment_info:
|
with vim_module._with('mode', 'i') as segment_info:
|
||||||
self.assertEqual(vim.mode(pl=pl, segment_info=segment_info), 'INSERT')
|
self.assertEqual(self.vim.mode(pl=pl, segment_info=segment_info), 'INSERT')
|
||||||
with vim_module._with('mode', chr(ord('V') - 0x40)) as segment_info:
|
with vim_module._with('mode', chr(ord('V') - 0x40)) as segment_info:
|
||||||
self.assertEqual(vim.mode(pl=pl, segment_info=segment_info), 'V-BLCK')
|
self.assertEqual(self.vim.mode(pl=pl, segment_info=segment_info), 'V-BLCK')
|
||||||
self.assertEqual(vim.mode(pl=pl, segment_info=segment_info, override={'^V': 'VBLK'}), 'VBLK')
|
self.assertEqual(self.vim.mode(pl=pl, segment_info=segment_info, override={'^V': 'VBLK'}), 'VBLK')
|
||||||
|
|
||||||
def test_visual_range(self):
|
def test_visual_range(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
vr = partial(vim.visual_range, pl=pl)
|
vr = partial(self.vim.visual_range, pl=pl)
|
||||||
vim_module.current.window.cursor = [0, 0]
|
vim_module.current.window.cursor = [0, 0]
|
||||||
try:
|
try:
|
||||||
with vim_module._with('mode', 'i') as segment_info:
|
with vim_module._with('mode', 'i') as segment_info:
|
||||||
@ -839,116 +836,116 @@ class TestVim(TestCase):
|
|||||||
def test_modified_indicator(self):
|
def test_modified_indicator(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
segment_info = vim_module._get_segment_info()
|
segment_info = vim_module._get_segment_info()
|
||||||
self.assertEqual(vim.modified_indicator(pl=pl, segment_info=segment_info), None)
|
self.assertEqual(self.vim.modified_indicator(pl=pl, segment_info=segment_info), None)
|
||||||
segment_info['buffer'][0] = 'abc'
|
segment_info['buffer'][0] = 'abc'
|
||||||
try:
|
try:
|
||||||
self.assertEqual(vim.modified_indicator(pl=pl, segment_info=segment_info), '+')
|
self.assertEqual(self.vim.modified_indicator(pl=pl, segment_info=segment_info), '+')
|
||||||
self.assertEqual(vim.modified_indicator(pl=pl, segment_info=segment_info, text='-'), '-')
|
self.assertEqual(self.vim.modified_indicator(pl=pl, segment_info=segment_info, text='-'), '-')
|
||||||
finally:
|
finally:
|
||||||
vim_module._bw(segment_info['bufnr'])
|
vim_module._bw(segment_info['bufnr'])
|
||||||
|
|
||||||
def test_paste_indicator(self):
|
def test_paste_indicator(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
segment_info = vim_module._get_segment_info()
|
segment_info = vim_module._get_segment_info()
|
||||||
self.assertEqual(vim.paste_indicator(pl=pl, segment_info=segment_info), None)
|
self.assertEqual(self.vim.paste_indicator(pl=pl, segment_info=segment_info), None)
|
||||||
with vim_module._with('options', paste=1):
|
with vim_module._with('options', paste=1):
|
||||||
self.assertEqual(vim.paste_indicator(pl=pl, segment_info=segment_info), 'PASTE')
|
self.assertEqual(self.vim.paste_indicator(pl=pl, segment_info=segment_info), 'PASTE')
|
||||||
self.assertEqual(vim.paste_indicator(pl=pl, segment_info=segment_info, text='P'), 'P')
|
self.assertEqual(self.vim.paste_indicator(pl=pl, segment_info=segment_info, text='P'), 'P')
|
||||||
|
|
||||||
def test_readonly_indicator(self):
|
def test_readonly_indicator(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
segment_info = vim_module._get_segment_info()
|
segment_info = vim_module._get_segment_info()
|
||||||
self.assertEqual(vim.readonly_indicator(pl=pl, segment_info=segment_info), None)
|
self.assertEqual(self.vim.readonly_indicator(pl=pl, segment_info=segment_info), None)
|
||||||
with vim_module._with('bufoptions', readonly=1):
|
with vim_module._with('bufoptions', readonly=1):
|
||||||
self.assertEqual(vim.readonly_indicator(pl=pl, segment_info=segment_info), 'RO')
|
self.assertEqual(self.vim.readonly_indicator(pl=pl, segment_info=segment_info), 'RO')
|
||||||
self.assertEqual(vim.readonly_indicator(pl=pl, segment_info=segment_info, text='L'), 'L')
|
self.assertEqual(self.vim.readonly_indicator(pl=pl, segment_info=segment_info, text='L'), 'L')
|
||||||
|
|
||||||
def test_file_scheme(self):
|
def test_file_scheme(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
segment_info = vim_module._get_segment_info()
|
segment_info = vim_module._get_segment_info()
|
||||||
self.assertEqual(vim.file_scheme(pl=pl, segment_info=segment_info), None)
|
self.assertEqual(self.vim.file_scheme(pl=pl, segment_info=segment_info), None)
|
||||||
with vim_module._with('buffer', '/tmp/’’/abc') as segment_info:
|
with vim_module._with('buffer', '/tmp/’’/abc') as segment_info:
|
||||||
self.assertEqual(vim.file_scheme(pl=pl, segment_info=segment_info), None)
|
self.assertEqual(self.vim.file_scheme(pl=pl, segment_info=segment_info), None)
|
||||||
with vim_module._with('buffer', 'zipfile:/tmp/abc.zip::abc/abc.vim') as segment_info:
|
with vim_module._with('buffer', 'zipfile:/tmp/abc.zip::abc/abc.vim') as segment_info:
|
||||||
self.assertEqual(vim.file_scheme(pl=pl, segment_info=segment_info), 'zipfile')
|
self.assertEqual(self.vim.file_scheme(pl=pl, segment_info=segment_info), 'zipfile')
|
||||||
|
|
||||||
def test_file_directory(self):
|
def test_file_directory(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
segment_info = vim_module._get_segment_info()
|
segment_info = vim_module._get_segment_info()
|
||||||
self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info), None)
|
self.assertEqual(self.vim.file_directory(pl=pl, segment_info=segment_info), None)
|
||||||
with replace_env('HOME', '/home/foo', os.environ):
|
with replace_env('HOME', '/home/foo', os.environ):
|
||||||
with vim_module._with('buffer', '/tmp/’’/abc') as segment_info:
|
with vim_module._with('buffer', '/tmp/’’/abc') as segment_info:
|
||||||
self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info), '/tmp/’’/')
|
self.assertEqual(self.vim.file_directory(pl=pl, segment_info=segment_info), '/tmp/’’/')
|
||||||
with vim_module._with('buffer', b'/tmp/\xFF\xFF/abc') as segment_info:
|
with vim_module._with('buffer', b'/tmp/\xFF\xFF/abc') as segment_info:
|
||||||
self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info), '/tmp/<ff><ff>/')
|
self.assertEqual(self.vim.file_directory(pl=pl, segment_info=segment_info), '/tmp/<ff><ff>/')
|
||||||
with vim_module._with('buffer', '/tmp/abc') as segment_info:
|
with vim_module._with('buffer', '/tmp/abc') as segment_info:
|
||||||
self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info), '/tmp/')
|
self.assertEqual(self.vim.file_directory(pl=pl, segment_info=segment_info), '/tmp/')
|
||||||
os.environ['HOME'] = '/tmp'
|
os.environ['HOME'] = '/tmp'
|
||||||
self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info), '~/')
|
self.assertEqual(self.vim.file_directory(pl=pl, segment_info=segment_info), '~/')
|
||||||
with vim_module._with('buffer', 'zipfile:/tmp/abc.zip::abc/abc.vim') as segment_info:
|
with vim_module._with('buffer', 'zipfile:/tmp/abc.zip::abc/abc.vim') as segment_info:
|
||||||
self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info, remove_scheme=False), 'zipfile:/tmp/abc.zip::abc/')
|
self.assertEqual(self.vim.file_directory(pl=pl, segment_info=segment_info, remove_scheme=False), 'zipfile:/tmp/abc.zip::abc/')
|
||||||
self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info, remove_scheme=True), '/tmp/abc.zip::abc/')
|
self.assertEqual(self.vim.file_directory(pl=pl, segment_info=segment_info, remove_scheme=True), '/tmp/abc.zip::abc/')
|
||||||
self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info), '/tmp/abc.zip::abc/')
|
self.assertEqual(self.vim.file_directory(pl=pl, segment_info=segment_info), '/tmp/abc.zip::abc/')
|
||||||
os.environ['HOME'] = '/tmp'
|
os.environ['HOME'] = '/tmp'
|
||||||
self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info, remove_scheme=False), 'zipfile:/tmp/abc.zip::abc/')
|
self.assertEqual(self.vim.file_directory(pl=pl, segment_info=segment_info, remove_scheme=False), 'zipfile:/tmp/abc.zip::abc/')
|
||||||
self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info, remove_scheme=True), '/tmp/abc.zip::abc/')
|
self.assertEqual(self.vim.file_directory(pl=pl, segment_info=segment_info, remove_scheme=True), '/tmp/abc.zip::abc/')
|
||||||
self.assertEqual(vim.file_directory(pl=pl, segment_info=segment_info), '/tmp/abc.zip::abc/')
|
self.assertEqual(self.vim.file_directory(pl=pl, segment_info=segment_info), '/tmp/abc.zip::abc/')
|
||||||
|
|
||||||
def test_file_name(self):
|
def test_file_name(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
segment_info = vim_module._get_segment_info()
|
segment_info = vim_module._get_segment_info()
|
||||||
self.assertEqual(vim.file_name(pl=pl, segment_info=segment_info), None)
|
self.assertEqual(self.vim.file_name(pl=pl, segment_info=segment_info), None)
|
||||||
self.assertEqual(vim.file_name(pl=pl, segment_info=segment_info, display_no_file=True), [
|
self.assertEqual(self.vim.file_name(pl=pl, segment_info=segment_info, display_no_file=True), [
|
||||||
{'contents': '[No file]', 'highlight_group': ['file_name_no_file', 'file_name']}
|
{'contents': '[No file]', 'highlight_group': ['file_name_no_file', 'file_name']}
|
||||||
])
|
])
|
||||||
self.assertEqual(vim.file_name(pl=pl, segment_info=segment_info, display_no_file=True, no_file_text='X'), [
|
self.assertEqual(self.vim.file_name(pl=pl, segment_info=segment_info, display_no_file=True, no_file_text='X'), [
|
||||||
{'contents': 'X', 'highlight_group': ['file_name_no_file', 'file_name']}
|
{'contents': 'X', 'highlight_group': ['file_name_no_file', 'file_name']}
|
||||||
])
|
])
|
||||||
with vim_module._with('buffer', '/tmp/abc') as segment_info:
|
with vim_module._with('buffer', '/tmp/abc') as segment_info:
|
||||||
self.assertEqual(vim.file_name(pl=pl, segment_info=segment_info), 'abc')
|
self.assertEqual(self.vim.file_name(pl=pl, segment_info=segment_info), 'abc')
|
||||||
with vim_module._with('buffer', '/tmp/’’') as segment_info:
|
with vim_module._with('buffer', '/tmp/’’') as segment_info:
|
||||||
self.assertEqual(vim.file_name(pl=pl, segment_info=segment_info), '’’')
|
self.assertEqual(self.vim.file_name(pl=pl, segment_info=segment_info), '’’')
|
||||||
with vim_module._with('buffer', b'/tmp/\xFF\xFF') as segment_info:
|
with vim_module._with('buffer', b'/tmp/\xFF\xFF') as segment_info:
|
||||||
self.assertEqual(vim.file_name(pl=pl, segment_info=segment_info), '<ff><ff>')
|
self.assertEqual(self.vim.file_name(pl=pl, segment_info=segment_info), '<ff><ff>')
|
||||||
|
|
||||||
def test_file_size(self):
|
def test_file_size(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
segment_info = vim_module._get_segment_info()
|
segment_info = vim_module._get_segment_info()
|
||||||
self.assertEqual(vim.file_size(pl=pl, segment_info=segment_info), '0 B')
|
self.assertEqual(self.vim.file_size(pl=pl, segment_info=segment_info), '0 B')
|
||||||
with vim_module._with('buffer', os.path.join(os.path.dirname(__file__), 'empty')) as segment_info:
|
with vim_module._with('buffer', os.path.join(os.path.dirname(__file__), 'empty')) as segment_info:
|
||||||
self.assertEqual(vim.file_size(pl=pl, segment_info=segment_info), '0 B')
|
self.assertEqual(self.vim.file_size(pl=pl, segment_info=segment_info), '0 B')
|
||||||
|
|
||||||
def test_file_opts(self):
|
def test_file_opts(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
segment_info = vim_module._get_segment_info()
|
segment_info = vim_module._get_segment_info()
|
||||||
self.assertEqual(vim.file_format(pl=pl, segment_info=segment_info), [
|
self.assertEqual(self.vim.file_format(pl=pl, segment_info=segment_info), [
|
||||||
{'divider_highlight_group': 'background:divider', 'contents': 'unix'}
|
{'divider_highlight_group': 'background:divider', 'contents': 'unix'}
|
||||||
])
|
])
|
||||||
self.assertEqual(vim.file_encoding(pl=pl, segment_info=segment_info), [
|
self.assertEqual(self.vim.file_encoding(pl=pl, segment_info=segment_info), [
|
||||||
{'divider_highlight_group': 'background:divider', 'contents': 'utf-8'}
|
{'divider_highlight_group': 'background:divider', 'contents': 'utf-8'}
|
||||||
])
|
])
|
||||||
self.assertEqual(vim.file_type(pl=pl, segment_info=segment_info), None)
|
self.assertEqual(self.vim.file_type(pl=pl, segment_info=segment_info), None)
|
||||||
with vim_module._with('bufoptions', filetype='python'):
|
with vim_module._with('bufoptions', filetype='python'):
|
||||||
self.assertEqual(vim.file_type(pl=pl, segment_info=segment_info), [
|
self.assertEqual(self.vim.file_type(pl=pl, segment_info=segment_info), [
|
||||||
{'divider_highlight_group': 'background:divider', 'contents': 'python'}
|
{'divider_highlight_group': 'background:divider', 'contents': 'python'}
|
||||||
])
|
])
|
||||||
|
|
||||||
def test_window_title(self):
|
def test_window_title(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
segment_info = vim_module._get_segment_info()
|
segment_info = vim_module._get_segment_info()
|
||||||
self.assertEqual(vim.window_title(pl=pl, segment_info=segment_info), None)
|
self.assertEqual(self.vim.window_title(pl=pl, segment_info=segment_info), None)
|
||||||
with vim_module._with('wvars', quickfix_title='Abc'):
|
with vim_module._with('wvars', quickfix_title='Abc'):
|
||||||
self.assertEqual(vim.window_title(pl=pl, segment_info=segment_info), 'Abc')
|
self.assertEqual(self.vim.window_title(pl=pl, segment_info=segment_info), 'Abc')
|
||||||
|
|
||||||
def test_line_percent(self):
|
def test_line_percent(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
segment_info = vim_module._get_segment_info()
|
segment_info = vim_module._get_segment_info()
|
||||||
segment_info['buffer'][0:-1] = [str(i) for i in range(100)]
|
segment_info['buffer'][0:-1] = [str(i) for i in range(100)]
|
||||||
try:
|
try:
|
||||||
self.assertEqual(vim.line_percent(pl=pl, segment_info=segment_info), '1')
|
self.assertEqual(self.vim.line_percent(pl=pl, segment_info=segment_info), '1')
|
||||||
vim_module._set_cursor(50, 0)
|
vim_module._set_cursor(50, 0)
|
||||||
self.assertEqual(vim.line_percent(pl=pl, segment_info=segment_info), '50')
|
self.assertEqual(self.vim.line_percent(pl=pl, segment_info=segment_info), '50')
|
||||||
self.assertEqual(vim.line_percent(pl=pl, segment_info=segment_info, gradient=True), [
|
self.assertEqual(self.vim.line_percent(pl=pl, segment_info=segment_info, gradient=True), [
|
||||||
{'contents': '50', 'highlight_group': ['line_percent_gradient', 'line_percent'], 'gradient_level': 50 * 100.0 / 101}
|
{'contents': '50', 'highlight_group': ['line_percent_gradient', 'line_percent'], 'gradient_level': 50 * 100.0 / 101}
|
||||||
])
|
])
|
||||||
finally:
|
finally:
|
||||||
@ -959,9 +956,9 @@ class TestVim(TestCase):
|
|||||||
segment_info = vim_module._get_segment_info()
|
segment_info = vim_module._get_segment_info()
|
||||||
segment_info['buffer'][0:-1] = [str(i) for i in range(99)]
|
segment_info['buffer'][0:-1] = [str(i) for i in range(99)]
|
||||||
try:
|
try:
|
||||||
self.assertEqual(vim.line_count(pl=pl, segment_info=segment_info), '100')
|
self.assertEqual(self.vim.line_count(pl=pl, segment_info=segment_info), '100')
|
||||||
vim_module._set_cursor(50, 0)
|
vim_module._set_cursor(50, 0)
|
||||||
self.assertEqual(vim.line_count(pl=pl, segment_info=segment_info), '100')
|
self.assertEqual(self.vim.line_count(pl=pl, segment_info=segment_info), '100')
|
||||||
finally:
|
finally:
|
||||||
vim_module._bw(segment_info['bufnr'])
|
vim_module._bw(segment_info['bufnr'])
|
||||||
|
|
||||||
@ -971,18 +968,18 @@ class TestVim(TestCase):
|
|||||||
try:
|
try:
|
||||||
segment_info['buffer'][0:-1] = [str(i) for i in range(99)]
|
segment_info['buffer'][0:-1] = [str(i) for i in range(99)]
|
||||||
vim_module._set_cursor(49, 0)
|
vim_module._set_cursor(49, 0)
|
||||||
self.assertEqual(vim.position(pl=pl, segment_info=segment_info), '50%')
|
self.assertEqual(self.vim.position(pl=pl, segment_info=segment_info), '50%')
|
||||||
self.assertEqual(vim.position(pl=pl, segment_info=segment_info, gradient=True), [
|
self.assertEqual(self.vim.position(pl=pl, segment_info=segment_info, gradient=True), [
|
||||||
{'contents': '50%', 'highlight_group': ['position_gradient', 'position'], 'gradient_level': 50.0}
|
{'contents': '50%', 'highlight_group': ['position_gradient', 'position'], 'gradient_level': 50.0}
|
||||||
])
|
])
|
||||||
vim_module._set_cursor(0, 0)
|
vim_module._set_cursor(0, 0)
|
||||||
self.assertEqual(vim.position(pl=pl, segment_info=segment_info), 'Top')
|
self.assertEqual(self.vim.position(pl=pl, segment_info=segment_info), 'Top')
|
||||||
vim_module._set_cursor(97, 0)
|
vim_module._set_cursor(97, 0)
|
||||||
self.assertEqual(vim.position(pl=pl, segment_info=segment_info, position_strings={'top': 'Comienzo', 'bottom': 'Final', 'all': 'Todo'}), 'Final')
|
self.assertEqual(self.vim.position(pl=pl, segment_info=segment_info, position_strings={'top': 'Comienzo', 'bottom': 'Final', 'all': 'Todo'}), 'Final')
|
||||||
segment_info['buffer'][0:-1] = [str(i) for i in range(2)]
|
segment_info['buffer'][0:-1] = [str(i) for i in range(2)]
|
||||||
vim_module._set_cursor(0, 0)
|
vim_module._set_cursor(0, 0)
|
||||||
self.assertEqual(vim.position(pl=pl, segment_info=segment_info, position_strings={'top': 'Comienzo', 'bottom': 'Final', 'all': 'Todo'}), 'Todo')
|
self.assertEqual(self.vim.position(pl=pl, segment_info=segment_info, position_strings={'top': 'Comienzo', 'bottom': 'Final', 'all': 'Todo'}), 'Todo')
|
||||||
self.assertEqual(vim.position(pl=pl, segment_info=segment_info, gradient=True), [
|
self.assertEqual(self.vim.position(pl=pl, segment_info=segment_info, gradient=True), [
|
||||||
{'contents': 'All', 'highlight_group': ['position_gradient', 'position'], 'gradient_level': 0.0}
|
{'contents': 'All', 'highlight_group': ['position_gradient', 'position'], 'gradient_level': 0.0}
|
||||||
])
|
])
|
||||||
finally:
|
finally:
|
||||||
@ -991,34 +988,34 @@ class TestVim(TestCase):
|
|||||||
def test_cursor_current(self):
|
def test_cursor_current(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
segment_info = vim_module._get_segment_info()
|
segment_info = vim_module._get_segment_info()
|
||||||
self.assertEqual(vim.line_current(pl=pl, segment_info=segment_info), '1')
|
self.assertEqual(self.vim.line_current(pl=pl, segment_info=segment_info), '1')
|
||||||
self.assertEqual(vim.col_current(pl=pl, segment_info=segment_info), '1')
|
self.assertEqual(self.vim.col_current(pl=pl, segment_info=segment_info), '1')
|
||||||
self.assertEqual(vim.virtcol_current(pl=pl, segment_info=segment_info), [{
|
self.assertEqual(self.vim.virtcol_current(pl=pl, segment_info=segment_info), [{
|
||||||
'highlight_group': ['virtcol_current_gradient', 'virtcol_current', 'col_current'], 'contents': '1', 'gradient_level': 100.0 / 80,
|
'highlight_group': ['virtcol_current_gradient', 'virtcol_current', 'col_current'], 'contents': '1', 'gradient_level': 100.0 / 80,
|
||||||
}])
|
}])
|
||||||
self.assertEqual(vim.virtcol_current(pl=pl, segment_info=segment_info, gradient=False), [{
|
self.assertEqual(self.vim.virtcol_current(pl=pl, segment_info=segment_info, gradient=False), [{
|
||||||
'highlight_group': ['virtcol_current', 'col_current'], 'contents': '1',
|
'highlight_group': ['virtcol_current', 'col_current'], 'contents': '1',
|
||||||
}])
|
}])
|
||||||
|
|
||||||
def test_modified_buffers(self):
|
def test_modified_buffers(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
self.assertEqual(vim.modified_buffers(pl=pl), None)
|
self.assertEqual(self.vim.modified_buffers(pl=pl), None)
|
||||||
|
|
||||||
def test_branch(self):
|
def test_branch(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
create_watcher = get_fallback_create_watcher()
|
create_watcher = get_fallback_create_watcher()
|
||||||
branch = partial(vim.branch, pl=pl, create_watcher=create_watcher)
|
branch = partial(self.vim.branch, pl=pl, create_watcher=create_watcher)
|
||||||
with vim_module._with('buffer', '/foo') as segment_info:
|
with vim_module._with('buffer', '/foo') as segment_info:
|
||||||
with replace_attr(vim, 'guess', get_dummy_guess(status=lambda: None)):
|
with replace_attr(self.vim, 'guess', get_dummy_guess(status=lambda: None)):
|
||||||
with replace_attr(vim, 'tree_status', lambda repo, pl: None):
|
with replace_attr(self.vim, 'tree_status', lambda repo, pl: None):
|
||||||
self.assertEqual(branch(segment_info=segment_info, status_colors=False), [
|
self.assertEqual(branch(segment_info=segment_info, status_colors=False), [
|
||||||
{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch'], 'contents': 'foo'}
|
{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch'], 'contents': 'foo'}
|
||||||
])
|
])
|
||||||
self.assertEqual(branch(segment_info=segment_info, status_colors=True), [
|
self.assertEqual(branch(segment_info=segment_info, status_colors=True), [
|
||||||
{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch_clean', 'branch'], 'contents': 'foo'}
|
{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch_clean', 'branch'], 'contents': 'foo'}
|
||||||
])
|
])
|
||||||
with replace_attr(vim, 'guess', get_dummy_guess(status=lambda: 'DU')):
|
with replace_attr(self.vim, 'guess', get_dummy_guess(status=lambda: 'DU')):
|
||||||
with replace_attr(vim, 'tree_status', lambda repo, pl: 'DU'):
|
with replace_attr(self.vim, 'tree_status', lambda repo, pl: 'DU'):
|
||||||
self.assertEqual(branch(segment_info=segment_info, status_colors=False), [
|
self.assertEqual(branch(segment_info=segment_info, status_colors=False), [
|
||||||
{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch'], 'contents': 'foo'}
|
{'divider_highlight_group': 'branch:divider', 'highlight_group': ['branch'], 'contents': 'foo'}
|
||||||
])
|
])
|
||||||
@ -1029,23 +1026,23 @@ class TestVim(TestCase):
|
|||||||
def test_file_vcs_status(self):
|
def test_file_vcs_status(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
create_watcher = get_fallback_create_watcher()
|
create_watcher = get_fallback_create_watcher()
|
||||||
file_vcs_status = partial(vim.file_vcs_status, pl=pl, create_watcher=create_watcher)
|
file_vcs_status = partial(self.vim.file_vcs_status, pl=pl, create_watcher=create_watcher)
|
||||||
with vim_module._with('buffer', '/foo') as segment_info:
|
with vim_module._with('buffer', '/foo') as segment_info:
|
||||||
with replace_attr(vim, 'guess', get_dummy_guess(status=lambda file: 'M')):
|
with replace_attr(self.vim, 'guess', get_dummy_guess(status=lambda file: 'M')):
|
||||||
self.assertEqual(file_vcs_status(segment_info=segment_info), [
|
self.assertEqual(file_vcs_status(segment_info=segment_info), [
|
||||||
{'highlight_group': ['file_vcs_status_M', 'file_vcs_status'], 'contents': 'M'}
|
{'highlight_group': ['file_vcs_status_M', 'file_vcs_status'], 'contents': 'M'}
|
||||||
])
|
])
|
||||||
with replace_attr(vim, 'guess', get_dummy_guess(status=lambda file: None)):
|
with replace_attr(self.vim, 'guess', get_dummy_guess(status=lambda file: None)):
|
||||||
self.assertEqual(file_vcs_status(segment_info=segment_info), None)
|
self.assertEqual(file_vcs_status(segment_info=segment_info), None)
|
||||||
with vim_module._with('buffer', '/bar') as segment_info:
|
with vim_module._with('buffer', '/bar') as segment_info:
|
||||||
with vim_module._with('bufoptions', buftype='nofile'):
|
with vim_module._with('bufoptions', buftype='nofile'):
|
||||||
with replace_attr(vim, 'guess', get_dummy_guess(status=lambda file: 'M')):
|
with replace_attr(self.vim, 'guess', get_dummy_guess(status=lambda file: 'M')):
|
||||||
self.assertEqual(file_vcs_status(segment_info=segment_info), None)
|
self.assertEqual(file_vcs_status(segment_info=segment_info), None)
|
||||||
|
|
||||||
def test_trailing_whitespace(self):
|
def test_trailing_whitespace(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
with vim_module._with('buffer', 'tws') as segment_info:
|
with vim_module._with('buffer', 'tws') as segment_info:
|
||||||
trailing_whitespace = partial(vim.trailing_whitespace, pl=pl, segment_info=segment_info)
|
trailing_whitespace = partial(self.vim.trailing_whitespace, pl=pl, segment_info=segment_info)
|
||||||
self.assertEqual(trailing_whitespace(), None)
|
self.assertEqual(trailing_whitespace(), None)
|
||||||
self.assertEqual(trailing_whitespace(), None)
|
self.assertEqual(trailing_whitespace(), None)
|
||||||
vim_module.current.buffer[0] = ' '
|
vim_module.current.buffer[0] = ' '
|
||||||
@ -1064,57 +1061,54 @@ class TestVim(TestCase):
|
|||||||
def test_tabnr(self):
|
def test_tabnr(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
segment_info = vim_module._get_segment_info()
|
segment_info = vim_module._get_segment_info()
|
||||||
self.assertEqual(vim.tabnr(pl=pl, segment_info=segment_info, show_current=True), '1')
|
self.assertEqual(self.vim.tabnr(pl=pl, segment_info=segment_info, show_current=True), '1')
|
||||||
self.assertEqual(vim.tabnr(pl=pl, segment_info=segment_info, show_current=False), None)
|
self.assertEqual(self.vim.tabnr(pl=pl, segment_info=segment_info, show_current=False), None)
|
||||||
|
|
||||||
def test_bufnr(self):
|
def test_bufnr(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
segment_info = vim_module._get_segment_info()
|
segment_info = vim_module._get_segment_info()
|
||||||
self.assertEqual(vim.bufnr(pl=pl, segment_info=segment_info, show_current=True), str(segment_info['bufnr']))
|
self.assertEqual(self.vim.bufnr(pl=pl, segment_info=segment_info, show_current=True), str(segment_info['bufnr']))
|
||||||
self.assertEqual(vim.bufnr(pl=pl, segment_info=segment_info, show_current=False), None)
|
self.assertEqual(self.vim.bufnr(pl=pl, segment_info=segment_info, show_current=False), None)
|
||||||
|
|
||||||
def test_winnr(self):
|
def test_winnr(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
segment_info = vim_module._get_segment_info()
|
segment_info = vim_module._get_segment_info()
|
||||||
self.assertEqual(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(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'):
|
||||||
with vim_module._with('buffer', '1') as segment_info:
|
with vim_module._with('buffer', '1') as segment_info:
|
||||||
self.assertEqual(vim.tab_modified_indicator(pl=pl, segment_info=segment_info), None)
|
self.assertEqual(self.vim.tab_modified_indicator(pl=pl, segment_info=segment_info), None)
|
||||||
vim_module.current.buffer[0] = ' '
|
vim_module.current.buffer[0] = ' '
|
||||||
self.assertEqual(vim.tab_modified_indicator(pl=pl, segment_info=segment_info), [{
|
self.assertEqual(self.vim.tab_modified_indicator(pl=pl, segment_info=segment_info), [{
|
||||||
'contents': '+',
|
'contents': '+',
|
||||||
'highlight_group': ['tab_modified_indicator', 'modified_indicator'],
|
'highlight_group': ['tab_modified_indicator', 'modified_indicator'],
|
||||||
}])
|
}])
|
||||||
vim_module._undo()
|
vim_module._undo()
|
||||||
self.assertEqual(vim.tab_modified_indicator(pl=pl, segment_info=segment_info), None)
|
self.assertEqual(self.vim.tab_modified_indicator(pl=pl, segment_info=segment_info), None)
|
||||||
old_buffer = vim_module.current.buffer
|
old_buffer = vim_module.current.buffer
|
||||||
vim_module._new('2')
|
vim_module._new('2')
|
||||||
segment_info = vim_module._get_segment_info()
|
segment_info = vim_module._get_segment_info()
|
||||||
self.assertEqual(vim.tab_modified_indicator(pl=pl, segment_info=segment_info), None)
|
self.assertEqual(self.vim.tab_modified_indicator(pl=pl, segment_info=segment_info), None)
|
||||||
old_buffer[0] = ' '
|
old_buffer[0] = ' '
|
||||||
self.assertEqual(vim.modified_indicator(pl=pl, segment_info=segment_info), None)
|
self.assertEqual(self.vim.modified_indicator(pl=pl, segment_info=segment_info), None)
|
||||||
self.assertEqual(vim.tab_modified_indicator(pl=pl, segment_info=segment_info), [{
|
self.assertEqual(self.vim.tab_modified_indicator(pl=pl, segment_info=segment_info), [{
|
||||||
'contents': '+',
|
'contents': '+',
|
||||||
'highlight_group': ['tab_modified_indicator', 'modified_indicator'],
|
'highlight_group': ['tab_modified_indicator', 'modified_indicator'],
|
||||||
}])
|
}])
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'path')))
|
||||||
|
from powerline.segments import vim
|
||||||
|
cls.vim = vim
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDownClass(cls):
|
||||||
|
sys.path.pop(0)
|
||||||
|
|
||||||
|
|
||||||
old_cwd = None
|
old_cwd = None
|
||||||
|
|
||||||
@ -1122,18 +1116,14 @@ old_cwd = None
|
|||||||
def setUpModule():
|
def setUpModule():
|
||||||
global old_cwd
|
global old_cwd
|
||||||
global __file__
|
global __file__
|
||||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'path')))
|
|
||||||
old_cwd = os.getcwd()
|
old_cwd = os.getcwd()
|
||||||
__file__ = os.path.abspath(__file__)
|
__file__ = os.path.abspath(__file__)
|
||||||
os.chdir(os.path.dirname(__file__))
|
os.chdir(os.path.dirname(__file__))
|
||||||
from powerline.segments import vim
|
|
||||||
globals()['vim'] = vim
|
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
global old_cwd
|
global old_cwd
|
||||||
os.chdir(old_cwd)
|
os.chdir(old_cwd)
|
||||||
sys.path.pop(0)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
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()
|
@ -16,7 +16,7 @@ catch
|
|||||||
cquit
|
cquit
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
if result isnot# '%#Pl_240_5789784_235_2500134_NONE# 1 %#Pl_240_5789784_235_2500134_NONE#./%#Pl_244_8421504_235_2500134_bold#abc %#Pl_244_8421504_235_2500134_NONE# %#Pl_240_5789784_235_2500134_NONE#2 %#Pl_240_5789784_235_2500134_NONE#./%#Pl_244_8421504_235_2500134_bold#def %#Pl_235_2500134_240_5789784_NONE# %#Pl_250_12369084_240_5789784_NONE#./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE# %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Tabs '
|
if result isnot# '%#Pl_247_10395294_236_3158064_NONE# 1 ./abc 2 ./def %#Pl_236_3158064_240_5789784_NONE# %#Pl_250_12369084_240_5789784_NONE#3 ./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE# %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Tabs '
|
||||||
call writefile(['Unexpected tabline', result], 'message.fail')
|
call writefile(['Unexpected tabline', result], 'message.fail')
|
||||||
cquit
|
cquit
|
||||||
endif
|
endif
|
||||||
@ -30,7 +30,7 @@ catch
|
|||||||
cquit
|
cquit
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
if result isnot# '%#Pl_240_5789784_235_2500134_NONE# 1 %#Pl_240_5789784_235_2500134_NONE#./%#Pl_244_8421504_235_2500134_bold#abc %#Pl_244_8421504_235_2500134_NONE# %#Pl_240_5789784_235_2500134_NONE#2 %#Pl_240_5789784_235_2500134_NONE#./%#Pl_244_8421504_235_2500134_bold#def %#Pl_235_2500134_240_5789784_NONE# %#Pl_250_12369084_240_5789784_NONE#./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE# %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Bufs '
|
if result isnot# '%#Pl_247_10395294_236_3158064_NONE# 1 ./abc 2 ./def %#Pl_236_3158064_240_5789784_NONE# %#Pl_250_12369084_240_5789784_NONE#3 ./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE# %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Bufs '
|
||||||
call writefile(['Unexpected tabline (2)', result], 'message.fail')
|
call writefile(['Unexpected tabline (2)', result], 'message.fail')
|
||||||
cquit
|
cquit
|
||||||
endif
|
endif
|
||||||
@ -42,7 +42,7 @@ catch
|
|||||||
call writefile(['Exception while evaluating &tabline (3)', v:exception], 'message.fail')
|
call writefile(['Exception while evaluating &tabline (3)', v:exception], 'message.fail')
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
if result isnot# '%#Pl_240_5789784_235_2500134_NONE# 1 %#Pl_240_5789784_235_2500134_NONE#./%#Pl_244_8421504_235_2500134_bold#abc %#Pl_244_8421504_235_2500134_NONE# %#Pl_240_5789784_235_2500134_NONE#2 %#Pl_240_5789784_235_2500134_NONE#./%#Pl_244_8421504_235_2500134_bold#def %#Pl_235_2500134_240_5789784_NONE# %#Pl_250_12369084_240_5789784_NONE#./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE# %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Bufs '
|
if result isnot# '%#Pl_247_10395294_236_3158064_NONE# 1 ./abc 2 ./def %#Pl_236_3158064_240_5789784_NONE# %#Pl_250_12369084_240_5789784_NONE#3 ./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE# %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Bufs '
|
||||||
call writefile(['Unexpected tabline (3)', result], 'message.fail')
|
call writefile(['Unexpected tabline (3)', result], 'message.fail')
|
||||||
cquit
|
cquit
|
||||||
endif
|
endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user