1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-10 14:05:48 +08:00
SpaceVim/bundle/defx.nvim/rplugin/python3/defx/column/time.py
2020-06-13 14:06:35 +08:00

47 lines
1.4 KiB
Python

# ============================================================================
# FILE: time.py
# AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
# License: MIT license
# ============================================================================
from defx.base.column import Base
from defx.context import Context
from defx.util import Nvim, readable
from defx.view import View
import time
import typing
class Column(Base):
def __init__(self, vim: Nvim) -> None:
super().__init__(vim)
self.name = 'time'
self._length = 0
self.vars = {
'format': '%y.%m.%d %H:%M',
}
def on_init(self, view: View, context: Context) -> None:
self._length = self.vim.call('strwidth',
time.strftime(self.vars['format']))
def get(self, context: Context,
candidate: typing.Dict[str, typing.Any]) -> str:
path = candidate['action__path']
if not readable(path):
return str(' ' * self._length)
return time.strftime(self.vars['format'],
time.localtime(path.stat().st_mtime))
def length(self, context: Context) -> int:
return self._length
def highlight_commands(self) -> typing.List[str]:
commands: typing.List[str] = []
commands.append(
f'highlight default link {self.syntax_name} Identifier')
return commands