1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-24 06:20:05 +08:00
SpaceVim/bundle/dein.vim/rplugin/python3/denite/source/dein_log.py

61 lines
2.0 KiB
Python
Raw Normal View History

2020-06-13 14:06:35 +08:00
# ============================================================================
# FILE: dein_log.py
# AUTHOR: delphinus <delphinus@remora.cx>
# License: MIT license
# ============================================================================
import re
from .base import Base
HEADER_RE = re.compile(r'^\s*[a-zA-Z_]\w*://')
SPACE_RE = re.compile(r'^\s+')
DEIN_LOG_SYNTAX_HIGHLIGHT = [
{'name': 'Progress', 're': r'\[[ =]\+\]', 'link': 'String'},
{'name': 'Source', 're': r'|.\{-}|', 'link': 'Type'},
{'name': 'URI', 're': r'-> diff URI', 'link': 'Underlined'},
]
class Source(Base):
def __init__(self, vim):
super().__init__(vim)
self.name = 'dein/log'
def on_init(self, context):
context['__source_log'] = []
def gather_candidates(self, context):
dein_context = self.vim.call('dein#install#_get_context')
context['is_async'] = bool(dein_context)
if context['args'] and context['args'][0] == '!':
log_func = 'dein#install#_get_updates_log'
else:
log_func = 'dein#install#_get_log'
logs = self.vim.call(log_func)
def make_candidates(row):
return {
'word': ' -> diff URI',
'kind': 'file',
'action__path': SPACE_RE.sub('', row),
} if HEADER_RE.match(row) else {'word': row, 'kind': 'word'}
rows = len(context['__source_log'])
candidates = list(map(make_candidates, logs[rows:]))
context['__source_log'] = logs
# Needs wait to call Vim output handlers
self.vim.command('sleep 100m')
return candidates
def highlight(self):
for syn in DEIN_LOG_SYNTAX_HIGHLIGHT:
self.vim.command(
'syntax match {0}_{1} /{2}/ contained containedin={0}'
.format(self.syntax_name, syn['name'], syn['re']))
self.vim.command(
'highlight default link {0}_{1} {2}'
.format(self.syntax_name, syn['name'], syn['link']))