1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-04 03:50:05 +08:00
SpaceVim/bundle/defx.nvim/rplugin/python3/defx/column/mark.py

65 lines
2.1 KiB
Python
Raw Normal View History

2020-06-13 14:06:35 +08:00
# ============================================================================
# FILE: mark.py
# AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
# License: MIT license
# ============================================================================
2020-10-31 15:58:52 +08:00
from defx.base.column import Base, Highlights
2020-06-13 14:06:35 +08:00
from defx.context import Context
2020-10-31 15:58:52 +08:00
from defx.util import Nvim, Candidate, len_bytes
2020-06-13 14:06:35 +08:00
import os
import typing
class Column(Base):
def __init__(self, vim: Nvim) -> None:
super().__init__(vim)
self.name = 'mark'
self.vars = {
'length': 1,
'readonly_icon': 'X',
'selected_icon': '*',
}
self._syntaxes = [
'directory',
'opened',
'readonly',
'selected',
]
2020-10-31 15:58:52 +08:00
self.has_get_with_highlights = True
2020-06-13 14:06:35 +08:00
2020-10-31 15:58:52 +08:00
self._icons = {
'readonly': 'Comment',
'selected': 'Statement',
}
def get_with_highlights(
self, context: Context, candidate: Candidate
) -> typing.Tuple[str, Highlights]:
2020-06-13 14:06:35 +08:00
if candidate['is_selected']:
2020-10-31 15:58:52 +08:00
return (str(self.vars['selected_icon']),
[(f'{self.highlight_name}_selected',
self.start, len_bytes(self.vars['selected_icon']))])
2020-06-13 14:06:35 +08:00
elif not os.access(str(candidate['action__path']), os.W_OK):
2020-10-31 15:58:52 +08:00
return (str(self.vars['readonly_icon']),
[(f'{self.highlight_name}_readonly',
self.start, len_bytes(self.vars['readonly_icon']))])
return (' ' * self.vars['length'], [])
2020-06-13 14:06:35 +08:00
def length(self, context: Context) -> int:
return typing.cast(int, self.vars['length'])
def syntaxes(self) -> typing.List[str]:
return [self.syntax_name + '_' + x for x in self._syntaxes]
def highlight_commands(self) -> typing.List[str]:
commands: typing.List[str] = []
2020-10-31 15:58:52 +08:00
for icon, highlight in self._icons.items():
2020-06-13 14:06:35 +08:00
commands.append(
'highlight default link {}_{} {}'.format(
2020-10-31 15:58:52 +08:00
self.highlight_name, icon, highlight))
2020-06-13 14:06:35 +08:00
return commands