Skip to content

Commit 8e23c89

Browse files
author
cht
committed
add a alone title
1 parent 28608d9 commit 8e23c89

3 files changed

Lines changed: 53 additions & 9 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ require("csvtools").setup({
1111
-- this will clear the highlight of buf after move
1212
showoverflow = true,
1313
-- this will provide a overflow show
14+
titelflow = true,
15+
-- add an alone title
1416

1517
})
1618
```

lua/csvtools.lua

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@ local api = vim.api
22
local highlight = require("csvtools.highlight")
33
local overflow = require("csvtools.overflowtext")
44
local M = {
5-
--winid = nil,
6-
--buf = nil,
7-
--mainwindowbuf = nil,
8-
--header = {},
95
before = 20,
106
after = 20,
117
clearafter = true,
128
showoverflow = true,
13-
--overflowtext = {
14-
-- markid = nil,
15-
-- ns_id = nil,
16-
-- id = nil,
17-
--},
9+
titleflow = true,
1810
}
1911
-- buf's status
2012
local Status = {
@@ -136,6 +128,9 @@ function M.Highlight()
136128
--highlight.highlight(M.mainwindowbuf, count)
137129
count = count + 1
138130
end
131+
if line - 2 > 0 and M.titleflow then
132+
table.insert(Status.overflowtext, overflow.OverFlowTitle(line - 2, Status.header, 4))
133+
end
139134
end
140135
end
141136
end

lua/csvtools/overflowtext.lua

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,51 @@ function M.OverFlow(line_num, header, id)
5454
id = id,
5555
}
5656
end
57+
function M.OverFlowTitle(line_num, header, id)
58+
local bnr = vim.fn.bufnr("%")
59+
local line = unpack(vim.api.nvim_buf_get_lines(0, 0, 1, true))
60+
local output = Split(line, ",")
61+
for count = 1, #header do
62+
if output[count] == nil then
63+
output[count] = ""
64+
end
65+
local len = string.len(output[count])
66+
if len < header[count] then
67+
for _ = 1, header[count] - len do
68+
output[count] = output[count] .. " "
69+
end
70+
elseif len > header[count] then
71+
--print(len," ",header[count])
72+
output[count] = output[count]:sub(1, header[count] - 2)
73+
output[count] = output[count] .. ".."
74+
--print("len=" , string.len(output[count]))
75+
end
76+
--print(header[count])
77+
end
78+
local virt_text = {}
79+
for count = 1, #output do
80+
if count % 2 == 0 then
81+
table.insert(virt_text, { output[count], "WhidHeader" })
82+
else
83+
table.insert(virt_text, { output[count], "WhidSubHeader" })
84+
end
85+
table.insert(virt_text, { "|" })
86+
--table.insert(virt_text,{text,"WhidHeader"})
87+
--print(output[count])
88+
end
89+
local opts = {
90+
end_line = 1,
91+
id = id,
92+
virt_text = virt_text,
93+
virt_text_pos = "overlay",
94+
-- virt_text_win_col = 20,
95+
}
96+
--highlighttop2(bnr, text)
97+
--print("sss")
98+
return {
99+
markid = vim.api.nvim_buf_set_extmark(bnr, ns_id, line_num - 1, 0, opts),
100+
ns_id = ns_id,
101+
id = id,
102+
}
103+
end
57104
return M

0 commit comments

Comments
 (0)