Skip to content

Commit

Permalink
update show message
Browse files Browse the repository at this point in the history
  • Loading branch information
cht committed Feb 17, 2022
1 parent 8e23c89 commit 4d6901e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
10 changes: 6 additions & 4 deletions lua/csvtools.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local api = vim.api
local highlight = require("csvtools.highlight")
local overflow = require("csvtools.overflowtext")
local getheader = require("csvtools.header")
local M = {
before = 20,
after = 20,
Expand All @@ -16,9 +17,9 @@ local Status = {
header = {},
overflowtext = {},
}
function M.printheader()
return Status.header
end
--function M.printheader()
-- return Status.header
--end
function M.Ifclear()
if M.clearafter then
M.clearafter = false
Expand All @@ -43,7 +44,7 @@ function M.NewWindow()
local win = vim.api.nvim_get_current_win()
api.nvim_buf_set_lines(buf, 0, -1, false, { messages })
api.nvim_win_set_buf(win, buf)
Status.header = highlight.highlighttop(buf, messages)
highlight.highlighttop(buf, messages)
Status.winid = win
Status.buf = buf
M.add_mappings()
Expand Down Expand Up @@ -87,6 +88,7 @@ local function getrangeoverflow(line, length)
end
function M.Highlight()
if vim.o.filetype == "csv" then
Status.header = getheader.Header()
if M.showoverflow then
for count = 1, #Status.overflowtext do
vim.api.nvim_buf_del_extmark(
Expand Down
21 changes: 21 additions & 0 deletions lua/csvtools/header.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
local M = {}

--@param buf winbuf
--@param line string
function M.Header()
local line = unpack(vim.api.nvim_buf_get_lines(0, 0, 1, true))
local header = {}
local cout = 1
local length = 0
for i = 1, #line do
if line:sub(i, i) ~= "," then
length = length + 1
else
table.insert(header, length)
length = 0
cout = cout + 1
end
end
return header
end
return M
12 changes: 6 additions & 6 deletions lua/csvtools/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ local M = {}
--@param buf winbuf
--@param line string
function M.highlighttop(buf, line)
local header = {}
--local header = {}
local cout = 1
local length = 0
--local length = 0
for i = 1, #line do
if line:sub(i, i) ~= "|" then
length = length + 1
--length = length + 1
if cout % 2 == 0 then
--print(line:sub(i, i))
api.nvim_buf_add_highlight(buf, -1, "WhidHeader", 0, i - 1, i)
else
api.nvim_buf_add_highlight(buf, -1, "WhidSubHeader", 0, i - 1, i)
end
else
table.insert(header, length)
length = 0
--table.insert(header, length)
--length = 0
cout = cout + 1
end
end
return header
--return header
end

--@param buf winbuf
Expand Down

0 comments on commit 4d6901e

Please sign in to comment.