@@ -4,26 +4,28 @@ local M = {
44 winid = nil ,
55 buf = nil ,
66 mainwindowbuf = nil ,
7+ before = 10 ,
8+ after = 10 ,
79}
10+ local highlight = require (" csvtools.topbarhighlight" )
811function M .NewWindow ()
912 if M .winid == nil then
1013 M .mainwindowbuf = vim .api .nvim_get_current_buf ()
11- local file = vim .api .nvim_buf_get_name (0 )
12- local f = io.open (file , " r" )
13-
14- local messages = f :read ()
14+ -- local file = vim.api.nvim_buf_get_name(0)
15+ -- local f = io.open(file, "r")
16+ local messages = unpack (api .nvim_buf_get_lines (M .mainwindowbuf ,0 ,1 ,true ))
1517 if messages == nil then
1618 return
1719 end
18- f :close ()
20+ -- f:close()
1921 messages = messages :gsub (" %," , " |" )
2022 local buf = api .nvim_create_buf (false , true ) -- create new emtpy buffer
2123 vim .cmd ([[ sview]] )
2224 api .nvim_win_set_height (0 , 1 )
2325 local win = vim .api .nvim_get_current_win ()
2426 api .nvim_buf_set_lines (buf , 0 , - 1 , false , { messages })
2527 api .nvim_win_set_buf (win , buf )
26- require ( " csvtools.topbarhighlight " ). hightlight (buf , messages )
28+ highlight . highlighttop (buf , messages )
2729 -- api.nvim_buf_add_highlight(buf, -1, 'WhidHeader',0,0,1)
2830 -- api.nvim_buf_add_highlight(buf, -1, 'WhidSubHeader', 0, 1, 2)
2931 M .winid = win
@@ -38,13 +40,43 @@ function M.CloseWindow()
3840 M .buf = nil
3941 end
4042end
43+ local function getrange (line ,length )
44+ local start = 1
45+ if line - M .before > 1 then
46+ start = line - M .before
47+ end
48+ local final = length
49+ if line + M .after < length then
50+ final = line + M .after
51+ end
52+ return start , final
53+ end
54+ function M .Highlight ()
55+ if vim .o .filetype == " csv" then
56+
57+ M .mainwindowbuf = vim .api .nvim_get_current_buf ()
58+ local line ,_ = unpack (vim .api .nvim_win_get_cursor (0 ))
59+ local length = vim .api .nvim_buf_line_count (M .mainwindowbuf )
60+ local start , final = getrange (line ,length )
61+ -- print(start)
62+ -- print(final)
63+ for i = start , line , 1 do
64+ highlight .highlight (M .mainwindowbuf ,i )
65+ end
66+ for i = line , final , 1 do
67+ highlight .highlight (M .mainwindowbuf ,i )
68+ end
69+ end
70+ end
4171function M .add_mappings ()
4272 -- print(M.mainwindowbuf)
4373 local opts = { nowait = true , noremap = true , silent = true }
4474 -- vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<leader>td", ":lua require'csvtools'.CloseWindow<cr>", opts)
4575 vim .api .nvim_buf_set_keymap (M .mainwindowbuf , " n" , " <leader>tf" , " :lua require'csvtools'.NewWindow()<cr>" , opts )
4676 vim .api .nvim_buf_set_keymap (M .buf , " n" , " <leader>td" , " :lua require'csvtools'.CloseWindow()<cr>" , opts )
4777 vim .api .nvim_buf_set_keymap (M .mainwindowbuf , " n" , " <leader>td" , " :lua require'csvtools'.CloseWindow()<cr>" , opts )
78+ vim .api .nvim_buf_set_keymap (M .mainwindowbuf , " n" , " <up>" , " :lua require'csvtools'.Highlight()<cr>:-1<cr>" , opts )
79+ vim .api .nvim_buf_set_keymap (M .mainwindowbuf , " n" , " <down>" , " :lua require'csvtools'.Highlight()<cr>:+1<cr>" , opts )
4880end
4981function M .setup (opts )
5082 M = vim .tbl_deep_extend (" force" , M , opts )
0 commit comments