1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 07:10:06 +08:00

perf(zettelkasten): check title width

This commit is contained in:
Eric Wong 2024-12-22 23:27:48 +08:00
parent afe49af8a3
commit 113110b163

View File

@ -7,6 +7,15 @@
--=============================================================================
local M = {}
local function str2chars(str)
local t = {}
for _, k in ipairs(vim.fn.split(str, '\\zs')) do
table.insert(t, k)
end
return t
end
local s_formatters = {
['%r'] = function(line)
return #line.references
@ -18,10 +27,19 @@ local s_formatters = {
return vim.fn.fnamemodify(line.file_name, ':t')
end,
['%h'] = function(line)
if vim.fn.strdisplaywidth(line.title) <= 30 then
if vim.fn.strdisplaywidth(line.title) < 30 then
return line.title .. string.rep(' ', 30 - vim.fn.strdisplaywidth(line.title))
else
return string.sub(line.title, 1, 27) .. '...'
local t = ''
for _, char in ipairs(str2chars(line.title)) do
if vim.fn.strdisplaywidth(t) + vim.fn.strdisplaywidth(char) <= 27 then
t = t .. char
else
break
end
end
t = t .. '...'
return t .. string.rep(' ', 30 - vim.fn.strdisplaywidth(t))
end
end,
['%d'] = function(line)